From 037dfae957d8a4be617a94bc0878049b74ff9795 Mon Sep 17 00:00:00 2001 From: Eric Bode Date: Tue, 22 Oct 2024 15:33:40 +0100 Subject: [PATCH] fix(git): throw error when using ~ 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. https://github.com/golang/go/commit/8b6534b78af791b80f371857a15d76bbc10fd012#diff-7c289d314f17f4e276724c62cfd8dd5e2c7dffad2d900987f8eae83192ad15bdL131 Signed-off-by: Eric Bode --- subcommands/docker/cmd.go | 3 +++ subcommands/git/cmd.go | 7 ++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/subcommands/docker/cmd.go b/subcommands/docker/cmd.go index c4ff9266..a3ed968b 100644 --- a/subcommands/docker/cmd.go +++ b/subcommands/docker/cmd.go @@ -122,6 +122,9 @@ func doDockerCreds(cmd *cobra.Command, args []string) { configBytes, err := subcommands.MarshalIndent(config, "", " ") subcommands.DieNotNil(err) + if strings.Contains(helperPath, "~/") { + subcommands.DieNotNil(fmt.Errorf("~ character is not supported in --creds-path=. Try to run it as --creds-path %s", helperPath)) + } dst := filepath.Join(helperPath, DOCKER_CREDS_HELPER) if runtime.GOOS == "windows" { dst += ".exe" diff --git a/subcommands/git/cmd.go b/subcommands/git/cmd.go index 7865a0cb..a965a3f1 100644 --- a/subcommands/git/cmd.go +++ b/subcommands/git/cmd.go @@ -19,9 +19,7 @@ import ( const GIT_CREDS_HELPER = "git-credential-fio" -var ( - helperPath string -) +var helperPath string func NewCommand() *cobra.Command { path, err := exec.LookPath("git") @@ -74,6 +72,9 @@ func doGitCreds(cmd *cobra.Command, args []string) { var gitHelperCommandArgs []string helperName := "fio" + if strings.Contains(helperPath, "~/") { + subcommands.DieNotNil(fmt.Errorf("~ character is not supported in --creds-path=. Try to run it as --creds-path %s", helperPath)) + } dst := filepath.Join(helperPath, GIT_CREDS_HELPER) if runtime.GOOS == "windows" { // To get around edge cases with git on Windows we use the absolute path