Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions internal/diff/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ func diffDotfiles(systemURL, referenceURL string) *DotfilesDiff {
dd.RepoChanged = &ValueChange{System: systemURL, Reference: referenceURL}
}

// Only check local dotfiles repo state if dotfiles are actually configured
// If both URLs are empty, there's no dotfiles setup to check
if sysNorm == "" && refNorm == "" {
return dd
}

// Check local dotfiles repo for dirty state
home, err := os.UserHomeDir()
if err != nil {
Expand Down
13 changes: 10 additions & 3 deletions internal/system/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,18 @@ func InstallHomebrew() error {
}

func GetGitConfig(key string) string {
// Try global first (most common)
output, err := RunCommandSilent("git", "config", "--global", key)
if err != nil {
return ""
if err == nil && output != "" {
return output
}
// Fall back to any available config (local, system, etc.)
output, err = RunCommandSilent("git", "config", key)
if err == nil {
return output
Comment on lines 72 to +81
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change adds new behavior (fallback to non-global git config scopes), but the existing tests only validate the global case. Please add a test that sets user.name/user.email in a local repo config (or system config) while keeping global unset, and assert GetGitConfig returns the non-global value to prevent regressions of the original bug.

Copilot uses AI. Check for mistakes.
}
return output

return ""
}

func GetExistingGitConfig() (name, email string) {
Expand Down
35 changes: 35 additions & 0 deletions internal/system/system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,38 @@ func TestRunCommandSilent_MultilineOutput(t *testing.T) {
assert.Contains(t, output, "line2")
assert.Contains(t, output, "line3")
}

// TestGetGitConfig_FallsBackToAnyScope verifies that GetGitConfig checks all git config scopes,
// not just --global. This handles cases where user.name/user.email are set in local or system config.
// Regression test for: git config detection issue
func TestGetGitConfig_FallsBackToAnyScope(t *testing.T) {
tmpDir := t.TempDir()
t.Setenv("HOME", tmpDir)

// Create a git repo in tmpDir
cmd := exec.Command("git", "init")
cmd.Dir = tmpDir
if err := cmd.Run(); err != nil {
t.Skip("git not installed, skipping")
}

// Set a local config value (not global)
cmd = exec.Command("git", "config", "user.localtest", "local-value")
cmd.Dir = tmpDir
require.NoError(t, cmd.Run())

// Change to the tmpDir so git can find the local config
oldWd, _ := os.Getwd()
os.Chdir(tmpDir)
defer os.Chdir(oldWd)

// Set XDG_CONFIG_HOME to avoid reading global git config
oldXdg := os.Getenv("XDG_CONFIG_HOME")
os.Setenv("XDG_CONFIG_HOME", tmpDir+"/nonexistent")
defer os.Setenv("XDG_CONFIG_HOME", oldXdg)

// The global config should be empty since we changed HOME
// but the local config should be found via fallback
value := GetGitConfig("user.localtest")
assert.Equal(t, "local-value", value, "GetGitConfig should fall back to local config when global is not set")
}
Loading