Skip to content

Commit

Permalink
Merge b07febf into 057829d
Browse files Browse the repository at this point in the history
  • Loading branch information
Songmu committed Jul 24, 2020
2 parents 057829d + b07febf commit 19595ed
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
22 changes: 16 additions & 6 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ type Config struct {
System, Global, Local bool
File string
Cd string
GitPath string
}

func (c *Config) git() string {
if c.GitPath != "" {
return c.GitPath
}
return "git"
}

// Do the git config
Expand All @@ -36,15 +44,17 @@ func (c *Config) Do(args ...string) (string, error) {
}

gitArgs = append(gitArgs, args...)
cmd := exec.Command("git", gitArgs...)
cmd := exec.Command(c.git(), gitArgs...)
cmd.Stderr = os.Stderr

buf, err := cmd.Output()
if exitError, ok := err.(*exec.ExitError); ok {
if waitStatus, ok := exitError.Sys().(syscall.WaitStatus); ok {
if waitStatus.ExitStatus() == 1 {
return "", notFound(
fmt.Sprintf("config not found. args: %q", strings.Join(gitArgs, " ")))
if err != nil {
if exitError, ok := err.(*exec.ExitError); ok {
if waitStatus, ok := exitError.Sys().(syscall.WaitStatus); ok {
if waitStatus.ExitStatus() == 1 {
return "", notFound(
fmt.Sprintf("config not found. args: %q", strings.Join(gitArgs, " ")))
}
}
}
return "", err
Expand Down
9 changes: 9 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,12 @@ vcs = hg
})
}
}

func TestConfigDo_nogit(t *testing.T) {
c := &Config{GitPath: "dummy"}

_, err := c.Do("hoge")
if err == nil {
t.Errorf("error shouldn't be nil")
}
}

0 comments on commit 19595ed

Please sign in to comment.