git util: fix Get/SetConfig error reporting

This commit is contained in:
Simone Gotti 2019-06-11 12:46:41 +02:00
parent cff6b8d531
commit f7faab353e
1 changed files with 12 additions and 8 deletions

View File

@ -154,12 +154,14 @@ func (g *Git) ConfigGet(ctx context.Context, args ...string) (string, error) {
args = append([]string{"config", "--get", "--null"}, args...) args = append([]string{"config", "--get", "--null"}, args...)
out, err := g.Output(ctx, nil, args...) out, err := g.Output(ctx, nil, args...)
if err != nil {
if exitError, ok := err.(*exec.ExitError); ok { if exitError, ok := err.(*exec.ExitError); ok {
if waitStatus, ok := exitError.Sys().(syscall.WaitStatus); ok { if waitStatus, ok := exitError.Sys().(syscall.WaitStatus); ok {
if waitStatus.ExitStatus() == 1 { if waitStatus.ExitStatus() == 1 {
return "", &ErrGitKeyNotFound{Key: args[len(args)-1]} return "", &ErrGitKeyNotFound{Key: args[len(args)-1]}
} }
} }
}
return "", err return "", err
} }
@ -170,12 +172,14 @@ func (g *Git) ConfigSet(ctx context.Context, args ...string) (string, error) {
args = append([]string{"config", "--null"}, args...) args = append([]string{"config", "--null"}, args...)
out, err := g.Output(ctx, nil, args...) out, err := g.Output(ctx, nil, args...)
if err != nil {
if exitError, ok := err.(*exec.ExitError); ok { if exitError, ok := err.(*exec.ExitError); ok {
if waitStatus, ok := exitError.Sys().(syscall.WaitStatus); ok { if waitStatus, ok := exitError.Sys().(syscall.WaitStatus); ok {
if waitStatus.ExitStatus() == 1 { if waitStatus.ExitStatus() == 1 {
return "", &ErrGitKeyNotFound{Key: args[len(args)-1]} return "", &ErrGitKeyNotFound{Key: args[len(args)-1]}
} }
} }
}
return "", err return "", err
} }