diff options
Diffstat (limited to 'git-codereview/sync.go')
| -rw-r--r-- | git-codereview/sync.go | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/git-codereview/sync.go b/git-codereview/sync.go index 71fc312..6ff36a3 100644 --- a/git-codereview/sync.go +++ b/git-codereview/sync.go @@ -60,10 +60,11 @@ func cmdSync(args []string) { // hint: use --reapply-cherry-picks to include skipped commits // hint: Disable this message with "git config advice.skippedCherryPicks false" // + cfgRemote := config()["remote"] if *verbose > 1 { - run("git", "-c", "advice.skippedCherryPicks=false", "pull", "-q", "-r", "-v", "origin", strings.TrimPrefix(b.OriginBranch(), "origin/")) + run("git", "-c", "advice.skippedCherryPicks=false", "pull", "-q", "-r", "-v", cfgRemote, strings.TrimPrefix(b.OriginBranch(), cfgRemote+"/")) } else { - run("git", "-c", "advice.skippedCherryPicks=false", "pull", "-q", "-r", "origin", strings.TrimPrefix(b.OriginBranch(), "origin/")) + run("git", "-c", "advice.skippedCherryPicks=false", "pull", "-q", "-r", cfgRemote, strings.TrimPrefix(b.OriginBranch(), cfgRemote+"/")) } b = CurrentBranch() // discard any cached information @@ -188,30 +189,32 @@ func cmdSyncBranch(args []string) { // Note that this does a remote fetch of b.OriginBranch() (aka branch). cmdSync(nil) + cfgRemote := config()["remote"] + // Pull down parent commits too. quiet := "-q" if *verbose > 0 { quiet = "-v" } - run("git", "fetch", quiet, "origin", "refs/heads/"+parent+":refs/remotes/origin/"+parent) + run("git", "fetch", quiet, cfgRemote, "refs/heads/"+parent+":refs/remotes/"+cfgRemote+"/"+parent) // Write the status file to make sure we can, before starting a merge. status := &syncBranchStatus{ Local: b.Name, Parent: parent, - ParentHash: gitHash("origin/" + parent), + ParentHash: gitHash(cfgRemote + "/" + parent), Branch: branch, - BranchHash: gitHash("origin/" + branch), + BranchHash: gitHash(cfgRemote + "/" + branch), } writeSyncBranchStatus(status) - parentHash, err := cmdOutputErr("git", "rev-parse", "origin/"+parent) + parentHash, err := cmdOutputErr("git", "rev-parse", cfgRemote+"/"+parent) if err != nil { - dief("cannot sync-branch: cannot resolve origin/%s: %v\n%s", parent, err, parentHash) + dief("cannot sync-branch: cannot resolve %s/%s: %v\n%s", cfgRemote, parent, err, parentHash) } - branchHash, err := cmdOutputErr("git", "rev-parse", "origin/"+branch) + branchHash, err := cmdOutputErr("git", "rev-parse", cfgRemote+"/"+branch) if err != nil { - dief("cannot sync-branch: cannot resolve origin/%s: %v\n%s", branch, err, branchHash) + dief("cannot sync-branch: cannot resolve %s/%s: %v\n%s", cfgRemote, branch, err, branchHash) } parentHash = trim(parentHash) branchHash = trim(branchHash) @@ -221,7 +224,7 @@ func cmdSyncBranch(args []string) { // to be done, it should be done first on the dev branch, // not the parent branch. if mergeBackToParent { - other := cmdOutput("git", "log", "--format=format:+ %cd %h %s", "--date=short", "origin/"+branch+"..origin/"+parent) + other := cmdOutput("git", "log", "--format=format:+ %cd %h %s", "--date=short", cfgRemote+"/"+branch+".."+cfgRemote+"/"+parent) if other != "" { dief("cannot sync-branch --merge-back-to-parent: parent has new commits.\n"+ "\trun 'git codereview sync-branch' to bring them into this branch first:\n%s", @@ -237,10 +240,10 @@ func cmdSyncBranch(args []string) { // of the merge, the same as it would when we are doing it by hand // with a plain "git merge". This may help the display of the // merge graph in some tools more closely reflect what we did. - run("git", "reset", "--hard", "origin/"+parent) - _, err = cmdOutputErr("git", "merge", "--no-ff", "origin/"+branch) + run("git", "reset", "--hard", cfgRemote+"/"+parent) + _, err = cmdOutputErr("git", "merge", "--no-ff", cfgRemote+"/"+branch) } else { - _, err = cmdOutputErr("git", "merge", "--no-ff", "origin/"+parent) + _, err = cmdOutputErr("git", "merge", "--no-ff", cfgRemote+"/"+parent) } // Resolve codereview.cfg the right way - never take it from the merge. @@ -322,10 +325,11 @@ const ( ) func syncBranchContinue(flag string, b *Branch, status *syncBranchStatus) { - if h := gitHash("origin/" + status.Parent); h != status.ParentHash { + cfgRemote := config()["remote"] + if h := gitHash(cfgRemote + "/" + status.Parent); h != status.ParentHash { dief("cannot sync-branch%s: parent hash changed: %.7s -> %.7s", flag, status.ParentHash, h) } - if h := gitHash("origin/" + status.Branch); h != status.BranchHash { + if h := gitHash(cfgRemote + "/" + status.Branch); h != status.BranchHash { dief("cannot sync-branch%s: branch hash changed: %.7s -> %.7s", flag, status.BranchHash, h) } if b.Name != status.Local { @@ -364,11 +368,11 @@ func syncBranchContinue(flag string, b *Branch, status *syncBranchStatus) { } mergeHead = trim(mergeHead) if mergeHead != srcHash { - dief("cannot sync-branch%s: MERGE_HEAD is %.7s, but origin/%s is %.7s", flag, mergeHead, src, srcHash) + dief("cannot sync-branch%s: MERGE_HEAD is %.7s, but %s/%s is %.7s", flag, mergeHead, cfgRemote, src, srcHash) } head := gitHash("HEAD") if head != dstHash { - dief("cannot sync-branch%s: HEAD is %.7s, but origin/%s is %.7s", flag, head, dst, dstHash) + dief("cannot sync-branch%s: HEAD is %.7s, but %s/%s is %.7s", flag, head, cfgRemote, dst, dstHash) } if HasUnstagedChanges() { @@ -387,7 +391,7 @@ func syncBranchContinue(flag string, b *Branch, status *syncBranchStatus) { // Merge must never sync codereview.cfg, // because it contains the src and dst config. // Force the on-dst copy back while amending the commit. - cmdOutputDir(repoRoot(), "git", "checkout", "origin/"+dst, "--", "codereview.cfg") + cmdOutputDir(repoRoot(), "git", "checkout", cfgRemote+"/"+dst, "--", "codereview.cfg") conflictMsg := "" if len(status.Conflicts) > 0 { |
