-
Notifications
You must be signed in to change notification settings - Fork 285
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 use_readme_rmd() so that a pre-commit hook is registered if pkg uses git #41
Conversation
R/readme.R
Outdated
@@ -33,7 +33,8 @@ use_readme_rmd <- function(base_path = ".") { | |||
) | |||
use_build_ignore("^README-.*\\.png$", escape = FALSE, base_path = base_path) | |||
|
|||
if (uses_git(base_path) && !file.exists(base_path, ".git", "hooks", "pre-commit")) { | |||
if (uses_git(base_path) && | |||
!file.exists(file.path(base_path, ".git", "hooks", "pre-commit"))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it would be better to create a function for constructing this url? I presume use_git_hook
also has to do the same computation. Then you can test that function
Are you still interested in finishing this off? |
Yes, but have been swamped with other commitments. Will return to it tomorrow afternoon or next week. |
R/git.R
Outdated
stop("This project doesn't use git", call. = FALSE) | ||
} | ||
|
||
base_path <- git2r::discover_repository(base_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
git2r::discover_repository()
includes the .git
as the final part of the path it constructs
R/git.R
Outdated
@@ -71,15 +71,15 @@ restart_rstudio <- function(message = NULL, base_path = ".") { | |||
#' @family git helpers | |||
#' @export | |||
use_git_hook <- function(hook, script, base_path = ".") { | |||
if (uses_git(base_path)) { | |||
if (!uses_git(base_path)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check was backwards
R/readme.R
Outdated
@@ -33,7 +33,7 @@ use_readme_rmd <- function(base_path = ".", open = TRUE) { | |||
base_path = base_path | |||
) | |||
|
|||
if (uses_git(base_path) && !file.exists(base_path, ".git", "hooks", "pre-commit")) { | |||
if (uses_git(base_path)) { | |||
use_git_hook( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use_git_hook() warns if the file exists and is different from that being created
The failing build on R/3.1 is due to something in git2r, I think, but I don't understand it. |
Can you please skip that test on R 3.1? You can use |
Done. Pushed to https://github.com/PeteHaitch/usethis but it's not showing up here in the PR nor was a Travis build triggered. Have I done something wrong? |
I resolved the conflicts here and this PR works for me now. @PeteHaitch If you will grant me permission to push into your PR, I can push an update for the tests as well, which should clear up the Travis failures. Then, if @hadley approves, we can merge this. Here's how to grant me permission to add commits to your PR: |
Hi @jennybc, I think permission is already granted (bottom right of below screenshot). And thanks for following up on this! |
@PeteHaitch Yes, indeed I can push! I don't know if I could have detected that myself, but it seemed cheeky to just start pushing into your master branch. In any case, I think this is good to go now. |
Excellent! Thanks for incorporating. I'll try to make cleaner patches so that future PRs aren't so much work on your end. |
hook_path <- file.path(".git/hooks", hook) | ||
write_over(base_path, hook_path, script) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This made me realise usethis should have a proj_path()
function for constructing paths in the current project
Thanks everyone! |
Following up on r-lib/devtools#1512
AFAICT, this small bug meant that the registration of the pre-commit hook was never triggered because the file path was not properly constructed.
I couldn't figure out how you are planning to test usethis, so I haven't ported the unit test from the original PR. Will do it if you can point me in the right direction.