Skip to content

Commit

Permalink
fix(git): throw error when using ~
Browse files Browse the repository at this point in the history
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 <eric.bode@foundries.io>
  • Loading branch information
StealthyCoder committed Oct 24, 2024
1 parent 180e304 commit 5e5dfca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 3 additions & 0 deletions subcommands/docker/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 4 additions & 3 deletions subcommands/git/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5e5dfca

Please sign in to comment.