Commit dabb78bf authored by iannucci@chromium.org's avatar iannucci@chromium.org

Make git-rebase-update a bit more robust

  * When aborting a failed rebase, don't cascade errors if the abort itself
    fails.
  * When starting a rebase-update cycle, cd to the root of the repo. This avoids
    an issue when you run rebase-update from inside of a branch which adds a
    new folder.

R=agable@chromium.org
BUG=499031

Review URL: https://codereview.chromium.org/1180673003

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@295637 0039d316-1c4b-4281-b951-d872f2087c98
parent 8ba38ff4
...@@ -525,7 +525,7 @@ def rebase(parent, start, branch, abort=False): ...@@ -525,7 +525,7 @@ def rebase(parent, start, branch, abort=False):
return RebaseRet(True, '', '') return RebaseRet(True, '', '')
except subprocess2.CalledProcessError as cpe: except subprocess2.CalledProcessError as cpe:
if abort: if abort:
run('rebase', '--abort') run_with_retcode('rebase', '--abort') # ignore failure
return RebaseRet(False, cpe.stdout, cpe.stderr) return RebaseRet(False, cpe.stdout, cpe.stderr)
......
...@@ -12,6 +12,7 @@ import collections ...@@ -12,6 +12,7 @@ import collections
import logging import logging
import sys import sys
import textwrap import textwrap
import os
from fnmatch import fnmatch from fnmatch import fnmatch
from pprint import pformat from pprint import pformat
...@@ -20,21 +21,26 @@ import git_common as git ...@@ -20,21 +21,26 @@ import git_common as git
STARTING_BRANCH_KEY = 'depot-tools.rebase-update.starting-branch' STARTING_BRANCH_KEY = 'depot-tools.rebase-update.starting-branch'
STARTING_WORKDIR_KEY = 'depot-tools.rebase-update.starting-workdir'
def find_return_branch(): def find_return_branch_workdir():
"""Finds the branch which we should return to after rebase-update completes. """Finds the branch and working directory which we should return to after
rebase-update completes.
This value may persist across multiple invocations of rebase-update, if These values may persist across multiple invocations of rebase-update, if
rebase-update runs into a conflict mid-way. rebase-update runs into a conflict mid-way.
""" """
return_branch = git.config(STARTING_BRANCH_KEY) return_branch = git.config(STARTING_BRANCH_KEY)
workdir = git.config(STARTING_WORKDIR_KEY)
if not return_branch: if not return_branch:
workdir = os.getcwd()
git.set_config(STARTING_WORKDIR_KEY, workdir)
return_branch = git.current_branch() return_branch = git.current_branch()
if return_branch != 'HEAD': if return_branch != 'HEAD':
git.set_config(STARTING_BRANCH_KEY, return_branch) git.set_config(STARTING_BRANCH_KEY, return_branch)
return return_branch return return_branch, workdir
def fetch_remotes(branch_tree): def fetch_remotes(branch_tree):
...@@ -214,7 +220,8 @@ def main(args=None): ...@@ -214,7 +220,8 @@ def main(args=None):
) )
return 1 return 1
return_branch = find_return_branch() return_branch, return_workdir = find_return_branch_workdir()
os.chdir(git.run('rev-parse', '--show-toplevel'))
if git.current_branch() == 'HEAD': if git.current_branch() == 'HEAD':
if git.run('status', '--porcelain'): if git.run('status', '--porcelain'):
...@@ -264,7 +271,9 @@ def main(args=None): ...@@ -264,7 +271,9 @@ def main(args=None):
% (return_branch, root_branch) % (return_branch, root_branch)
) )
git.run('checkout', root_branch) git.run('checkout', root_branch)
os.chdir(return_workdir)
git.set_config(STARTING_BRANCH_KEY, '') git.set_config(STARTING_BRANCH_KEY, '')
git.set_config(STARTING_WORKDIR_KEY, '')
return retcode return retcode
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment