Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jennybc opened this issue Sep 12, 2024 · 2 comments
Open

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

jennybc opened this issue Sep 12, 2024 · 2 comments
Labels
bug an unexpected problem or unintended behavior git git, GitHub, and CI in general

Comments

@jennybc
Copy link
Member

jennybc commented Sep 12, 2024

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 global

I 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 global

For 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:

usethis/R/utils-git.R

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.

@jennybc jennybc added bug an unexpected problem or unintended behavior git git, GitHub, and CI in general labels Sep 12, 2024
@jennybc
Copy link
Member Author

jennybc commented 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:

~/rrr/usethis % git config --show-origin --show-scope --list
unknown file:/Library/Developer/CommandLineTools/usr/share/git-core/gitconfig   credential.helper=osxkeychain
unknown file:/Library/Developer/CommandLineTools/usr/share/git-core/gitconfig   init.defaultbranch=main
global  file:/Users/jenny/.gitconfig    user.name=Jenny Bryan
global  file:/Users/jenny/.gitconfig    [email protected]
global  file:/Users/jenny/.gitconfig    user.signingkey=/Users/jenny/.ssh/id_ed25519.pub
... and so on and so forth ...

Notably this system config is labelled as "unknown", as opposed to "global" and "local" (or even "system").

@jeroen
Copy link
Member

jeroen commented 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.defaultbranch during the installer process? So it is not specific to the version but rather to the vendor.

I think the unknown config file was hacked in by apple's git build to override some defaults in xcode. Note the path of this config is inside git-core so 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#6883

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior git git, GitHub, and CI in general
Projects
None yet
Development

No branches or pull requests

2 participants