[BUG] create_golem() doesn't restore the working directory when the hook fails, and `with_git` fails on paths with spaces
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
The two problems sit in R/create_golem.R: the setwd(path_to_golem) call near line 140 needs a restore that runs even when project_hook() errors, and the system(paste("git init", ...)) call near line 175 needs the path quoted. Run the reproduction in the issue to confirm both behaviours. Done means the working directory is restored after a failing hook and git init succeeds for a path containing spaces.
Written by the indexing model from the issue text.
Description
Describe the bug
Two issues in create_golem():
- The working directory is changed with
old <- setwd(path_to_golem)(R/create_golem.R#L140) and restored with a plainsetwd(old)later. Ifproject_hook()errors, the user is left inside the new project folder. with_git = TRUErunssystem(paste("git init", path_to_golem))(R/create_golem.R#L175) without quoting the path, so it fails whenever the path contains a space (common on macOS/Windows, e.g.~/Mes Documents/).
To Reproduce
library(golem)
setwd(tempdir())
try(
create_golem(
file.path(
tempdir(),
"app_hook"
),
open = FALSE,
check_name = FALSE,
project_hook = function(path, package_name, ...) stop("boom")
)
)
getwd()
# with_git and a space in the path
p <- file.path(
tempdir(),
"dir with space",
"app_git"
)
dir.create(dirname(p))
create_golem(
p,
open = FALSE,
check_name = FALSE,
with_git = TRUE
)
dir.exists(
file.path(
p,
".git"
)
)
Output:
Error in project_hook(path = path_to_golem, package_name = package_name, :
boom
[1] "/tmp/RtmpfiwYQq/app_hook"
x Error initializing git repository.
[1] FALSE
Expected behavior
- The working directory is restored even when the hook fails.
- The git repository is initialized regardless of spaces in the path.
Additional context
Suggested fixes: on.exit(setwd(old), add = TRUE) (or withr::with_dir()), and system2("git", c("init", shQuote(path_to_golem))).
session info
R 4.3.3, Ubuntu 24.04, {golem} master (9938a41, version 1.0.1).
Generated by Claude Code
- Dominant language
- R
- Stars
- 947
- Forks
- 135
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ThinkR-open/golem
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
ThinkR-open/golem#1265 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
ThinkR-open/golem#1259 ·
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 85/100
ThinkR-open/golem#1257 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
ThinkR-open/golem#1256 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
ThinkR-open/golem#1255 · 4 comments ·
All issues in ThinkR-open/golem
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
leppott/BioMonTools#162 ·
-
publications
Difficulty 1/5 Under an hour Newbie friendliness 85/100
epiforecasts/epiforecasts.github.io#161 ·
Maintainers usually reply within 1 day
-
Label `{sas}` chunk source as `sas` instead of `txt`, so it gets syntax highlightingPossibly taken @michaelmayer2 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
microbiome/OMA#1031 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
furrer-lab/abn#291 · 2 comments ·