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

Parse credential.helper command line using shell-words #680

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

arlosi
Copy link
Contributor

@arlosi arlosi commented Mar 9, 2021

Since sh is not available by default on Windows, git2-rs currently splits the credential
helper string by whitespace, which attempts to execute an invalid command line in the case
of the default credential helper on Windows.

The default git credential helper on Windows (Git Credential Manager Core) is set up as
C:/Program\ Files\ \(x86\)/Git\ Credential\ Manager\ Core/git-credential-manager-core.exe

This change resolves the issue by parsing the command line using shell_words,
which follows the unix-style parsing rules used by sh. shell-words is a small crate that
does not have any additional dependencies.

Since `sh` is not available by default on Windows, git2-rs currently splits the credential
helper string by whitespace, which attempts to execute an invalid command line in the case
of the default credential helper on Windows.

The default git credential helper on Windows (Git Credential Manager Core) is set up as
 `C:/Program\ Files\ \(x86\)/Git\ Credential\ Manager\ Core/git-credential-manager-core.exe`

This change resolves the issue by parsing the command line using `shell_words`,
which follows the unix-style parsing rules used by sh. `shell-words` is a small crate that
does not have any additional dependencies.
@alexcrichton
Copy link
Member

Thanks for this! I'm not sure if this is the right implementation for Windows, though. Do you know what git itself does in situations like this? Could/should we perhaps delegate to cmd instead of sh if it fails?

@arlosi
Copy link
Contributor Author

arlosi commented Mar 12, 2021

I think it's correct to always interpret it as a Unix shell command. git for Windows includes sh, and git always runs the credential helper command through sh.

Here's a screenshot from Process Explorer when the credential helper is prompting for credentials:
image

Running the command through cmd will fail, since the backslashes will be interpreted as directory separators instead of escapes. Using cmd would work if the user actually configured their credential.helper to use backslash separated paths, but that would break git - so it seems unlikely.

Also, the current defaults situation isn't quite as bad as I originally thought. When GCMC is installed bundled with git, its set up as manager-core, rather than the full path. Only users who installed GCMC separately will be broken (like me).

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

Successfully merging this pull request may close these issues.

2 participants