Repository navigation
Open
Description
I discovered this in Windows Positron work. My Git for Windows installation has system-level config that sets init.defaultBranch to master. I have init.defaultBranch set to main at the user level. git_sitrep() shows this:
• Default initial branch name: "master" and "main"
which is weird!
The underlying issue is this:
dat <- gert::git_config_global()
subset(dat, name == "init.defaultbranch")
#> name value level
#> 10 init.defaultbranch master system
#> 13 init.defaultbranch main globalI think I've never personally experienced this before because here's the same information on macOS:
dat <- gert::git_config_global()
subset(dat, name == "init.defaultbranch")
#> name value level
#> 7 init.defaultbranch main globalFor the record, here are the Git versions in each location:
on macOS
git version 2.39.3 (Apple Git-145)
on Windows
git version 2.45.2.windows.1
so the Windows Git version is actually newer.
All that really matters is that usethis:::git_cfg_get() needs to account for this possibility, though:
Lines 53 to 72 in 2cc9e5a
| git_cfg_get <- function(name, where = c("de_facto", "local", "global")) { | |
| where <- match.arg(where) | |
| if (where == "de_facto") { | |
| return(git_cfg_get(name, "local") %||% git_cfg_get(name, "global")) | |
| } | |
| if (where == "global" || !uses_git()) { | |
| dat <- gert::git_config_global() | |
| } else { | |
| dat <- gert::git_config(repo = git_repo()) | |
| } | |
| if (where == "local") { | |
| dat <- dat[dat$level == "local", ] | |
| } | |
| out <- dat$value[tolower(dat$name) == tolower(name)] | |
| if (length(out) > 0) out else NULL | |
| } |
Currently it seems to basically gloss over system config and only accounts for global and local.
Reacted by Lluís Revilla
Activity
jennybc commentedon Sep 13, 2024
Interesting tidbit from macOS. It's true that
gert::git_config_global()doesn't reveal any system config, but there does seem to be some:Notably this system config is labelled as "unknown", as opposed to "global" and "local" (or even "system").
jeroen commentedon Sep 18, 2024
Haven't tested this, but from the source it looks like git-for-windows lets the user choose the "system" value of
init.defaultbranchduring the installer process? So it is not specific to the version but rather to the vendor.I think the
unknownconfig file was hacked in by apple's git build to override some defaults in xcode. Note the path of this config is insidegit-coreso it really seems specific to this build of command-line-git and not intended for other git versions or libraries. That would explain why libgit2 does not find it, but I'll ask upstream in libgit2: libgit2/libgit2#6883jennybc commentedon Jul 24, 2025
I have tinkered with this a bit, but it's actually hard to play with on macOS using Git from Xcode command line tools, because of the peculiar situation with the system config.
I'll take another look when I'm next doing dev work on Windows, where I think it will be easier for me to revisit the situation I first reported.
Use highest-precedence level in `git_cfg_get()`