Skip to content

Use highest-precedence level in git_cfg_get() - #2284

Open
taekop wants to merge 1 commit into
r-lib:mainfrom
taekop:fix-git-cfg-get-global-levels
Open

taekop wants to merge 1 commit into
r-lib:mainfrom
taekop:fix-git-cfg-get-global-levels

Conversation

@taekop

@taekop taekop commented Oct 5, 2026

Copy link
Copy Markdown

git_cfg_get() read every row from gert::git_config_global() that matched the key. That table includes the system, XDG and global levels, so a key set at two levels returned two values. git_sitrep() then printed Default initial branch name: "master" and "main", and use_git_config() warned when it tried to store the previous value.

It now keeps only the rows from the highest-precedence level (programdata < system < xdg < global < local), which is what Git itself uses. Several values at a single level are still all returned, e.g. credential.helper.

I reproduced it on macOS by putting init.defaultBranch = master in $XDG_CONFIG_HOME/git/config and main in ~/.gitconfig, then calling git_sitrep("git", "user"). It printed both values before and only "main" after.

I compared git_cfg_get() before and after across 10 config layouts (global only, XDG only, both, neither, differently cased keys, multi-valued keys at one level and at two levels, with and without a local value). Results differ only where a key is defined at more than one level.

For the test I added a small gert_config_global() wrapper so the config table can be mocked, and the test calls git_sitrep(). It fails without the fix and passes with it. The full test suite passes with the same skips as main.

Closes #2057

@taekop
taekop force-pushed the fix-git-cfg-get-global-levels branch from 7880008 to 7f33b0a Compare October 20, 2026 10:27

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

git_sitrep() can report >1 value for the default default branch

1 participant