git2r icon indicating copy to clipboard operation
git2r copied to clipboard

`git add`: `force = TRUE` has no effect

Open pat-s opened this issue 5 years ago • 3 comments

Also tested with {gert}. Maybe an issue of ligbit2? Using git directly works.

library(git2r)
library(withr)
with_dir("~/git/mlr-org/mlr3gallery/", {
  status()
  git2r::add(".", "docs/CNAME", force = TRUE)
  # file should have been added
  status()
  system2("git", c("add", "docs/CNAME", "--force"))
  # file is added now - why not from git2r?
  status()
})
#> Staged changes:
#>  New:        docs/CNAME

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

Session info
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                                      
#>  version  R version 4.0.0 Patched (2020-04-30 r78337)
#>  os       macOS Catalina 10.15.4                     
#>  system   x86_64, darwin17.0                         
#>  ui       X11                                        
#>  language (EN)                                       
#>  collate  en_US.UTF-8                                
#>  ctype    en_US.UTF-8                                
#>  tz       Europe/Berlin                              
#>  date     2020-05-05                                 
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version    date       lib source                       
#>  assertthat    0.2.1      2019-03-21 [1] CRAN (R 4.0.0)               
#>  backports     1.1.6      2020-04-05 [1] CRAN (R 4.0.0)               
#>  callr         3.4.3      2020-03-28 [1] CRAN (R 4.0.0)               
#>  cli           2.0.2      2020-02-28 [1] CRAN (R 4.0.0)               
#>  crayon        1.3.4.9000 2020-04-23 [1] Github (r-lib/crayon@dcf6d44)
#>  desc          1.2.0      2018-05-01 [1] CRAN (R 4.0.0)               
#>  devtools      2.3.0      2020-04-10 [1] CRAN (R 4.0.0)               
#>  digest        0.6.25     2020-02-23 [1] CRAN (R 4.0.0)               
#>  ellipsis      0.3.0      2019-09-20 [1] CRAN (R 4.0.0)               
#>  evaluate      0.14       2019-05-28 [1] CRAN (R 4.0.0)               
#>  fansi         0.4.1      2020-01-08 [1] CRAN (R 4.0.0)               
#>  fs            1.4.1      2020-04-04 [1] CRAN (R 4.0.0)               
#>  git2r       * 0.27.1     2020-05-03 [1] CRAN (R 4.0.0)               
#>  glue          1.4.0      2020-04-03 [1] CRAN (R 4.0.0)               
#>  highr         0.8        2019-03-20 [1] CRAN (R 4.0.0)               
#>  htmltools     0.4.0      2019-10-04 [1] CRAN (R 4.0.0)               
#>  knitr         1.28       2020-02-06 [1] CRAN (R 4.0.0)               
#>  magrittr      1.5        2014-11-22 [1] CRAN (R 4.0.0)               
#>  memoise       1.1.0      2017-04-21 [1] CRAN (R 4.0.0)               
#>  pkgbuild      1.0.7      2020-04-25 [1] CRAN (R 4.0.0)               
#>  pkgload       1.0.2      2018-10-29 [1] CRAN (R 4.0.0)               
#>  prettyunits   1.1.1      2020-01-24 [1] CRAN (R 4.0.0)               
#>  processx      3.4.2      2020-02-09 [1] CRAN (R 4.0.0)               
#>  ps            1.3.2      2020-02-13 [1] CRAN (R 4.0.0)               
#>  R6            2.4.1      2019-11-12 [1] CRAN (R 4.0.0)               
#>  Rcpp          1.0.4.6    2020-04-09 [1] CRAN (R 4.0.0)               
#>  remotes       2.1.1      2020-02-15 [1] CRAN (R 4.0.0)               
#>  rlang         0.4.6      2020-05-02 [1] CRAN (R 4.0.0)               
#>  rmarkdown     2.1        2020-01-20 [1] CRAN (R 4.0.0)               
#>  rprojroot     1.3-2      2018-01-03 [1] CRAN (R 4.0.0)               
#>  sessioninfo   1.1.1      2018-11-05 [1] CRAN (R 4.0.0)               
#>  stringi       1.4.6      2020-02-17 [1] CRAN (R 4.0.0)               
#>  stringr       1.4.0      2019-02-10 [1] CRAN (R 4.0.0)               
#>  testthat      2.3.2      2020-03-02 [1] CRAN (R 4.0.0)               
#>  usethis       1.6.1.9000 2020-05-04 [1] local                        
#>  withr       * 2.2.0      2020-04-20 [1] CRAN (R 4.0.0)               
#>  xfun          0.13       2020-04-13 [1] CRAN (R 4.0.0)               
#>  yaml          2.2.1      2020-02-01 [1] CRAN (R 4.0.0)               
#> 
#> [1] /Users/pjs/Library/R/4.0/library
#> [2] /Library/Frameworks/R.framework/Versions/4.0/Resources/library

pat-s avatar May 05 '20 21:05 pat-s

@pat-s Is docs/ listed in your .gitignore? It's my understanding that libgit2 can force add files that were specifically ignored, but it can't force add files within ignored subdirectories. See my PR #290. It contains unit tests to confirm this behavior, but I don't know how to best solve it.

jdblischak avatar Jul 15 '21 17:07 jdblischak

At this point in history it seems docs/ was not in .gitignore.

but it can't force add files within ignored subdirectories

That's good to know!

pat-s avatar Jul 16 '21 07:07 pat-s

At this point in history it seems docs/ was not in .gitignore.

I must be missing something, because I don't see any pattern in that .gitignore that would ignore docs/CNAME. In other words, I don't see why --force would be needed in this situation in the first place.

Regardless though, the conclusion is still that libgit2 doesn't behave the same as Git itself when interpreting .gitignore and --force.

jdblischak avatar Jul 23 '21 20:07 jdblischak