From 5e57234ec619d0de930333a8dde3004d1dc575d6 Mon Sep 17 00:00:00 2001 From: Joe Hansche Date: Mon, 5 Mar 2012 11:41:19 -0500 Subject: [PATCH] Support automatically stashing local modifications during repo-rebase. Currently repo-rebase requires that all modifications be committed locally before it will allow the rebase. In high-velocity environments, you may want to just pull in newer code without explicitly creating local commits, which is typically achieved using git-stash. If called with the --auto-stash command line argument, and it is determined that the current index is dirty, the local modifications are stashed, and the rebase continues. If a stash was performed, that stash is popped once the rebase completes. Note that there is still a possibility that the git-stash pop will result in a merge conflict. Change-Id: Ibe3da96f0b4486cb7ce8d040639187e26501f6af --- subcmds/rebase.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/subcmds/rebase.py b/subcmds/rebase.py index 7c8e9389..20662b11 100644 --- a/subcmds/rebase.py +++ b/subcmds/rebase.py @@ -52,6 +52,9 @@ branch but need to incorporate new upstream changes "underneath" them. p.add_option('--whitespace', dest='whitespace', action='store', metavar='WS', help='Pass --whitespace to git rebase') + p.add_option('--auto-stash', + dest='auto_stash', action='store_true', + help='Stash local modifications before starting') def Execute(self, opt, args): all = self.GetProjects(args) @@ -103,5 +106,23 @@ branch but need to incorporate new upstream changes "underneath" them. print >>sys.stderr, '# %s: rebasing %s -> %s' % \ (project.relpath, cb, upbranch.LocalMerge) + needs_stash = False + if opt.auto_stash: + stash_args = ["update-index", "--refresh", "-q"] + + if GitCommand(project, stash_args).Wait() != 0: + needs_stash = True + # Dirty index, requires stash... + stash_args = ["stash"] + + if GitCommand(project, stash_args).Wait() != 0: + return -1 + if GitCommand(project, args).Wait() != 0: return -1 + + if needs_stash: + stash_args.append('pop') + stash_args.append('--quiet') + if GitCommand(project, stash_args).Wait() != 0: + return -1