diff options
| author | 2026-03-06 21:19:56 +0800 | |
|---|---|---|
| committer | 2026-03-07 00:34:30 +0800 | |
| commit | 01d15bccf3b1dcc51516b1f64d50950b31d7f8fb (patch) | |
| tree | e491fcc762c67c1ef4ce54faafc5dafdb734ae8a /internal/testgit/repo_commit_tree_env.go | |
| parent | objectstored/refstore: Weird ireturn behavior (diff) | |
| signature | No 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_commit_tree_env.go')
| -rw-r--r-- | internal/testgit/repo_commit_tree_env.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/internal/testgit/repo_commit_tree_env.go b/internal/testgit/repo_commit_tree_env.go new file mode 100644 index 00000000..ee949b5c --- /dev/null +++ b/internal/testgit/repo_commit_tree_env.go @@ -0,0 +1,51 @@ +package testgit + +import ( + "slices" + "strings" + "testing" + + "codeberg.org/lindenii/furgit/objectid" +) + +// CommitTreeWithEnv creates one commit from a tree and message, optionally with +// parents, using additional environment variables for the git subprocess. +func (testRepo *TestRepo) CommitTreeWithEnv( + tb testing.TB, + extraEnv []string, + tree objectid.ObjectID, + message string, + parents ...objectid.ObjectID, +) objectid.ObjectID { + tb.Helper() + + args := make([]string, 0, 2+2*len(parents)+2) + + args = append(args, "commit-tree", tree.String()) + for _, parent := range parents { + args = append(args, "-p", parent.String()) + } + + args = append(args, "-m", message) + hex := testRepo.runWithExtraEnv(tb, extraEnv, args...) + + id, err := objectid.ParseHex(testRepo.algo, hex) + if err != nil { + tb.Fatalf("parse commit-tree output %q: %v", hex, err) + } + + return id +} + +func (testRepo *TestRepo) runWithExtraEnv(tb testing.TB, extraEnv []string, args ...string) string { + tb.Helper() + + env := slices.Concat(testRepo.env, extraEnv) + + out, err := testRepo.runBytesWithEnv(tb, nil, testRepo.dir, env, args...) + if err != nil { + tb.Fatalf("git %v failed: %v\n%s", args, err, out) + } + + return strings.TrimSpace(string(out)) +} |
