diff options
| author | Yann Kerhervé <yann.kerherve@gmail.com> | 2014-12-19 15:35:35 -0800 |
|---|---|---|
| committer | Andrew Gerrand <adg@golang.org> | 2014-12-22 01:37:53 +0000 |
| commit | 5a8749f0a02575c44b2e68f9a74a88f401e36465 (patch) | |
| tree | 2b93f81ad843b32eb4277bbfb12dab4d2e46b163 /git-codereview/review.go | |
| parent | 4b0c4ea98aa4c2daec3ff6023260d9953d93c014 (diff) | |
| download | go-x-review-5a8749f0a02575c44b2e68f9a74a88f401e36465.tar.xz | |
git-codereview: fix .netrc authentication
.netrc credentials were clobbered by missing Git cookiefile. The command
to get the output of `git config http.cookiefile` was exiting the
program before it got a chance to see if any .netrc file were defined.
Remove redundancy in handling error of `git config remote.origin.url`.
Change-Id: I1e08710b4e9b154b8fa5ebfb3c2ce72ef4dd2360
Reviewed-on: https://go-review.googlesource.com/1867
Reviewed-by: Andrew Gerrand <adg@golang.org>
Diffstat (limited to 'git-codereview/review.go')
| -rw-r--r-- | git-codereview/review.go | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/git-codereview/review.go b/git-codereview/review.go index 0b0ee8e..a2a60fb 100644 --- a/git-codereview/review.go +++ b/git-codereview/review.go @@ -195,9 +195,21 @@ func runDirErr(dir, command string, args ...string) error { // getOutput runs the specified command and returns its combined standard // output and standard error outputs. +// It dies on command errors. // NOTE: It should only be used to run commands that return information, // **not** commands that make any actual changes. func getOutput(command string, args ...string) string { + s, err := getOutputErr(command, args...) + if err != nil { + fmt.Fprintf(os.Stderr, "%v\n%s\n", commandString(command, args), s) + dief("%v", err) + } + return s +} + +// Given a command and its arguments, getOutputErr returns the same +// trimmed output as getOutput, but it returns any error instead of exiting. +func getOutputErr(command string, args ...string) (string, error) { // NOTE: We only show these non-state-modifying commands with -v -v. // Otherwise things like 'git sync -v' show all our internal "find out about // the git repo" commands, which is confusing if you are just trying to find @@ -206,11 +218,7 @@ func getOutput(command string, args ...string) string { fmt.Fprintln(os.Stderr, commandString(command, args)) } b, err := exec.Command(command, args...).CombinedOutput() - if err != nil { - fmt.Fprintf(os.Stderr, "%v\n%s\n", commandString(command, args), b) - dief("%v", err) - } - return string(bytes.TrimSpace(b)) + return string(bytes.TrimSpace(b)), err } // getLines is like getOutput but it returns only non-empty output lines, |
