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): expand user home dir first #437

Merged
merged 1 commit into from
Oct 24, 2024

Conversation

StealthyCoder
Copy link
Member

When using it like fioctl configure-git --creds-path ~/.config there is no problem however if you use it like fioctl configure-git --creds-path=~/.config there is.

The reason lies in the fact that in the first example the shell already expands the ~ into the absolute path of the homedir, in the second it will not.

@@ -74,6 +72,11 @@ func doGitCreds(cmd *cobra.Command, args []string) {
var gitHelperCommandArgs []string

helperName := "fio"
if strings.HasPrefix(helperPath, "~/") {
Copy link
Member

Choose a reason for hiding this comment

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

this is tricky:
golang/go#4140

I think this would also happen in the docker helper. After reading those bug comments like "what about Win32", I'm more inclined to check string.contains("~") and just return an error like golang chose:
golang/go@8b6534b#diff-7c289d314f17f4e276724c62cfd8dd5e2c7dffad2d900987f8eae83192ad15bdL131

Copy link
Member

@vkhoroz vkhoroz Oct 22, 2024

Choose a reason for hiding this comment

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

I agree to this.

It also raises a ton of questions like what about fioctl configure-git --creds-path='~/.config'?
(In the above case there must be no expansion, but single quotes are not passed to the program by shell).
...Or what about non-Bash shells?... which have no tilda expansion (and should not have by design).

I'd say: let the shell do its job, and let's not pretend to "fix" it... as there are so many use cases we're burrowing a rabbit hole.

Copy link
Member Author

Choose a reason for hiding this comment

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

This makes sense to me. I adjusted it to also just throw an error for both git and docker. The only difference I did, was to always throw an error regardless of OS. I actually think this will be beneficial to the end user since it conveys more information.

When using it like `fioctl configure-git --creds-path ~/.config` there
is no problem however if you use it like `fioctl configure-git
--creds-path=~/.config` there is.

The reason lies in the fact that in the first example the shell already
expands the ~ into the absolute path of the homedir, in the second it
will not.

Let's throw an error the same way golang does itself.
golang/go@8b6534b#diff-7c289d314f17f4e276724c62cfd8dd5e2c7dffad2d900987f8eae83192ad15bdL131

Signed-off-by: Eric Bode <[email protected]>
Copy link
Member

@doanac doanac left a comment

Choose a reason for hiding this comment

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

seems okay. i'll defer to @vkhoroz

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

@StealthyCoder StealthyCoder merged commit 5e5dfca into foundriesio:main Oct 24, 2024
8 checks passed
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