r-lib / gert

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

git_config_global() options being forced to lowercase #133

Closed zkamvar closed 3 years ago

zkamvar commented 3 years ago

I was experiencing the same problem as #110, and I noticed that init.defaultBranch is set to lowercase in the output of gert::git_config_global():

head(gert::git_config_global())
#> # A tibble: 6 x 3
#>   name               value                                level 
#>   <chr>              <chr>                                <chr> 
#> 1 include.path       /Users/zhian/config-files/.gitconfig global
#> 2 init.defaultbranch main                                 global
#> 3 pull.rebase        false                                global
#> 4 color.ui           true                                 global
#> 5 alias.lg           !git lg1                             global
#> 6 alias.lg1          !git lg1-specific --all              global
gert::libgit2_config()$version
#> [1] '1.1.0'

Created on 2021-03-22 by the reprex package (v1.0.0)

In my configuration file, however, the B is upper case: https://github.com/zkamvar/config-files/blob/master/.gitconfig

jeroen commented 3 years ago

I think that is expected, option names are not case sensitive.

Can you please include code if the bug, if any? This works for me:

library(gert)
stopifnot(libgit2_config()$version >= "1.1")
repo <- git_init(tempfile())
writeLines('hello', file.path(repo, 'test.txt'))
git_add('test.txt', repo = repo)
git_commit('This is a test', repo = repo)
git_branch_list(repo = repo)
# A tibble: 1 x 6
#  name  local ref         upstream commit                    updated
#* <chr> <lgl> <chr>       <chr>    <chr>                     <dttm>
#1 main  TRUE  refs/heads… NA       0fd28d59cdfd5f35175c3281… 2021-03-25 15:35:41
zkamvar commented 3 years ago

You are correct. It works for me:

library(gert)
#> Linking to libgit2 v1.1.0, ssh support: YES
#> Global config: /Users/zhian/.gitconfig
#> Default user: Zhian N. Kamvar <zkamvar@gmail.com>
stopifnot(libgit2_config()$version >= "1.1")
repo <- git_init(tempfile())
writeLines('hello', file.path(repo, 'test.txt'))
git_add('test.txt', repo = repo)
#> # A tibble: 1 x 3
#>   file     status staged
#>   <chr>    <chr>  <lgl> 
#> 1 test.txt new    TRUE
git_commit('This is a test', repo = repo)
#> [1] "d34f7b456f5f4dff3b13b7c0eb2b666fe4c6fcb9"
git_branch_list(repo = repo)
#> # A tibble: 1 x 6
#>   name  local ref         upstream commit                    updated            
#> * <chr> <lgl> <chr>       <chr>    <chr>                     <dttm>             
#> 1 main  TRUE  refs/heads… <NA>     d34f7b456f5f4dff3b13b7c0… 2021-03-25 08:18:49

Created on 2021-03-25 by the reprex package (v1.0.0)

I think this means that this is an issue in {usethis} where this line should be changed to be case-insensitive: https://github.com/r-lib/usethis/blob/29192cf7e485c7bb29b64d6394aac13909a30880/R/utils-git.R#L63

Should I open an issue there?

jennybc commented 3 years ago

I don't really understand why gert changes the case, though. Does that serve some purpose?

jeroen commented 3 years ago

This is done by libgit2, not gert. I don't know why, I suspect to normalize the option names if they are in fact case insensitive. We'd have to ask @ethomson to be sure.

jennybc commented 3 years ago

Ah, I see. I guess that suggests that I (meaning: usethis) should become case insensitive re: git config keys.

jeroen commented 3 years ago

It is mentioned here in the documentation: https://libgit2.org/libgit2/#HEAD/type/git_config_entry that the name gets indeed normalized.

Indeed I think you should wrap both sides in tolower() in usethis when comparing/searching by key names.

zkamvar commented 3 years ago

I think it would also be worthwhile to document this in the {gert} documentation. I can make a PR suggestion if you would like.

jeroen commented 3 years ago

@zkamvar yes that sounds good, feel free to send a PR to improve the docs. Please keep the wording concise, with a link to the canonical source (libgit2 docs) for more details.