aboutsummaryrefslogtreecommitdiff
path: root/git-codereview/gofmt.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2021-01-08 11:05:45 -0500
committerRuss Cox <rsc@golang.org>2021-01-13 14:40:11 +0000
commitb916a6f42a60763185b530b8bd15d6aa0099e5da (patch)
tree5a15f56c8e482c8a781ffc2155b5c72a1111d72b /git-codereview/gofmt.go
parentfdc5e6a4e6b93c6381d20cf1dfbfaa49f420a43d (diff)
downloadgo-x-review-b916a6f42a60763185b530b8bd15d6aa0099e5da.tar.xz
git-codereview: clean up detached HEAD mode
Long ago I decided to return origin/HEAD from b.OriginBranch in detached HEAD mode, thinking it would cause obvious failures. But the joke was on me - origin/HEAD is a real thing in git, and HEAD tracking origin/HEAD is not the right answer on dev branches. Now that each branch's codereview.cfg typically has the branch info we need, we can use that in detached HEAD mode to be able to provide useful displays in commands like "git pending". And we can be careful not to do that when we don't know the actual branch. This commit cleans all that up. Change-Id: I0e59bcb6f9b61e0cdce7a27299b7f29fef8e7048 Reviewed-on: https://go-review.googlesource.com/c/review/+/282616 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'git-codereview/gofmt.go')
-rw-r--r--git-codereview/gofmt.go16
1 files changed, 9 insertions, 7 deletions
diff --git a/git-codereview/gofmt.go b/git-codereview/gofmt.go
index 7986d07..ca5f798 100644
--- a/git-codereview/gofmt.go
+++ b/git-codereview/gofmt.go
@@ -120,13 +120,15 @@ func runGofmt(flags int) (files []string, stderrText string) {
}
// Find files modified in the index compared to the branchpoint.
- branchpt := b.Branchpoint()
- if strings.Contains(cmdOutput("git", "branch", "-r", "--contains", b.FullName()), "origin/") {
- // This is a branch tag move, not an actual change.
- // Use HEAD as branch point, so nothing will appear changed.
- // We don't want to think about gofmt on already published
- // commits.
- branchpt = "HEAD"
+ // The default of HEAD will only compare against the most recent commit.
+ // But if we know the origin branch, and this isn't a branch tag move,
+ // then check all the pending commits.
+ branchpt := "HEAD"
+ if b.OriginBranch() != "" {
+ isBranchTagMove := strings.Contains(cmdOutput("git", "branch", "-r", "--contains", b.FullName()), "origin/")
+ if !isBranchTagMove {
+ branchpt = b.Branchpoint()
+ }
}
indexFiles := addRoot(repo, filter(gofmtRequired, nonBlankLines(cmdOutput("git", "diff", "--name-only", "--diff-filter=ACM", "--cached", branchpt, "--"))))
localFiles := addRoot(repo, filter(gofmtRequired, nonBlankLines(cmdOutput("git", "diff", "--name-only", "--diff-filter=ACM"))))