-
Notifications
You must be signed in to change notification settings - Fork 58
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
Refactor code for finding home directory on Windows #322
Conversation
Signed-off-by: John Blischak <jdblischak@gmail.com>
Signed-off-by: John Blischak <jdblischak@gmail.com>
The good news is that AppVeyor is running my tests. The bad news is that the tests are failing! It failed on the initial check that .gitconfig does not exist after just checking the configuration. This suggests that perhaps there is already a .gitconfig file present on AppVeyor. Based on the appveyor.yml in this repo and the appveyor helper script from r-appveyor, I don't expect there to be a .gitconfig present. I'm not sure how to debug this. The tests pass for me on my local Windows machine:
Any ideas? |
I look into it tomorrow |
R/credential.R
Outdated
} | ||
|
||
# Return the user's home directory regardless of operating system | ||
home <- function() { |
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.
I'd consider calling this git_home()
for added clarity.
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.
But it's not specific to Git because it's currently used to find the home directory for both .gitconfig
and .ssh/
. What about calling it something like user_home()
or home_user()
?
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.
@stewid Your opinion?
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.
... code for finding home directory ...
What about home_dir
?
Seems like this should be exploiting the new |
Signed-off-by: John Blischak <jdblischak@gmail.com>
@jennybc Good idea! I updated the code to check for the existence of global config file using |
I added artifacts to appveyor.yml to debug and found that "C:\Users\appveyor/.gitconfig" already exists.
Maybe it works to:
|
OK. That explains the problem then. Thanks!
Yes, I'll temporarily move that file for these tests (and only on AppVeyor). |
Had to unify AppVeyor tests of config() in tests/config.R. Signed-off-by: John Blischak <jdblischak@gmail.com>
Signed-off-by: John Blischak <jdblischak@gmail.com>
tests/config.R
Outdated
str(normalizePath("~")) | ||
str(git_config_files()) | ||
|
||
## Temporarily move AppVeyor .gitconfig |
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.
Why do you want to move .gitconfig
? Would it make more sense to write a config test that operates on local git config for a temporary repo? That would seem to require less special case-y ness.
If you're going to do such things, withr is a very handy package for doing some work in a temporarily modified state, with automatic cleanup/restoration. I don't know how much this comes up in other tests -- this would probably be a testing shift beyond the scope of this one test or PR. But worth thinking about.
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.
Why do you want to move .gitconfig? Would it make more sense to write a config test that operates on local git config for a temporary repo? That would seem to require less special case-y ness.
Because this unit test is to test if config()
creates the global .gitconfig
in the correct location on Windows.
If you're going to do such things, withr is a very handy package for doing some work in a temporarily modified state, with automatic cleanup/restoration. I don't know how much this comes up in other tests -- this would probably be a testing shift beyond the scope of this one test or PR. But worth thinking about.
withr looks super useful. I am going to have to start incorporating it into the unit tests for my own packages. However, since this isn't my repo, I am trying to follow the style of the existing tests. I'm happy to use withr if you'd prefer I do.
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.
I agree, withr
looks very useful. However, for this single case I prefer to keep it as it is and not add a dependency.
I found the bug that is causing the test to fail (at least the test is working like it should...). I'm re-building (which takes forever on Windows) and testing locally first, but will push update soon. |
Signed-off-by: John Blischak <jdblischak@gmail.com>
Signed-off-by: John Blischak <jdblischak@gmail.com>
Thanks |
The main change in this PR is refactoring
ssh_path
to create a new functionhome
that returns the user's home directory regardless of operating system. It is currently used byssh_path
andconfig
.xref: #317 #320
It also has two other minor changes:
email
toconfig
instead ofuser.email
. This generated a warning message on my local Windows machine. Should that have been detected on AppVeyor? I used the conditional statement used bytestthat::skip_on_appveyor
, but I don't know if that works outside of testthat (in other words, is the environment variable"APPVEYOR"
created by AppVeyor or testthat?).