From efa34acc59ffcd88328048174592ba54a80b0acd Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Fri, 15 Mar 2019 15:34:45 +0100 Subject: [PATCH] gits: also rebase onto origin/master Change-Id: Icb331d225e8ec1b75d199e40c61c741a44c9a87c --- src/gits | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/gits b/src/gits index 99c899a..2dbb011 100755 --- a/src/gits +++ b/src/gits @@ -320,6 +320,30 @@ def rebase(git_dir): ask_reset_hard_or_push_f(git_dir, orig_branch, upstream_branch) + if git_has_modifications(git_dir): + raise SkipThisRepo() + + # Rebase onto origin/master? Only when this isn't already the master branch + if upstream_branch != 'origin/master': + ahead, behind = git_ahead_behind(git_dir, orig_branch, 'origin/master') + + if ahead and behind: + do_rebase = ask(git_dir, '%r diverged from master. git rebase -i origin/master?' % orig_branch, + " don't rebase", + 'ok rebase onto origin/master', + valid_answers=('', 'ok')) + + if do_rebase == 'ok': + git(git_dir, 'rebase', '-i', 'origin/master') + # On conflicts, we'll exit with error implicitly + + do_push = ask(git_dir, 'git push -f to overwrite %r?' % upstream_branch, + " don't overwrite upstream", + 'P `push -f` to overwrite upstream (P in caps!)', + valid_answers=('', 'P')) + if do_push == 'P': + git(git_dir, 'push', '-f') + return orig_branch