Added the remote option and updated README.

This commit is contained in:
Monty Taylor 2011-09-29 11:05:04 -07:00
parent 6433d9f4e0
commit 2fec4bcf47
2 changed files with 34 additions and 17 deletions

View File

@ -19,6 +19,18 @@ If you want to submit that code to a different target branch, then:
If you want to submit to a different remote: If you want to submit to a different remote:
git -r my-remote review git review -r my-remote
If you want to supply a review topic:
git review -t topic/awesome-feature
If you want to submit your change to a branch other than master:
git review milestone-proposed
If you want to skip the automatic rebase -i step:
git review -R

View File

@ -158,18 +158,19 @@ def map_known_locations(hostname, team, project):
return hostname return hostname
def check_remote(): def check_remote(remote):
"""Check that a Gerrit Git remote repo exists, if not, set one.""" """Check that a Gerrit Git remote repo exists, if not, set one."""
if "gerrit" in commands.getoutput("git remote").split("\n"): if remote in commands.getoutput("git remote").split("\n"):
for remote in commands.getoutput("git branch -a").split("\n"): for current_remote in commands.getoutput("git branch -a").split("\n"):
if remote.strip() == "remotes/gerrit/master" and not UPDATE: if current_remote.strip() == "remotes/%s/master" % (remote) \
and not UPDATE:
return return
# We have the remote, but aren't set up to fetch. Fix it # We have the remote, but aren't set up to fetch. Fix it
if VERBOSE: if VERBOSE:
print "Setting up gerrit branch tracking for better rebasing" print "Setting up gerrit branch tracking for better rebasing"
commands.getoutput("git remote update gerrit") commands.getoutput("git remote update %s")
return return
fetch_url = "" fetch_url = ""
@ -205,9 +206,9 @@ def check_remote():
return hostname return hostname
def rebase_changes(branch): def rebase_changes(branch, remote):
cmd = "GIT_EDITOR=true git rebase -i gerrit/%s" % branch cmd = "GIT_EDITOR=true git rebase -i %s/%s" % (remote, branch)
(status, output) = commands.getstatusoutput(cmd) (status, output) = commands.getstatusoutput(cmd)
if status != 0: if status != 0:
print "Errors running %s" % cmd print "Errors running %s" % cmd
@ -216,12 +217,12 @@ def rebase_changes(branch):
return True return True
def assert_diverge(branch): def assert_diverge(branch, remote):
cmd = "git diff gerrit/%s..HEAD" % branch cmd = "git diff %s/%s..HEAD" % (remote, branch)
(status, output) = commands.getstatusoutput(cmd) (status, output) = commands.getstatusoutput(cmd)
if len(output) == 0: if len(output) == 0:
print "No changes between HEAD and gerrit/%s." % branch print "No changes between HEAD and %s/%s." % (remote, branch)
print "Submitting for review would be pointless." print "Submitting for review would be pointless."
sys.exit(1) sys.exit(1)
if status != 0: if status != 0:
@ -274,6 +275,8 @@ def main():
help="Topic to submit branch to") help="Topic to submit branch to")
parser.add_option("-n", "--dry-run", dest="dry", action="store_true", parser.add_option("-n", "--dry-run", dest="dry", action="store_true",
help="Don't actually submit the branch for review") help="Don't actually submit the branch for review")
parser.add_option("-r", "--remote", dest="remote",
help="git remote to use for gerrit")
parser.add_option("-R", "--no-rebase", dest="rebase", parser.add_option("-R", "--no-rebase", dest="rebase",
action="store_false", action="store_false",
help="Don't rebase changes before submitting.") help="Don't rebase changes before submitting.")
@ -281,7 +284,8 @@ def main():
help="Output more information about what's going on") help="Output more information about what's going on")
parser.add_option("-u", "--update", dest="update", action="store_true", parser.add_option("-u", "--update", dest="update", action="store_true",
help="Force updates from remote locations") help="Force updates from remote locations")
parser.set_defaults(dry=False, rebase=True, verbose=False, update=False) parser.set_defaults(dry=False, rebase=True, verbose=False, update=False,
remote="gerrit")
branch = "master" branch = "master"
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
@ -291,6 +295,7 @@ def main():
global UPDATE global UPDATE
VERBOSE = options.verbose VERBOSE = options.verbose
UPDATE = options.update UPDATE = options.update
remote = options.remote
topic = options.topic topic = options.topic
if topic is None: if topic is None:
@ -305,20 +310,20 @@ def main():
needs_update = latest_is_newer() needs_update = latest_is_newer()
hostname = check_remote() hostname = check_remote(remote)
set_hooks_commit_msg(hostname) set_hooks_commit_msg(hostname)
if UPDATE: if UPDATE:
cmd = "git fetch gerrit %s" % branch cmd = "git fetch %s %s" % (remote, branch)
(status, output) = commands.getstatusoutput(cmd) (status, output) = commands.getstatusoutput(cmd)
if options.rebase: if options.rebase:
if not rebase_changes(branch): if not rebase_changes(branch, remote):
print_exit_message(1, needs_update) print_exit_message(1, needs_update)
assert_diverge(branch) assert_diverge(branch, remote)
cmd = "%s git push gerrit HEAD:refs/for/%s/%s" % (drier, branch, topic) cmd = "%s git push %s HEAD:refs/for/%s/%s" % (remote, drier, branch, topic)
(status, output) = commands.getstatusoutput(cmd) (status, output) = commands.getstatusoutput(cmd)
print output print output
print_exit_message(status, needs_update) print_exit_message(status, needs_update)