From f701a38287ffe1c81b67f15f16f87ed32007cee1 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Wed, 23 Jan 2013 12:05:11 -0500 Subject: [PATCH] review: Automatically push personal local branches to the remote. (imported from commit 29cf7d7316eb3666e2f8b39aacf3baa86990bace) --- tools/review | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/tools/review b/tools/review index 2af8f357fb..58c86d7183 100755 --- a/tools/review +++ b/tools/review @@ -153,8 +153,27 @@ def make_header(repo, opts, revs): name = name[len(prefix):] tip_name = '%s (%s)' % (name, revs[-1].hexsha[:7]) else: - print >>sys.stderr, "WARNING: Can't find this commit in remote -- did you push?" - tip_name = revs[-1].hexsha[:7] + (_, local_name) = repo.git.name_rev(revs[-1].hexsha, + refs='refs/heads/*', + always=True).split() + if local_name == "undefined": + print >>sys.stderr, "ERROR: Can't find this commit in remote or identify local branch!" + sys.exit(1) + + email_basename = get_current_user_email(repo).split("@")[0] + if local_name.startswith("%s-" % (email_basename,)): + # Try to push the local branch to the remote automatically + try: + print "Attempting to push %s to remote %s" % (local_name, remote) + repo.git.push(remote, local_name) + tip_name = '%s (%s)' % (local_name, revs[-1].hexsha[:7]) + except git.GitCommandError, e: + print >>sys.stderr, "ERROR: Couldn't push %s to remote" % (local_name,) + print >>sys.stderr, e + sys.exit(1) + else: + print >>sys.stderr, "ERROR: Can't find this commit in remote -- did you push %s?" % (local_name) + sys.exit(1) objective_summary = '%d commit(s) to %s' % (len(revs), tip_name) summary = ('%s (%s)' % (opts.summary, objective_summary) if opts.summary