Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix install with submodules #408

Merged
merged 2 commits into from
Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,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 @@ -84,7 +84,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)

})