Usethis: use_git() should make an initial commit, if necessary

Created on 23 Jul 2019  路  3Comments  路  Source: r-lib/usethis

TLDR:Use_git doesn't make the initial commit if the project is started already with git from Rstudio

I started a new package following the Rstudio new project > R package > git then I used some of the usethis functions to set up the package.

The history of command run is:

use_rstudio()
use_git()
use_mit_license()
use_testthat()
use_package("package")
desc::desc_normalize()
use_readme_rmd()
use_travis() # Error shown below
use_github()
use_coverage()
use_vignette("name")
?use_github
git_sitrep() # Sitrep shown below

However it failed:
different commands that relay on github remote
Despite having correctly setup the git configuration, see the git_sitrep:
Result of git_sitrep

The problem comes from use_github, which expects to find a branch. But the branch is not created in use_git because Rstudio already created the repository and then use_git doesn't continue and commit the "Initial commit".

A solution would be to check if there is any committed file by checking the repository head. This involves the line https://github.com/r-lib/usethis/blob/9ffc27fd69934c74377fd3598489cebc50ef2680/R/git.R#L14.

Which could be adapted to check if there is any committed file or any branch.

bug git

Most helpful comment

Minimal reprex:

library(usethis)
options(usethis.quiet = TRUE)

path <- create_package(tempfile())
proj_set(path)
git2r::init(proj_get())
#> Local:    /private/tmp/RtmpYSF5zd/file1414c75b8d944
#> Head:     nothing commited (yet)
use_git()
use_github()
#> Error: Detached head; can't continue

Created on 2020-03-14 by the reprex package (v0.3.0)

All 3 comments

I'll be doing a lot of "git renovation" here, probably before the next CRAN release. So I'll deal with this then.

Great to hear that (I suppose that this is specially difficult for newcomers who are not sure which guidelines follow so I hope it can be fixed soon).

Minimal reprex:

library(usethis)
options(usethis.quiet = TRUE)

path <- create_package(tempfile())
proj_set(path)
git2r::init(proj_get())
#> Local:    /private/tmp/RtmpYSF5zd/file1414c75b8d944
#> Head:     nothing commited (yet)
use_git()
use_github()
#> Error: Detached head; can't continue

Created on 2020-03-14 by the reprex package (v0.3.0)

Was this page helpful?
0 / 5 - 0 ratings