Skip to content

Commit 7db09da

Browse files
author
Jerry Xie
committed
test: add test for git config scope fallback
Adds TestGetGitConfig_FallsBackToAnyScope to verify that GetGitConfig checks all git config scopes (global, local, system) when looking for user.name and user.email, not just --global. Related to git config detection issue
1 parent ed44eee commit 7db09da

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

internal/system/system_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,3 +302,21 @@ func TestRunCommandSilent_MultilineOutput(t *testing.T) {
302302
assert.Contains(t, output, "line2")
303303
assert.Contains(t, output, "line3")
304304
}
305+
306+
// TestGetGitConfig_FallsBackToAnyScope verifies that GetGitConfig checks all git config scopes,
307+
// not just --global. This handles cases where user.name/user.email are set in local or system config.
308+
// Regression test for: git config detection issue
309+
func TestGetGitConfig_FallsBackToAnyScope(t *testing.T) {
310+
tmpDir := t.TempDir()
311+
t.Setenv("HOME", tmpDir)
312+
313+
// Create a temporary git config file
314+
gitConfigDir := tmpDir + "/.config/git"
315+
os.MkdirAll(gitConfigDir, 0755)
316+
317+
// Test that GetGitConfig returns empty when nothing is set
318+
value := GetGitConfig("user.testkey")
319+
// If git is not installed or no config exists, should return empty
320+
// The function tries --global first, then falls back to any scope
321+
assert.IsType(t, "", value)
322+
}

0 commit comments

Comments
 (0)