aboutsummaryrefslogtreecommitdiff
path: root/internal/testgit/repo_rev_list.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/testgit/repo_rev_list.go')
-rw-r--r--internal/testgit/repo_rev_list.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/internal/testgit/repo_rev_list.go b/internal/testgit/repo_rev_list.go
new file mode 100644
index 00000000..d3adf5a0
--- /dev/null
+++ b/internal/testgit/repo_rev_list.go
@@ -0,0 +1,37 @@
+package testgit
+
+import (
+ "strings"
+ "testing"
+
+ "codeberg.org/lindenii/furgit/objectid"
+)
+
+// RevList runs "git rev-list" with args and parses one object ID per line.
+func (testRepo *TestRepo) RevList(tb testing.TB, args ...string) []objectid.ObjectID {
+ tb.Helper()
+
+ cmdArgs := make([]string, 0, len(args)+1)
+ cmdArgs = append(cmdArgs, "rev-list")
+ cmdArgs = append(cmdArgs, args...)
+ out := testRepo.Run(tb, cmdArgs...)
+
+ lines := strings.Split(strings.TrimSpace(out), "\n")
+
+ outIDs := make([]objectid.ObjectID, 0, len(lines))
+ for _, line := range lines {
+ line = strings.TrimSpace(line)
+ if line == "" {
+ continue
+ }
+
+ id, err := objectid.ParseHex(testRepo.algo, line)
+ if err != nil {
+ tb.Fatalf("parse rev-list oid %q: %v", line, err)
+ }
+
+ outIDs = append(outIDs, id)
+ }
+
+ return outIDs
+}