aboutsummaryrefslogtreecommitdiff
path: root/git-codereview/mail.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2014-12-23 14:12:53 -0500
committerRuss Cox <rsc@golang.org>2015-01-06 15:08:43 +0000
commitc3e5818734a979dd8168d10f722bfcdafe875ebb (patch)
tree55156b5d9c670baa00f2cde6d18210ce9cf4e314 /git-codereview/mail.go
parentc5341d68ee62a899be9c2b7cce20f575f3526289 (diff)
downloadgo-x-review-c3e5818734a979dd8168d10f722bfcdafe875ebb.tar.xz
git-codereview: begin to handle multiple-change branches
Gerrit supports multiple-change branches, and we'd like to make git-codereview useful for people using this mode of work. This CL is the first step. - remove error message on detecting a multiple-change branch - require 'git submit hash' in multiple-change branch - make git submit, git sync cleanup safe for multiple-change branch - adjust git pending output to show full information about multiple-change branch - add pending -c to show only current branch, since output is getting long We're not advertising or supporting this mode yet. For now the only way to enter it is to run 'git commit' to create the second commit. Perhaps eventually we will support something like 'git change -new'. Change-Id: I8284a7c230503061d3e6d7cce0be7d8d05c9b2a3 Reviewed-on: https://go-review.googlesource.com/2110 Reviewed-by: Andrew Gerrand <adg@golang.org> Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'git-codereview/mail.go')
-rw-r--r--git-codereview/mail.go27
1 files changed, 18 insertions, 9 deletions
diff --git a/git-codereview/mail.go b/git-codereview/mail.go
index c6eee7e..c5ec7ce 100644
--- a/git-codereview/mail.go
+++ b/git-codereview/mail.go
@@ -23,21 +23,25 @@ func mail(args []string) {
flags.Var(ccList, "cc", "comma-separated list of people to CC:")
flags.Usage = func() {
- fmt.Fprintf(stderr(), "Usage: %s mail %s [-r reviewer,...] [-cc mail,...]\n", os.Args[0], globalFlags)
+ fmt.Fprintf(stderr(), "Usage: %s mail %s [-r reviewer,...] [-cc mail,...] [commit-hash]\n", os.Args[0], globalFlags)
}
flags.Parse(args)
- if len(flags.Args()) != 0 {
+ if len(flags.Args()) > 1 {
flags.Usage()
os.Exit(2)
}
b := CurrentBranch()
- if b.ChangeID() == "" {
- dief("no pending change; can't mail.")
+
+ var c *Commit
+ if len(flags.Args()) == 1 {
+ c = b.CommitByHash("mail", flags.Arg(0))
+ } else {
+ c = b.DefaultCommit("mail")
}
if *diff {
- run("git", "diff", b.Branchpoint()+"..HEAD", "--")
+ run("git", "diff", b.Branchpoint()[:7]+".."+c.ShortHash, "--")
return
}
@@ -49,7 +53,7 @@ func mail(args []string) {
// for side effect of dying with a good message if origin is GitHub
loadGerritOrigin()
- refSpec := b.PushSpec()
+ refSpec := b.PushSpec(c)
start := "%"
if *rList != "" {
refSpec += mailList(start, "r", string(*rList))
@@ -74,9 +78,14 @@ func mail(args []string) {
run("git", "tag", "-f", b.Name+".mailed")
}
-// PushSpec returns the spec for a Gerrit push command to publish the change in b.
-func (b *Branch) PushSpec() string {
- return "HEAD:refs/for/" + strings.TrimPrefix(b.OriginBranch(), "origin/")
+// PushSpec returns the spec for a Gerrit push command to publish the change c in b.
+// If c is nil, PushSpec returns a spec for pushing all changes in b.
+func (b *Branch) PushSpec(c *Commit) string {
+ local := "HEAD"
+ if c != nil && (len(b.Pending()) == 0 || b.Pending()[0].Hash != c.Hash) {
+ local = c.ShortHash
+ }
+ return local + ":refs/for/" + strings.TrimPrefix(b.OriginBranch(), "origin/")
}
// mailAddressRE matches the mail addresses we admit. It's restrictive but admits