Skip to content

Commit

Permalink
fix(git): Use absolute path instead
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Bode <[email protected]>
  • Loading branch information
StealthyCoder committed Sep 7, 2023
1 parent a7078b1 commit c6e3ecf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions subcommands/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"os"
"path/filepath"
"strings"
"text/tabwriter"

"github.com/cheynewallace/tabby"
Expand Down Expand Up @@ -292,3 +293,7 @@ func ShowPages(showPage int, next *string) {
fmt.Println()
}
}

func EncodeWhiteSpace(str string) string {
return strings.ReplaceAll(str, " ", "\\ ")
}
9 changes: 8 additions & 1 deletion subcommands/git/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func findSelf() string {
func doGitCreds(cmd *cobra.Command, args []string) {
self := findSelf()

var credsPath = cmd.Flags().Lookup("creds-path")
sudoer := os.Getenv("SUDO_USER")
var execCommand string
var gitUsernameCommandArgs []string
Expand All @@ -73,10 +74,16 @@ func doGitCreds(cmd *cobra.Command, args []string) {
helperName := "fio"
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
// So for example the following path will be used: C:/Program\\ Files/Git/bin/git-credential-fio.exe
dst += ".exe"
helperName += ".exe"
helperName = filepath.ToSlash(dst)
} else if credsPath.Changed {
helperName = dst
}

helperName = subcommands.EncodeWhiteSpace(helperName)

if len(sudoer) > 0 {
u, err := user.Lookup(sudoer)
subcommands.DieNotNil(err)
Expand Down

0 comments on commit c6e3ecf

Please sign in to comment.