Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
14 changes: 11 additions & 3 deletions internal/system/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,19 @@ 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
}
return output

return ""
}

func GetExistingGitConfig() (name, email string) {
Expand Down
18 changes: 18 additions & 0 deletions internal/system/system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,21 @@ 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 temporary git config file
gitConfigDir := tmpDir + "/.config/git"
os.MkdirAll(gitConfigDir, 0755)

// Test that GetGitConfig returns empty when nothing is set
value := GetGitConfig("user.testkey")
// If git is not installed or no config exists, should return empty
// The function tries --global first, then falls back to any scope
assert.IsType(t, "", value)
}
Loading