Skip to content

Commit

Permalink
rm system("git ...") calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Eliot McIntire committed Oct 22, 2024
1 parent c940745 commit f68ca2a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 29 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Description: Quickly setup a 'SpaDES' project directories and add modules using
URL:
https://spades-project.predictiveecology.org/,
https://github.com/PredictiveEcology/SpaDES.project
Date: 2024-08-02
Version: 0.1.0.9008
Date: 2024-10-21
Version: 0.1.0.9009
Authors@R: c(
person("Eliot J B", "McIntire", email = "[email protected]",
role = c("aut", "cre"), comment = c(ORCID = "0000-0002-6914-8316")),
Expand All @@ -23,7 +23,7 @@ Imports:
data.table,
fs,
methods,
Require (>= 0.3.1.9082),
Require (>= 1.0.0),
rprojroot,
rstudioapi,
tools,
Expand Down
58 changes: 32 additions & 26 deletions R/setupProject.R
Original file line number Diff line number Diff line change
Expand Up @@ -1351,45 +1351,53 @@ setupModules <- function(name, paths, modules, inProject, useGit = getOption("Sp

prev <- setwd(file.path(paths[["modulePath"]]))
cloneOrSubmodule <- if (isTRUE(isLocalGitRepoAlready)) {
"submodule add"
gert::git_submodule_add
# "submodule add"
} else {
"clone"
gert::git_clone
# "clone"
}

cmd <- paste0("git ", cloneOrSubmodule," https://github.com/", modPath)

for (i in 1:2) {
system(cmd)
if (dir.exists(file.path(paths[["modulePath"]], split$repo)))
break
if (getOption("SpaDES.project.forceGit", TRUE)) {
messageVerbose("It looks like the submodule was deleted; restoring it.\n",
"Set options('SpaDES.project.forceGit' = FALSE) to prevent this", verbose = verbose)
verbose <<- max(0, verbose - 1)
cmd2 <- strsplit(cmd, cloneOrSubmodule)[[1]]
cmd <- paste0(cmd2[1], cloneOrSubmodule, " --force", tail(cmd2, 1))
}
}
# cmd <- paste0("git ", cloneOrSubmodule," https://github.com/", modPath)
# setwd(paths[["modulePath"]])
# gert::git_submodule_add("https://github.com/cboisvenue/spadesCBM", path = "modules/spadesCBM")
out <- cloneOrSubmodule(paste0("https://github.com/", modPath),
path = file.path(basename(paths[["modulePath"]]), basename(modPath)))

# for (i in 1:2) {
# system(cmd)
# if (dir.exists(file.path(paths[["modulePath"]], split$repo)))
# break
# if (getOption("SpaDES.project.forceGit", TRUE)) {
# messageVerbose("It looks like the submodule was deleted; restoring it.\n",
# "Set options('SpaDES.project.forceGit' = FALSE) to prevent this", verbose = verbose)
# verbose <<- max(0, verbose - 1)
# cmd2 <- strsplit(cmd, cloneOrSubmodule)[[1]]
# cmd <- paste0(cmd2[1], cloneOrSubmodule, " --force", tail(cmd2, 1))
# }
# }

} else {
messageVerbose("module exists at ", localPath, "; not cloning", verbose = verbose)
}
reportBranch <- TRUE
# if (!grepl("master|main|HEAD", split$br)) {
prev <- setwd(file.path(paths[["modulePath"]], split$repo))
cmd <- "git rev-parse --abbrev-ref HEAD"
# next line -- cd doesn't work on my windows; no idea why
# cmd <- paste0("cd ", file.path(paths[["modulePath"]], split$repo), " && git rev-parse --abbrev-ref HEAD ")
curBr <- system(cmd, intern = TRUE)
curBr <- gert::git_branch()

# cmd <- "git rev-parse --abbrev-ref HEAD"
# curBr <- system(cmd, intern = TRUE)
if (!identical(split$br, curBr)) {
prev <- setwd(file.path(paths[["modulePath"]], split$repo))
cmd <- paste0("git checkout ", split$br)
system(cmd)
gert::git_branch_checkout(split$br)
# cmd <- paste0("git checkout ", split$br)
# system(cmd)
reportBranch <- FALSE
}
gert::git_pull()
# }
cmd <- paste0("git pull")
system(cmd)
# cmd <- paste0("git pull")
# system(cmd)

if (reportBranch)
messageVerbose("\b ... on ", split$br, " branch")
Expand Down Expand Up @@ -3047,8 +3055,6 @@ checkGitRemote <- function(name, paths) {
usethis::use_github(gitUserName)
stop_quietly()
}
# usethis::use_github(gitUserName, private = FALSE)
# system("git init -b main")
} else {
message("It looks like the remote Git repo exists (",file.path(gitUserName, name),
"). Would you like to clone it now to ", paths[["projectPath"]], "?")
Expand Down

0 comments on commit f68ca2a

Please sign in to comment.