diff options
| author | Austin Clements <austin@google.com> | 2015-11-05 12:29:37 -0500 |
|---|---|---|
| committer | Austin Clements <austin@google.com> | 2015-11-11 00:37:47 +0000 |
| commit | 4a2b2fd69ccbe0e57e6bdecedacab520fd35b9c9 (patch) | |
| tree | 0f128f1201e521d22da10a0f88c7c61f10a5eff3 | |
| parent | 34635f909d7542a2a5de32ecf2b3a80a07f77a87 (diff) | |
| download | go-x-review-4a2b2fd69ccbe0e57e6bdecedacab520fd35b9c9.tar.xz | |
git-codereview: factor submitting a single change
This factors the logic for committing a single change in preparation
for supporting submitting multiple changes at once.
Change-Id: Ida083ada2c3a5393f99159e588dbc87af3902091
Reviewed-on: https://go-review.googlesource.com/16673
Reviewed-by: Andrew Gerrand <adg@golang.org>
| -rw-r--r-- | git-codereview/submit.go | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/git-codereview/submit.go b/git-codereview/submit.go index 8528641..df43148 100644 --- a/git-codereview/submit.go +++ b/git-codereview/submit.go @@ -37,6 +37,28 @@ func cmdSubmit(args []string) { checkStaged("submit") checkUnstaged("submit") + // Submit the change. + g := submit(b, c) + + // Sync client to revision that Gerrit committed, but only if we can do it cleanly. + // Otherwise require user to run 'git sync' themselves (if they care). + run("git", "fetch", "-q") + if len(b.Pending()) == 1 { + if err := runErr("git", "checkout", "-q", "-B", b.Name, g.CurrentRevision, "--"); err != nil { + dief("submit succeeded, but cannot sync local branch\n"+ + "\trun 'git sync' to sync, or\n"+ + "\trun 'git branch -D %s; git change master; git sync' to discard local branch", b.Name) + } + } else { + printf("submit succeeded; run 'git sync' to sync") + } + + // Done! Change is submitted, branch is up to date, ready for new work. +} + +// submit submits a single commit c on branch b and returns the +// GerritChange for the submitted change. It dies if the submit fails. +func submit(b *Branch, c *Commit) *GerritChange { // Fetch Gerrit information about this change. g, err := b.GerritChange(c, "LABELS", "CURRENT_REVISION") if err != nil { @@ -139,18 +161,5 @@ func cmdSubmit(args []string) { dief("cannot submit: timed out waiting for change to be submitted by Gerrit") } - // Sync client to revision that Gerrit committed, but only if we can do it cleanly. - // Otherwise require user to run 'git sync' themselves (if they care). - run("git", "fetch", "-q") - if len(b.Pending()) == 1 { - if err := runErr("git", "checkout", "-q", "-B", b.Name, g.CurrentRevision, "--"); err != nil { - dief("submit succeeded, but cannot sync local branch\n"+ - "\trun 'git sync' to sync, or\n"+ - "\trun 'git branch -D %s; git change master; git sync' to discard local branch", b.Name) - } - } else { - printf("submit succeeded; run 'git sync' to sync") - } - - // Done! Change is submitted, branch is up to date, ready for new work. + return g } |
