Skip to content

Commit

Permalink
gitignore updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Eliot McIntire committed Oct 24, 2024
1 parent aac5fd4 commit ea38680
Showing 1 changed file with 47 additions and 28 deletions.
75 changes: 47 additions & 28 deletions R/setupProject.R
Original file line number Diff line number Diff line change
Expand Up @@ -2048,23 +2048,24 @@ setupGitIgnore <- function(paths, gitignore = getOption("SpaDES.project.gitignor
}

# ignore these folders/files
igs <- c("cachePath", "inputPath", "outputPath", ".Rproj.user", ".Rhistory",
".Rdata", ".RData", ".secret", ".secrets", ".Rprofile")

for (ig in igs) {
igRel <- if (!is.null(paths[[ig]])) {
fs::path_rel(paths[[ig]], prjP)
} else {
ig
}

if (!isAbsolutePath(igRel)) { # if igRel is inside projectPath, then add to .gitignore
if (!any(grepl(igRel, gif))) { # only add if not already there
insertLine <- length(gif)
gif[insertLine + 1] <- igRel
}
}
}
igs <- gitIgnoreInitials(paths)
# igs <- c(paths[["cachePath"]], paths[["inputPath"]], paths[["outputPath"]], ".Rproj.user", ".Rhistory",
# ".Rdata", ".RData", ".secret", ".secrets", ".Rprofile")
#
# for (ig in igs) {
# igRel <- if (!is.null(paths[[ig]])) {
# fs::path_rel(paths[[ig]], prjP)
# } else {
# ig
# }
#
# if (!isAbsolutePath(igRel)) { # if igRel is inside projectPath, then add to .gitignore
# if (!any(grepl(igRel, gif))) { # only add if not already there
# insertLine <- length(gif)
# gif[insertLine + 1] <- igRel
# }
# }
# }

# Write the file
if (length(setdiff(gif, gifOrig))) {
Expand Down Expand Up @@ -2606,24 +2607,20 @@ setupRestart <- function(updateRprofile, paths, name, inProject,
}
}

if (!isFALSE(getOption("SpaDES.project.gitignore", TRUE))) {
igs <- gitIgnoreInitials(paths)
usethis::use_git_ignore(igs)
# gert::git_add(".gitignore")
# gert::git_commit("add more .gitignores")
}

if (!rprojroot::is_git_root$testfun[[1]](pp)) {
if (needGitUserName) {
messageVerbose(msgNeedGitUserName(gitUserNamePoss), verbose = interactive() * 10)
gitUserName <- readline()
}
if (!nzchar(gitUserName))
gitUserName <- NULL
if (!isFALSE(getOption("SpaDES.project.gitignore", TRUE))) {
if (isTRUE(getOption("SpaDES.project.gitignore", TRUE))) {
igs <- c("cachePath", "inputPath", "outputPath", ".Rproj.user", ".Rhistory",
".Rdata", ".RData", ".secret", ".secrets", ".Rprofile", ".Restart*")
} else {
igs <- getOption("SpaDES.project.gitignore", TRUE)
}
usethis::use_git_ignore(igs)
# gert::git_add(".gitignore")
# gert::git_commit("add more .gitignores")
}
bbb <- try(usethis::use_git())
if (!(exists("gitUserNamePoss", inherits = FALSE)))
gitUserNamePoss <- gh::gh_whoami()$login
Expand Down Expand Up @@ -3284,3 +3281,25 @@ assignDefaults <- function(checkDefaults = c("Restart", "useGit", "setLinuxBinar
paste0("The github repository already exists: ", repo,
"\nWould you like to clone it now to ", to, "\nType (y)es or any other key for no: ")
}



gitIgnoreInitials <- function(paths) {
if (isTRUE(getOption("SpaDES.project.gitignore", TRUE))) {
igs1 <- c(".Rproj.user", ".Rhistory",
".Rdata", ".RData", ".secret", ".secrets", ".Rprofile", ".Restart*")
prjP <- paths[["projectPath"]]
igs <- c("cachePath", "inputPath", "outputPath")
igs <- vapply(igs, FUN.VALUE = character(1), function(ig) {
igRel <- if (!is.null(paths[[ig]])) {
fs::path_rel(paths[[ig]], prjP)
} else {
ig
}
igRel
})
igs <- c(igs, igs1)
} else {
igs <- getOption("SpaDES.project.gitignore", TRUE)
}
}

0 comments on commit ea38680

Please sign in to comment.