From 976f4e448560d5ceae5bfe495b184a0af961a0f4 Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Thu, 9 Aug 2012 08:39:53 -0700 Subject: [PATCH] Don't rebase if the rebase doesn't conflict Change-Id: I549b6c8bf4355d4bb968d9006f71afa7803c7d8f --- git-review | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/git-review b/git-review index 0c471896..8628ee03 100755 --- a/git-review +++ b/git-review @@ -372,6 +372,16 @@ def rebase_changes(branch, remote): return True +def undo_rebase(): + cmd = "git reset --hard ORIG_HEAD" + (status, output) = run_command_status(cmd) + if status != 0: + print("Errors running %s" % cmd) + print(output) + return False + return True + + def get_branch_name(target_branch): global _branch_name if _branch_name is not None: @@ -650,6 +660,9 @@ def main(): parser.add_argument("-R", "--no-rebase", dest="rebase", action="store_false", help="Don't rebase changes before submitting.") + parser.add_argument("-F", "--force-rebase", dest="force_rebase", + action="store_true", + help="Force rebase even when not needed.") parser.add_argument("-d", "--download", dest="download", help="Download the contents of an existing gerrit " "review into a branch") @@ -727,6 +740,8 @@ def main(): if options.rebase: if not rebase_changes(branch, remote): print_exit_message(1, needs_update) + if not options.force_rebase and not undo_rebase(): + print_exit_message(1, needs_update) assert_one_change(remote, branch, yes, have_hook) ref = "publish"