Skip to content

Commit

Permalink
Fix install with submodules (#408)
Browse files Browse the repository at this point in the history
* manage installation from a repo where there are submodules (+ update broken example from README)

* update NEWS.md file
  • Loading branch information
pommedeterresautee authored Feb 13, 2020
1 parent f75e4be commit 1f8a3b2
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 15 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@

* git submodules now work if the submodule file is empty (@muschellij2, #234)

* git submodules now work if the R package is stored in a subfolder (@pommedeterresautee, #233)

* `install_gitlab()` no longer adds the access token twice to the request
(@aornugent, #363).

Expand Down
2 changes: 1 addition & 1 deletion R/install-remote.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ install_remote <- function(remote,
source <- source_pkg(bundle, subdir = remote$subdir)
on.exit(unlink(source, recursive = TRUE), add = TRUE)

update_submodules(source, quiet)
update_submodules(source, remote$subdir, quiet)

add_metadata(source, remote_metadata(remote, bundle, source, remote_sha))

Expand Down
14 changes: 12 additions & 2 deletions R/submodule.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,20 @@ update_submodule <- function(url, path, branch, quiet) {
git(paste0(args, collapse = " "), quiet = quiet)
}

update_submodules <- function(source, quiet) {
update_submodules <- function(source, subdir, quiet) {
file <- file.path(source, ".gitmodules")

if (!file.exists(file)) {
return()

if (!is.null(subdir)) {
nb_sub_folders <- lengths(strsplit(subdir, "/"))
source <- do.call(file.path, as.list(c(source, rep("..", nb_sub_folders))))
}

file <- file.path(source, ".gitmodules")
if (!file.exists(file)) {
return()
}
}
info <- parse_submodules(file)

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ If the R package is inside a subdirectory of the root directory,
then give this subdirectory as well:

```r
remotes::install_github("dmlc/xgboost/R-package")
# build = FALSE because of some specificities of XGBoost package
install_github("dmlc/xgboost/R-package", build = FALSE)
```

To install a certain branch or commit or tag, append it to the
Expand Down
16 changes: 13 additions & 3 deletions inst/install-github.R

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions install-github.R

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions man/install_version.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/testthat/test-submodule.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ test_that("Can install a repo with a submodule", {

writeLines("^bar$", build_ignore)

update_submodules("submodule", quiet = TRUE)
update_submodules("submodule", NULL, quiet = TRUE)
expect_true(dir.exists(file.path("submodule", "R")))
expect_false(dir.exists(file.path("submodule", "bar")))

Expand Down Expand Up @@ -154,6 +154,6 @@ test_that("Can update a submodule with an empty .gitmodules submodule", {

writeLines("^bar$", build_ignore)

update_submodules("submodule", quiet = TRUE)
update_submodules("submodule", NULL, quiet = TRUE)

})

0 comments on commit 1f8a3b2

Please sign in to comment.