Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
7 changes: 4 additions & 3 deletions internal/cli/doctor.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"

"github.com/openbootdotdev/openboot/internal/brew"
"github.com/openbootdotdev/openboot/internal/system"
"github.com/openbootdotdev/openboot/internal/ui"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -143,10 +144,10 @@ func checkGit() []checkResult {
status: "ok",
})

name, _ := exec.Command("git", "config", "--global", "user.name").Output()
email, _ := exec.Command("git", "config", "--global", "user.email").Output()
name := system.GetGitConfig("user.name")
email := system.GetGitConfig("user.email")

if len(strings.TrimSpace(string(name))) == 0 || len(strings.TrimSpace(string(email))) == 0 {
if name == "" || email == "" {
results = append(results, checkResult{
name: "Git identity",
status: "warn",
Expand Down
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 system config only (skip local to avoid repo-specific values)
output, err = RunCommandSilent("git", "config", "--system", 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
25 changes: 25 additions & 0 deletions internal/system/system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,28 @@ func TestRunCommandSilent_MultilineOutput(t *testing.T) {
assert.Contains(t, output, "line2")
assert.Contains(t, output, "line3")
}

// TestGetGitConfig_FallsBackToSystemScope verifies that GetGitConfig falls back
// to --system scope (not local) when --global has no value. This ensures that
// running openboot inside a repo with local git config does not skip the global
// git config wizard.
// Regression test for: git config detection issue
func TestGetGitConfig_FallsBackToSystemScope(t *testing.T) {
tmpDir := t.TempDir()
t.Setenv("HOME", tmpDir)
t.Setenv("XDG_CONFIG_HOME", tmpDir+"/nonexistent")

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

cmd = exec.Command("git", "-C", tmpDir, "config", "user.localonly", "local-value")
require.NoError(t, cmd.Run())

// GetGitConfig should NOT find the local-only value because the fallback
// is --system, not bare git config.
value := GetGitConfig("user.localonly")
assert.Equal(t, "", value, "GetGitConfig should not fall back to local config; only global and system are checked")
}
Loading