diff options
| author | Russ Cox <rsc@golang.org> | 2020-09-11 10:20:23 -0400 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2020-09-11 20:38:38 +0000 |
| commit | 3c482744cb56e16a5547cb048a12845d62497497 (patch) | |
| tree | 3420fb5984ba925a5a91f6f615ab01a23ecfb570 | |
| parent | a2b90d2f6e29477343826a7b79798b588394f4aa (diff) | |
| download | go-x-review-3c482744cb56e16a5547cb048a12845d62497497.tar.xz | |
git-codereview: change upstream fallback to try main before master
Will help when we start using origin/main in Go repos.
(Tested using git-codereview against github.com/google/licensecheck.)
Change-Id: I564a0f6863938a3196dea3df9e8af240faba91fc
Reviewed-on: https://go-review.googlesource.com/c/review/+/254420
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
| -rw-r--r-- | git-codereview/branch.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/git-codereview/branch.go b/git-codereview/branch.go index a332256..2bd9fe9 100644 --- a/git-codereview/branch.go +++ b/git-codereview/branch.go @@ -89,6 +89,18 @@ func (b *Branch) OriginBranch() string { // Have seen both "No upstream configured" and "no upstream configured". if strings.Contains(string(out), "upstream configured") { // Assume branch was created before we set upstream correctly. + // See if origin/main exists; if so, use it. + // Otherwise, fall back to origin/master. + argv := []string{"git", "rev-parse", "--abbrev-ref", "origin/main"} + cmd := exec.Command(argv[0], argv[1:]...) + setEnglishLocale(cmd) + if out, err := cmd.CombinedOutput(); err == nil { + b.originBranch = string(bytes.TrimSpace(out)) + // Best effort attempt to correct setting for next time, + // and for "git status". + exec.Command("git", "branch", "-u", "origin/main").Run() + return b.originBranch + } b.originBranch = "origin/master" return b.originBranch } |
