Skip to content
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

Using system2() to call git on Windows leads to issue #24

Closed
cderv opened this issue Dec 9, 2021 · 6 comments
Closed

Using system2() to call git on Windows leads to issue #24

cderv opened this issue Dec 9, 2021 · 6 comments

Comments

@cderv
Copy link
Collaborator

cderv commented Dec 9, 2021

I think this is a limitation of using command line tool to deal with git instead of packages like gert

xfun::crandalf_check() will run command git() which is basically system2('git', ...).
Unfortunately, on Windows this lead to issues.
For example:

> xfun:::git(c('merge', 'main'))
Committer identity unknown

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

However, I am set up

❯ git config user.name
Christophe Dervieux
❯ git config user.email
christophe.dervieux@gmail.com

I think this is because of the working directory ~ not being the same while I run git in terminal or run it through R command to call system tool.

When using system2(), it will look for global config file in C:/Users/chris/Documents/.gitconfig, whereas the file is in C:/Users/chris/.gitconfig which is where command line Git use. This is probably because of R - IDK.

Using special tool like gert or git2r does not have this issues, because they use a lib (C or C++ probably) and it does not have this issue.

Anyway, opening this issue so that this limitation is documented. I'll find a workaround or use Linux, until I find a solution to this if any.

@yihui
Copy link
Owner

yihui commented Dec 9, 2021

Perhaps temporarily changing HOME to USERPROFILE can fix it. That is,

env = xfun::set_envvar(c(HOME = Sys.getenv('USERPROFILE'))
on.exit(xfun::set_envvar(env))

I don't know why R adds Documents after the HOME variable.

@cderv
Copy link
Collaborator Author

cderv commented Dec 9, 2021

I'll try that.

But this is a another specificity of Windows where ~ does not mean the same thing between OS in R.

I remember a discussion on this, but I can't find it yet. I know this is really painful.

Basically

> Sys.getenv("R_USER")
[1] "C:\\Users\\chris\\Documents"
> Sys.getenv("HOME")
[1] "C:\\Users\\chris\\Documents"

https://cran.r-project.org/bin/windows/base/rw-FAQ.html#What-are-HOME-and-working-directories_003f

This is how the default is set. I can probably modify that as you suggest

@yihui
Copy link
Owner

yihui commented Dec 9, 2021

That's interesting. I have never realized this difference until today. Anyway, xfun:::git() was just a quick and simple wrapper function that I didn't expect to be widely used by others, and obviously I've never tested it on Windows (so thanks for testing it!).

@cderv
Copy link
Collaborator Author

cderv commented Dec 10, 2021

Oh yeah I know it was a quick wrapper untested :) You just happen to have a teammate using Windows 😅

That is to avoid this differences between OS that something tools using other generic lib are safer (like gert or git2r) as not using the CLI tool. Also that is to make things on the same level for all OS that fs has been done I think (in fs, ~ means USERPROFILE on Windows too).

I'll make the adaptation so that I can use the tooling for our team. I don't think this will be widely use by others so we'll continue adapt as needed I guess.

@cderv
Copy link
Collaborator Author

cderv commented Dec 10, 2021

I have pushed a fix in yihui/xfun@7e511f6

> system2('git', c('config', 'user.name'), stdout = TRUE)
character(0)
attr(,"status")
[1] 1
Warning message:
In system2("git", c("config", "user.name"), stdout = TRUE) :
  running command '"git" config user.name' had status 1

> xfun:::git(c('config', 'user.name'))
Christophe Dervieux

So that should prevent error for me from now on.

@cderv cderv closed this as completed Dec 10, 2021
@yihui
Copy link
Owner

yihui commented Dec 10, 2021

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants