aboutsummaryrefslogtreecommitdiff
path: root/internal/testgit/repo_run.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-03-06 21:19:56 +0800
committerGravatar Runxi Yu2026-03-07 00:34:30 +0800
commit01d15bccf3b1dcc51516b1f64d50950b31d7f8fb (patch)
treee491fcc762c67c1ef4ce54faafc5dafdb734ae8a /internal/testgit/repo_run.go
parentobjectstored/refstore: Weird ireturn behavior (diff)
signatureNo signature
Urgh I made some wrong amends and I'm too tired to separate the commits out this time
ancestor: Split out of reachability mergebase: Add merge base routines internal/commitquery: Add commit query context engine thingy internal/peel: Shared tag peeling errors: Shared object query errors internal/testgit: Add rooted repo helpers; remove raw path access objectstore/memory: Add in-memory object store objectid: Add Compare helper
Diffstat (limited to 'internal/testgit/repo_run.go')
-rw-r--r--internal/testgit/repo_run.go52
1 files changed, 45 insertions, 7 deletions
diff --git a/internal/testgit/repo_run.go b/internal/testgit/repo_run.go
index 162a0d72..448b88f0 100644
--- a/internal/testgit/repo_run.go
+++ b/internal/testgit/repo_run.go
@@ -22,6 +22,15 @@ func (testRepo *TestRepo) RunBytes(tb testing.TB, args ...string) []byte {
return testRepo.runBytes(tb, nil, testRepo.dir, args...)
}
+// RunE executes git and returns trimmed textual output plus any command error.
+func (testRepo *TestRepo) RunE(tb testing.TB, args ...string) (string, error) {
+ tb.Helper()
+
+ out, err := testRepo.runBytesE(nil, testRepo.dir, args...)
+
+ return strings.TrimSpace(string(out)), err
+}
+
// RunInput executes git with stdin and returns trimmed textual output.
func (testRepo *TestRepo) RunInput(tb testing.TB, stdin []byte, args ...string) string {
tb.Helper()
@@ -39,19 +48,48 @@ func (testRepo *TestRepo) RunInputBytes(tb testing.TB, stdin []byte, args ...str
func (testRepo *TestRepo) runBytes(tb testing.TB, stdin []byte, dir string, args ...string) []byte {
tb.Helper()
+
+ out, err := testRepo.runBytesE(stdin, dir, args...)
+ if err != nil {
+ tb.Fatalf("git %v failed: %v\n%s", args, err, out)
+ }
+
+ return out
+}
+
+func (testRepo *TestRepo) runBytesE(stdin []byte, dir string, args ...string) ([]byte, error) {
+ return testRepo.runBytesWithEnvNoHelper(stdin, dir, testRepo.env, args...)
+}
+
+// runBytesWithEnv executes git using the supplied environment.
+func (testRepo *TestRepo) runBytesWithEnv(
+ tb testing.TB,
+ stdin []byte,
+ dir string,
+ env []string,
+ args ...string,
+) ([]byte, error) {
+ tb.Helper()
+
+ return testRepo.runBytesWithEnvNoHelper(stdin, dir, env, args...)
+}
+
+// runBytesWithEnvNoHelper executes git using the supplied environment without
+// touching testing helper state.
+func (testRepo *TestRepo) runBytesWithEnvNoHelper(
+ stdin []byte,
+ dir string,
+ env []string,
+ args ...string,
+) ([]byte, error) {
//nolint:noctx
cmd := exec.Command("git", args...) //#nosec G204
cmd.Dir = dir
- cmd.Env = testRepo.env
+ cmd.Env = env
if stdin != nil {
cmd.Stdin = bytes.NewReader(stdin)
}
- out, err := cmd.CombinedOutput()
- if err != nil {
- tb.Fatalf("git %v failed: %v\n%s", args, err, out)
- }
-
- return out
+ return cmd.CombinedOutput()
}