review: Fix error of git change on windows
git change doesn't pass @{u} correctly on windows.
The runtime of msys2/cygwin runtime treat @{u] as @u on cmd.exe.
This is a workaround for avoiding mis-converting.
Fixes golang/go#15036
Change-Id: Ia0389108af69a8b8987ccba1ed933d0767f8efa7
Reviewed-on: https://go-review.googlesource.com/21018
Reviewed-by: Russ Cox <rsc@golang.org>
diff --git a/git-codereview/branch.go b/git-codereview/branch.go
index c96bce0..5d47dc9 100644
--- a/git-codereview/branch.go
+++ b/git-codereview/branch.go
@@ -7,8 +7,10 @@
import (
"bytes"
"fmt"
+ "os"
"os/exec"
"regexp"
+ "runtime"
"strings"
)
@@ -67,7 +69,17 @@
return b.originBranch
}
argv := []string{"git", "rev-parse", "--abbrev-ref", b.Name + "@{u}"}
- out, err := exec.Command(argv[0], argv[1:]...).CombinedOutput()
+ cmd := exec.Command(argv[0], argv[1:]...)
+ if runtime.GOOS == "windows" {
+ // Workaround on windows. git for windows can't handle @{u} as same as
+ // given. Disable glob for this command if running on Cygwin or MSYS2.
+ envs := os.Environ()
+ envs = append(envs, "CYGWIN=noglob "+os.Getenv("CYGWIN"))
+ envs = append(envs, "MSYS=noglob "+os.Getenv("MSYS"))
+ cmd.Env = envs
+ }
+
+ out, err := cmd.CombinedOutput()
if err == nil && len(out) > 0 {
b.originBranch = string(bytes.TrimSpace(out))
return b.originBranch