review: Automatically push personal local branches to the remote.

(imported from commit 29cf7d7316eb3666e2f8b39aacf3baa86990bace)
This commit is contained in:
Tim Abbott 2013-01-23 12:05:11 -05:00
parent 7a7fc54234
commit f701a38287
1 changed files with 21 additions and 2 deletions

View File

@ -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