r-lib / gert

Simple git client for R
https://docs.ropensci.org/gert/
Other
148 stars 32 forks source link

Setting init.defaultBranch to "main" but git_init() still creates as master #110

Closed BJWiley233 closed 3 years ago

BJWiley233 commented 3 years ago

This is more of a question but I set my .gitconfig so defaultBranch = main but when I run git_init() inside my .Rproj it seems to still create a 'master' branch. Is there an easy way to fix this? If I run git init for my other projects it defaults the HEAD to ref: refs/heads/main. How to do this for gert?

jennybc commented 3 years ago

I believe this has not yet been enacted in libgit2 but that is coming:

https://github.com/libgit2/libgit2/issues/5562

So gert gets this feature when libgit2 gets the feature.

BJWiley233 commented 3 years ago

Ok thanks. Had a feeling about that. Do we have to read through that mailing list to see what the status is?

jennybc commented 3 years ago

The git mailing list? No, because the feature is already present in command line git.

So if you want to stay current re: libgit2 (and gert), I'd subscribe to the issue linked above.

(FYI: command line git and libgit2 are 2 entirely separate code bases, believe it or not.)

jennybc commented 3 years ago

I now know that this has been implemented in libgit2 as of v1.1 "Fernweh":

https://github.com/libgit2/libgit2/blame/27e34f9b9843f7bcc33a4ccfe3e395fe303cba63/docs/changelog.md#L35

  • The init.defaultBranch setting is now respected and master is no longer the hardcoded as the default branch name.

and I have personally verified the behaviour from R (so doing git init via gert, via usethis). The libgit2 issue linked above should actually be closed and presumably will be soon.

Furthermore, the version of libgit2 that comes with the CRAN version of gert as of v1.0.2 -- at least for macOS and Windows users -- is sufficient to honour init.defaultBranch.

So I'm going to close this. The answer for macOS or Windows users is simply to re-install gert from CRAN.

jennybc commented 3 years ago

Part of why I remained confused about this for so long is that libgit2 v1.1 took a long time to make its way into homebrew (happened here https://github.com/Homebrew/homebrew-core/pull/65706) and I am often installed from a locally built version of gert. But this is also resolved as of early December.