feat(context): centralize RepoContext API for git operations (#1102)
Centralizes repository context resolution via RepoContext API, fixing bugs where git commands run in the wrong repo when BEADS_DIR points elsewhere or in worktree scenarios.
This commit is contained in:
committed by
GitHub
parent
159114563b
commit
0a48519561
@@ -29,6 +29,40 @@ func TestBuildGitCommitArgs_ConfigOptions(t *testing.T) {
|
||||
if !strings.Contains(joined, "-m hello") {
|
||||
t.Fatalf("expected message in args: %v", args)
|
||||
}
|
||||
// buildGitCommitArgs includes -C for raw exec.Command
|
||||
if !strings.HasPrefix(joined, "-C /repo commit") {
|
||||
t.Fatalf("expected -C /repo prefix in args: %v", args)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildCommitArgs_ForRepoContext(t *testing.T) {
|
||||
// buildCommitArgs is for use with RepoContext.GitCmd() which sets cmd.Dir,
|
||||
// so it should NOT include the -C flag.
|
||||
if err := config.Initialize(); err != nil {
|
||||
t.Fatalf("config.Initialize: %v", err)
|
||||
}
|
||||
config.Set("git.author", "Test User <test@example.com>")
|
||||
config.Set("git.no-gpg-sign", true)
|
||||
|
||||
args := buildCommitArgs("hello", "--", ".beads")
|
||||
joined := strings.Join(args, " ")
|
||||
|
||||
// Should start with "commit", not "-C"
|
||||
if !strings.HasPrefix(joined, "commit") {
|
||||
t.Fatalf("expected to start with 'commit', got: %v", args)
|
||||
}
|
||||
if strings.Contains(joined, "-C") {
|
||||
t.Fatalf("buildCommitArgs should NOT contain -C (RepoContext sets cmd.Dir): %v", args)
|
||||
}
|
||||
if !strings.Contains(joined, "--author") {
|
||||
t.Fatalf("expected --author in args: %v", args)
|
||||
}
|
||||
if !strings.Contains(joined, "--no-gpg-sign") {
|
||||
t.Fatalf("expected --no-gpg-sign in args: %v", args)
|
||||
}
|
||||
if !strings.Contains(joined, "-m hello") {
|
||||
t.Fatalf("expected message in args: %v", args)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGitCommitBeadsDir_PathspecDoesNotCommitOtherStagedFiles(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user