fix(tests): use --initial-branch=main for modern git compatibility

Modern git (2.28+) uses 'main' as default branch, not 'master'.
Tests were failing because they assumed 'master' branch exists.

Changes:
- Use 'git init --initial-branch=main' instead of bare 'git init'
- Change 'git checkout master' to 'git checkout main'
- Add git.ResetCaches() after os.Chdir() to clear cached git state
- Ensures test isolation when changing directories
This commit is contained in:
Ryan Snodgrass
2025-12-26 19:09:41 -05:00
parent 252de1cdba
commit 9c9f2f2ad8
5 changed files with 78 additions and 26 deletions

View File

@@ -23,8 +23,8 @@ func setupGitRepo(t *testing.T) string {
t.Fatalf("failed to create .beads directory: %v", err)
}
// Initialize git repo
cmd := exec.Command("git", "init")
// Initialize git repo with 'main' as default branch (modern git convention)
cmd := exec.Command("git", "init", "--initial-branch=main")
cmd.Dir = dir
if err := cmd.Run(); err != nil {
t.Fatalf("failed to init git repo: %v", err)
@@ -278,8 +278,8 @@ func setupGitRepoInDir(t *testing.T, dir string) {
t.Fatalf("failed to create .beads directory: %v", err)
}
// Initialize git repo
cmd := exec.Command("git", "init")
// Initialize git repo with 'main' as default branch (modern git convention)
cmd := exec.Command("git", "init", "--initial-branch=main")
cmd.Dir = dir
if err := cmd.Run(); err != nil {
t.Fatalf("failed to init git repo: %v", err)