r-lib/usethis

use_git_config() behavior inconsistent with article

ijlyttle opened this issue · 4 comments

Edit: I did not look at this carefully enough; as @cderv points out, this is very likely a documentation issue.


As best as I can tell, this was working in usethis 1.4.0:

## reveals config, even if not changing anything
use_git_config()

I updated one of my machines to the dev version, and it returns without printing anything to the screen.

The operative code in usethis seems to be in an internal function git_config(), which then calls git2r::config():

usethis/R/git-utils.R

Lines 297 to 310 in 37a774e

git_config <- function(..., .repo = NULL) {
values <- list(...)
if (is.null(.repo)) {
old <- git2r::config()$global[names(values)]
do.call(git2r::config, c(list(global = TRUE), values))
} else {
old <- git2r::config(.repo)$local[names(values)]
do.call(git2r::config, c(list(repo = .repo), values))
}
names(old) <- names(values)
invisible(old)
}

When I updated my usethis, it updated git2r 0.24.0 -> 0.25.2

Happy to dig further, but wanted to surface this now in case you had some ideas already.

Thanks!

Upon further consideration, I suspect a "culprit" is the invisible(old) line that returns from usethis:::git_config(), not git2r.

cderv commented

@ijlyttle I think this is an intended change as it is documented in the NEWS file for the current dev version.

use_git_config() now invisibly returns the previous values of the settings.

and it is in place since since bbc6b47

also documented

usethis/R/git.R

Line 105 in f08ecb6

#' @return Invisibly, the previous values of the modified components.

Before that, yes this function was returning visibly all the time for user name and email only

usethis/R/git.R

Lines 132 to 133 in a4c0113

nms <- c("user.name", "user.email")
return(stats::setNames(cfg[nms], nms))

now it returns invisibly only the modified values.

I guess only usethis-setup.Rmd should be updated ?
Unless old behaviour should be restored by printing configuration if interactive() and no value to modify is provided : usethis::use_git_config() ? or like a possible git_config_sitrep() ?
However, git2r::config() does exactly this and return a pretty descent list with all the configuration if nothing is modified.

Hi @cderv,

Of course, you are correct; my understanding was incomplete, I needed to look more-thoroughly :)

Given that this is the intended behavior of use_git_config(), I concur with @cderv's suggestion that usethis-setup.Rmd be updated, and I would be happy to make such a PR.

image

Yes I'd appreciate a change to the setup vignette. Note that I just pushed a bit of a update to that document myself. But I didn't touch this stuff.