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>
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 @@
 	"fmt"
 	"os/exec"
 	"regexp"
+	"runtime"
 	"strings"
 )
 
@@ -51,6 +52,16 @@
 	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 @@
 	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))