From 0d7922879a3c8f00706afeff7e19df53620dfc64 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Wed, 12 Aug 2015 20:57:13 +0900 Subject: 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 --- git-codereview/branch.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'git-codereview') 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)) -- cgit v1.3