Note: The following tests exist in other test files and are not duplicated here: - TestIsGitRepo is in commands_utils_test.go (tests isGitRepo utility) - TestFindGitRoot is in gitroot_test.go (tests findGitRoot utility) - TestEnsureGitAttributes is in gitattributes_test.go (comprehensive gitattribut
(t *testing.T)
| 24 | // - TestStageGitAttributesIfChanged (tests conditional staging during compilation) |
| 25 | |
| 26 | func TestGetCurrentBranch(t *testing.T) { |
| 27 | tmpDir := testutil.TempDir(t, "test-*") |
| 28 | |
| 29 | originalDir, err := os.Getwd() |
| 30 | require.NoError(t, err, "get current directory for test setup") |
| 31 | defer func() { |
| 32 | _ = os.Chdir(originalDir) |
| 33 | }() |
| 34 | |
| 35 | require.NoError(t, os.Chdir(tmpDir), "change to temp directory for test setup") |
| 36 | |
| 37 | // Initialize git repo |
| 38 | if err := exec.Command("git", "init").Run(); err != nil { |
| 39 | t.Skip("Git not available") |
| 40 | } |
| 41 | |
| 42 | // Configure git user for commits |
| 43 | exec.Command("git", "config", "user.name", "Test User").Run() |
| 44 | exec.Command("git", "config", "user.email", "test@example.com").Run() |
| 45 | |
| 46 | // Create initial commit to establish branch |
| 47 | require.NoError(t, os.WriteFile("test.txt", []byte("test"), 0644), "create initial test file") |
| 48 | exec.Command("git", "add", "test.txt").Run() |
| 49 | if err := exec.Command("git", "commit", "-m", "Initial commit").Run(); err != nil { |
| 50 | t.Skip("Failed to create initial commit") |
| 51 | } |
| 52 | |
| 53 | // Get current branch |
| 54 | branch, err := getCurrentBranch() |
| 55 | require.NoError(t, err, "get current branch in git repository") |
| 56 | |
| 57 | // Should be on main or master branch |
| 58 | if branch != "main" && branch != "master" { |
| 59 | t.Logf("Note: branch name is %q (expected 'main' or 'master')", branch) |
| 60 | } |
| 61 | |
| 62 | // Verify it's not empty |
| 63 | assert.NotEmpty(t, branch, "getCurrentBranch should return a non-empty branch name") |
| 64 | } |
| 65 | |
| 66 | func TestGetCurrentBranchNotInRepo(t *testing.T) { |
| 67 | tmpDir := testutil.TempDir(t, "test-*") |
nothing calls this directly
no test coverage detected