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

fix(git): Use absolute path instead #264

Merged

Conversation

StealthyCoder
Copy link
Member

@StealthyCoder StealthyCoder commented Sep 6, 2023

Installing git on Windows will most likely place it in the Program Files directory.

Following our own docs on Windows will run the command as Administrator and place the resulting credential helper in C:\Program Files\Git\bin\. In order to make it work as seamless as possible on Windows we use the absolute path configuration for the credential helper in the .gitconfig file managing the global configuration for git.

On Windows the absolute path has to be converted into a different format.

  1. All \ have to become /
  2. All spaces have to be 'escaped' making a into \\

This works around symlinks, permission errors and other edge cases on Windows.

subcommands/git/cmd.go Outdated Show resolved Hide resolved
subcommands/git/cmd.go Outdated Show resolved Hide resolved
@StealthyCoder StealthyCoder force-pushed the fix/windows_git_helper branch 5 times, most recently from b2a2cb8 to c6e3ecf Compare September 7, 2023 11:02
}

helperName = subcommands.EncodeWhiteSpace(helperName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm now confused by this whole PR. I think the normal case (not windows i guess) is to:

  • find a directory in $PATH we can write to
  • link file fioctl -> git-credential-fio
  • run git config ... to set the helper

The whole point of finding something in $PATH is so we don't need absolute paths?

It almost sounds like on windows - we aren't finding something in the user's actual path?

If we do need absolute paths, rather than trying to "encode" (nitpick - I think we are escaping) - we probably need to put quotes around what we present to git-config. That way what winds up in git config looks like:

helper = "c:\\program files\blah.exe"

I suspect the quotations would address things beyond spaces we haven't considered.

That said - seems like the bug is that we can't find PATH correctly on windows

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, the problem partly stems from us requiring the user to run as root/Administrator and the PATHS being different for them on Windows. I will briefly look into a way if you can easily get the original calling user on Windows. If that is the case we could either add in logic to add things to the PATH for that user, or place the symlink into one of the places in their PATH locations. Then we can drop this special case for Windows again, apart from the naming having an extra .exe. 👍

Copy link
Member

@vkhoroz vkhoroz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I'm fine to merge this as long as @doanac is fine with it.

@StealthyCoder StealthyCoder merged commit 1065ca4 into foundriesio:main Sep 12, 2023
@StealthyCoder StealthyCoder deleted the fix/windows_git_helper branch September 12, 2023 11:36
detsch pushed a commit to detsch/fioctl that referenced this pull request Sep 22, 2023
detsch pushed a commit to detsch/fioctl that referenced this pull request Sep 22, 2023
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.

3 participants