git-codereview: fix active rebase detection

A sync + merge conflict + git rebase --continue can leave behind
a REBASE_HEAD even though it really should not. So don't use that
as the signal that there's an active rebase.

The rebase-merge directory is a better signal and seems to be
cleaned up more diligently than REBASE_HEAD.

Change-Id: Ie5bc20156e19fc7ce3e32333babea784242dc770
Reviewed-on: https://go-review.googlesource.com/c/review/+/293838
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Katie Hockman <katie@golang.org>
diff --git a/git-codereview/change.go b/git-codereview/change.go
index 24cbb71..045fe9c 100644
--- a/git-codereview/change.go
+++ b/git-codereview/change.go
@@ -6,6 +6,8 @@
 
 import (
 	"fmt"
+	"os"
+	"path/filepath"
 	"regexp"
 	"strconv"
 	"strings"
@@ -29,7 +31,9 @@
 	if _, err := cmdOutputErr("git", "rev-parse", "--abbrev-ref", "MERGE_HEAD"); err == nil {
 		diePendingMerge("change")
 	}
-	if _, err := cmdOutputErr("git", "rev-parse", "--abbrev-ref", "REBASE_HEAD"); err == nil {
+	// Note: A rebase with a conflict + rebase --continue sometimes leaves behind REBASE_HEAD.
+	// So check for the rebase-merge directory instead, which it does a better job cleaning up.
+	if _, err := os.Stat(filepath.Join(gitPathDir(), "rebase-merge")); err == nil {
 		dief("cannot change: found pending rebase or sync")
 	}