From 8c1fa9c3b8ad0c79f9cefba3bdd8afde5d569f38 Mon Sep 17 00:00:00 2001 From: Filippo Valsorda Date: Mon, 8 Feb 2021 00:10:48 +0100 Subject: git-codereview: fix sync-branch to work in worktrees Change-Id: I8a3bcad53eae3273dc498ba94d53fe2d50b58520 Reviewed-on: https://go-review.googlesource.com/c/review/+/290212 Trust: Filippo Valsorda Run-TryBot: Filippo Valsorda Auto-Submit: Filippo Valsorda TryBot-Result: Gopher Robot Reviewed-by: Russ Cox --- git-codereview/sync.go | 3 +-- git-codereview/sync_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/git-codereview/sync.go b/git-codereview/sync.go index f8233f1..0555d67 100644 --- a/git-codereview/sync.go +++ b/git-codereview/sync.go @@ -10,7 +10,6 @@ import ( "fmt" "io/ioutil" "os" - "path/filepath" "strings" ) @@ -104,7 +103,7 @@ type syncBranchStatus struct { } func syncBranchStatusFile() string { - return filepath.Join(repoRoot(), ".git/codereview-sync-branch-status") + return gitPath("codereview-sync-branch-status") } func readSyncBranchStatus() *syncBranchStatus { diff --git a/git-codereview/sync_test.go b/git-codereview/sync_test.go index 884168c..1dbd7bf 100644 --- a/git-codereview/sync_test.go +++ b/git-codereview/sync_test.go @@ -7,6 +7,7 @@ package main import ( "bytes" "io/ioutil" + "os" "path/filepath" "strings" "testing" @@ -238,6 +239,29 @@ func TestSyncBranch(t *testing.T) { "Run 'git codereview mail' to send for review.") } +func TestSyncBranchWorktree(t *testing.T) { + gt := newGitTest(t) + defer gt.done() + + gt.serverWork(t) + gt.serverWork(t) + trun(t, gt.server, "git", "checkout", "dev.branch") + gt.serverWorkUnrelated(t, "") + gt.serverWorkUnrelated(t, "") + gt.serverWorkUnrelated(t, "") + trun(t, gt.server, "git", "checkout", "main") + + wt := filepath.Join(gt.tmpdir, "git-worktree") + trun(t, gt.client, "git", "worktree", "add", "-b", "dev.branch", wt, "origin/dev.branch") + if err := os.Chdir(wt); err != nil { + t.Fatal(err) + } + + testMain(t, "sync-branch") + testHideRevHashes(t) + testPrintedStdout(t, "[dev.branch] all: merge main (REVHASH) into dev.branch") +} + func TestSyncBranchMergeBack(t *testing.T) { gt := newGitTest(t) defer gt.done() -- cgit v1.3