| Index: checkout.py
|
| diff --git a/checkout.py b/checkout.py
|
| index c75b0f317e299b7f572e8dea514f366b21748a17..4226cda9fb6f7c03b761428fa3450e8b2b89c802 100644
|
| --- a/checkout.py
|
| +++ b/checkout.py
|
| @@ -82,7 +82,7 @@ class SvnMixIn(object):
|
| kwargs.setdefault('cwd', self.project_path)
|
| return subprocess2.check_call(self._add_svn_flags(args), **kwargs)
|
|
|
| - def _capture_svn(self, args, **kwargs):
|
| + def _check_capture_svn(self, args, **kwargs):
|
| """Runs svn and throws an exception if the command failed.
|
|
|
| Returns the output.
|
| @@ -163,7 +163,7 @@ class SvnCheckout(CheckoutBase, SvnMixIn):
|
| os.write(handle, commit_message)
|
| os.close(handle)
|
| try:
|
| - output = self._capture_svn(['commit', '--file', commit_filename])
|
| + output = self._check_capture_svn(['commit', '--file', commit_filename])
|
| revision = re.compile(
|
| r'.*?\nCommitted revision (\d+)',
|
| re.DOTALL).match(output).group(1)
|
| @@ -219,7 +219,7 @@ class SvnCheckout(CheckoutBase, SvnMixIn):
|
| # Revive files that were deleted above.
|
| self._check_call_svn(['update', '--force'] + flags)
|
|
|
| - out = self._capture_svn(['info', '.'])
|
| + out = self._check_capture_svn(['info', '.'])
|
| return int(self._parse_svn_info(out, 'revision'))
|
|
|
|
|
| @@ -236,9 +236,12 @@ class GitCheckoutBase(CheckoutBase):
|
| def prepare(self):
|
| """Resets the git repository in a clean state."""
|
| assert os.path.isdir(self.project_path)
|
| - self._check_call_git(['checkout', 'master', '--force'])
|
| - self._check_call_git(['pull', self.remote, self.remote_branch])
|
| - self._call_git(['branch', '-D', self.working_branch])
|
| + branches, active = self._branches()
|
| + if active != 'master':
|
| + self._check_call_git(['checkout', 'master', '--force', '--quiet'])
|
| + self._check_call_git(['pull', self.remote, self.remote_branch, '--quiet'])
|
| + if self.working_branch in branches:
|
| + self._call_git(['branch', '-D', self.working_branch])
|
|
|
| def apply_patch(self, patch_data):
|
| """Applies a patch on 'working_branch'."""
|
| @@ -267,6 +270,17 @@ class GitCheckoutBase(CheckoutBase):
|
| kwargs.setdefault('cwd', self.project_path)
|
| return subprocess2.check_capture(['git'] + args, **kwargs)
|
|
|
| + def _branches(self):
|
| + """Returns the list of branches and the active one."""
|
| + out = self._check_capture_git(['branch']).splitlines(False)
|
| + branches = [l[2:] for l in out]
|
| + active = None
|
| + for l in out:
|
| + if l.startswith('*'):
|
| + active = l[2:]
|
| + break
|
| + return branches, active
|
| +
|
|
|
| class GitSvnCheckoutBase(GitCheckoutBase, SvnMixIn):
|
| """Base class for git-svn checkout. Not to be used as-is."""
|
| @@ -288,9 +302,15 @@ class GitSvnCheckoutBase(GitCheckoutBase, SvnMixIn):
|
|
|
| def prepare(self):
|
| """Resets the git repository in a clean state."""
|
| - self._check_call_git(['checkout', 'master', '--force'])
|
| - self._check_call_git_svn(['rebase'])
|
| - self._call_git(['branch', '-D', self.working_branch])
|
| + branches, active = self._branches()
|
| + if active != 'master':
|
| + self._check_call_git(['checkout', 'master', '--force', '--quiet'])
|
| + # git svn rebase --quiet --quiet doesn't work, use two steps to silence it.
|
| + self._check_call_git_svn(['fetch'])
|
| + self._check_call_git(
|
| + ['rebase', '--quiet', '%s/%s' % (self.remote, self.remote_branch)])
|
| + if self.working_branch in branches:
|
| + self._call_git(['branch', '-D', self.working_branch])
|
| return int(self._git_svn_info('revision'))
|
|
|
| def _git_svn_info(self, key):
|
| @@ -316,8 +336,8 @@ class GitSvnCheckoutBase(GitCheckoutBase, SvnMixIn):
|
| for it."""
|
| if not self.commit_user:
|
| return
|
| - logging.info('Caching svn credentials for %s' % self.commit_user)
|
| - self._check_call_svn(['ls', self.svn_url], cwd=None)
|
| + # Use capture to lower noise in logs.
|
| + self._check_capture_svn(['ls', self.svn_url], cwd=None)
|
|
|
| def _check_call_git_svn(self, args, **kwargs):
|
| """Handles svn authentication while calling git svn."""
|
|
|