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:
@@ -9,6 +9,7 @@ import (
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/steveyegge/beads/internal/git"
|
||||
"github.com/steveyegge/beads/internal/storage/sqlite"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
)
|
||||
@@ -90,6 +91,7 @@ func testFreshCloneAutoImport(t *testing.T) {
|
||||
|
||||
// Test checkGitForIssues detects issues.jsonl
|
||||
t.Chdir(dir)
|
||||
git.ResetCaches() // Reset git caches after changing directory
|
||||
|
||||
count, path, gitRef := checkGitForIssues()
|
||||
if count != 1 {
|
||||
@@ -169,6 +171,7 @@ func testDatabaseRemovalScenario(t *testing.T) {
|
||||
|
||||
// Change to test directory
|
||||
t.Chdir(dir)
|
||||
git.ResetCaches() // Reset git caches after changing directory
|
||||
|
||||
// Test checkGitForIssues finds issues.jsonl (canonical name)
|
||||
count, path, gitRef := checkGitForIssues()
|
||||
@@ -247,6 +250,7 @@ func testLegacyFilenameSupport(t *testing.T) {
|
||||
|
||||
// Change to test directory
|
||||
t.Chdir(dir)
|
||||
git.ResetCaches() // Reset git caches after changing directory
|
||||
|
||||
// Test checkGitForIssues finds issues.jsonl
|
||||
count, path, gitRef := checkGitForIssues()
|
||||
@@ -323,6 +327,7 @@ func testPrecedenceTest(t *testing.T) {
|
||||
|
||||
// Change to test directory
|
||||
t.Chdir(dir)
|
||||
git.ResetCaches() // Reset git caches after changing directory
|
||||
|
||||
// Test checkGitForIssues prefers issues.jsonl
|
||||
count, path, _ := checkGitForIssues()
|
||||
@@ -369,6 +374,7 @@ func testInitSafetyCheck(t *testing.T) {
|
||||
|
||||
// Change to test directory
|
||||
t.Chdir(dir)
|
||||
git.ResetCaches() // Reset git caches after changing directory
|
||||
|
||||
// Create empty database (simulating failed import)
|
||||
dbPath := filepath.Join(beadsDir, "test.db")
|
||||
@@ -409,8 +415,14 @@ func testInitSafetyCheck(t *testing.T) {
|
||||
// Helper functions
|
||||
|
||||
// runCmd runs a command and fails the test if it returns an error
|
||||
// If the command is "git init", it automatically adds --initial-branch=main
|
||||
// for modern git compatibility.
|
||||
func runCmd(t *testing.T, dir string, name string, args ...string) {
|
||||
t.Helper()
|
||||
// Add --initial-branch=main to git init for modern git compatibility
|
||||
if name == "git" && len(args) > 0 && args[0] == "init" {
|
||||
args = append(args, "--initial-branch=main")
|
||||
}
|
||||
cmd := exec.Command(name, args...)
|
||||
cmd.Dir = dir
|
||||
if output, err := cmd.CombinedOutput(); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user