Skip to content

fix: check all git config scopes, not just --global#21

Open
jerryjrxie wants to merge 4 commits intoopenbootdotdev:mainfrom
jerryjrxie:fix/git-config-detection
Open

fix: check all git config scopes, not just --global#21
jerryjrxie wants to merge 4 commits intoopenbootdotdev:mainfrom
jerryjrxie:fix/git-config-detection

Conversation

@jerryjrxie
Copy link
Copy Markdown
Contributor

Summary

Fixes false-positive "Git user information is not configured" warnings when git identity is set in non-global scopes.

Problem

The previous implementation only checked --global git config:

output, err := RunCommandSilent("git", "config", "--global", key)

But users may have their git identity configured in:

  • Local repository config (.git/config)
  • System config (/etc/gitconfig)
  • Worktree-specific config
  • Other scopes

Solution

Now checks --global first, then falls back to checking all scopes if empty:

// Try global first (most common)
output, err := RunCommandSilent("git", "config", "--global", key)
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
}

Testing

  • go vet passes
  • Logic handles both cases: global set, global empty but local set, both empty

Note

Based on user report that git config warning appears despite git being configured. The fix ensures we detect git identity regardless of where it's set.

The previous implementation only checked --global git config, but users
may have their git identity configured in:
- Local repository config (.git/config)
- System config (/etc/gitconfig)
- Other scopes

This change first tries --global, then falls back to checking all scopes
if --global returns empty. This ensures we detect git configuration
regardless of where it's set.

Closes git config detection issue
@github-actions
Copy link
Copy Markdown

👋 Thanks for opening this pull request!

🎉 This is your first PR to OpenBoot — welcome!

Before merging:

  • Code follows existing patterns in the codebase
  • go build ./... and go vet ./... pass
  • Commit message is clear and descriptive

@fullstackjam will review this soon. Thanks for contributing! 🚀

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates git identity detection to avoid false “Git user information is not configured” warnings by checking additional git config scopes beyond --global.

Changes:

  • Update GetGitConfig to try git config --global <key> first, then fall back to git config <key> (any scope) when global is empty/unset.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +78 to +85

// Fall back to any available config (local, system, etc.)
output, err = RunCommandSilent("git", "config", key)
if err == nil {
return output
}
return output

return ""
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.

The blank lines in this function contain trailing whitespace (tabs/spaces). Please run gofmt / remove the whitespace so the file stays clean and avoids noisy diffs in future changes.

Copilot uses AI. Check for mistakes.
Comment on lines 72 to +82
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
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.
Jerry Xie and others added 3 commits March 28, 2026 22:50
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
The diffDotfiles function was always checking the local ~/.dotfiles git
state, even when comparing snapshots with empty dotfiles URLs. This
caused test failures when the user's actual dotfiles repo had uncommitted
changes.

Fix: Only check dotfiles repo state if at least one URL is configured.
If both system and reference have empty dotfiles URLs, skip the git state
check entirely.

This makes the tests deterministic and not dependent on the user's local
dotfiles repo state.
Copy link
Copy Markdown
Collaborator

@fullstackjam fullstackjam left a comment

Choose a reason for hiding this comment

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

The underlying problem is real, but the fix misses the actual callsite:

[CRITICAL] doctor.go's checkGit() is not updated
The warning users actually see comes from checkGit() in internal/cli/doctor.go, which still hardcodes --global. The PR fixes the underlying GetGitConfig helper but leaves the user-facing check broken. Please update checkGit() as well.

[HIGH] Falling back to local scope is semantically wrong here
openboot is a machine setup tool. If a user runs it from inside a repo that has a local user.name set, the fallback will find that value and skip the global git configuration wizard — leaving them with no global identity configured. The fallback should be --global--system only, not the bare git config which includes local scope.

[LOW] os.Chdir in tests is fragile
os.Chdir modifies process-global state and will cause race conditions if tests ever run in parallel. Consider passing a working directory as a parameter or using dependency injection instead.

@fullstackjam fullstackjam added the bug Something isn't working label Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants