aboutsummaryrefslogtreecommitdiff
path: root/git-codereview/branch.go
diff options
context:
space:
mode:
authorYasuhiro Matsumoto <mattn.jp@gmail.com>2015-08-12 20:57:13 +0900
committerAndrew Gerrand <adg@golang.org>2015-08-20 09:18:54 +0000
commit0d7922879a3c8f00706afeff7e19df53620dfc64 (patch)
treee1eeaf4209cb4617eeefc621354b3840c4b20b12 /git-codereview/branch.go
parent263602e3bdefbb5ad721bca837f8bd191a4e2281 (diff)
downloadgo-x-review-0d7922879a3c8f00706afeff7e19df53620dfc64.tar.xz
review: git change doesn't pass @{u} correctly on windows.
Fixes golang/go#9377 Quote the branch name. Change-Id: Ib35a5dcf7198b94331d894f3bcd825af64b1582d Reviewed-on: https://go-review.googlesource.com/13600 Reviewed-by: Andrew Gerrand <adg@golang.org>
Diffstat (limited to 'git-codereview/branch.go')
-rw-r--r--git-codereview/branch.go14
1 files changed, 13 insertions, 1 deletions
diff --git a/git-codereview/branch.go b/git-codereview/branch.go
index 5eacb10..01af0c9 100644
--- a/git-codereview/branch.go
+++ b/git-codereview/branch.go
@@ -9,6 +9,7 @@ import (
"fmt"
"os/exec"
"regexp"
+ "runtime"
"strings"
)
@@ -51,6 +52,16 @@ func (b *Branch) DetachedHead() bool {
return b.Name == "HEAD"
}
+// Workaround on windows. git for windows can't handle @{u} as same as given.
+// It removes parens. And option '--' to skip parsing arguments doesn't work
+// correctly on git 2.5.0.
+func quoteOnWindows(branch string) string {
+ if runtime.GOOS != "windows" {
+ return branch
+ }
+ return "'" + branch + "'"
+}
+
// OriginBranch returns the name of the origin branch that branch b tracks.
// The returned name is like "origin/master" or "origin/dev.garbage" or
// "origin/release-branch.go1.4".
@@ -66,7 +77,8 @@ func (b *Branch) OriginBranch() string {
if b.originBranch != "" {
return b.originBranch
}
- argv := []string{"git", "rev-parse", "--abbrev-ref", b.Name + "@{u}"}
+ argv := []string{"git", "rev-parse", "--abbrev-ref", quoteOnWindows(b.Name + "@{u}")}
+
out, err := exec.Command(argv[0], argv[1:]...).CombinedOutput()
if err == nil && len(out) > 0 {
b.originBranch = string(bytes.TrimSpace(out))