Commit e409df67 authored by mmoss@chromium.org's avatar mmoss@chromium.org

Make sure branch-heads is configured whenever requested.

This allows the branch-heads to be pulled even if not configured on the
original clone.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@194382 0039d316-1c4b-4281-b951-d872f2087c98
parent e72c5f51
...@@ -316,6 +316,7 @@ class GitWrapper(SCMWrapper): ...@@ -316,6 +316,7 @@ class GitWrapper(SCMWrapper):
quiet = [] quiet = []
if not options.verbose: if not options.verbose:
quiet = ['--quiet'] quiet = ['--quiet']
self._UpdateBranchHeads(options, fetch=False)
self._Run(['fetch', 'origin', '--prune'] + quiet, options) self._Run(['fetch', 'origin', '--prune'] + quiet, options)
self._Run(['reset', '--hard', revision] + quiet, options) self._Run(['reset', '--hard', revision] + quiet, options)
self.UpdateSubmoduleConfig() self.UpdateSubmoduleConfig()
...@@ -384,6 +385,8 @@ class GitWrapper(SCMWrapper): ...@@ -384,6 +385,8 @@ class GitWrapper(SCMWrapper):
if verbose: if verbose:
print(remote_output.strip()) print(remote_output.strip())
self._UpdateBranchHeads(options, fetch=True)
# This is a big hammer, debatable if it should even be here... # This is a big hammer, debatable if it should even be here...
if options.force or options.reset: if options.force or options.reset:
self._Run(['reset', '--hard', 'HEAD'], options) self._Run(['reset', '--hard', 'HEAD'], options)
...@@ -692,31 +695,9 @@ class GitWrapper(SCMWrapper): ...@@ -692,31 +695,9 @@ class GitWrapper(SCMWrapper):
continue continue
raise e raise e
for _ in range(3): # Update the "branch-heads" remote-tracking branches, since we might need it
try: # to checkout a specific revision below.
# Add the "branch-heads" refspecs. Do this separately from the clone self._UpdateBranchHeads(options, fetch=True)
# command since apparently some versions of git don't support 'clone
# --config'.
# Don't assume 'with_branch_heads' is added by 'gclient sync' setup,
# since _Clone() can by reached in roundabout ways (e.g. 'gclient
# revert').
if hasattr(options, 'with_branch_heads') and options.with_branch_heads:
config_cmd = ['config', 'remote.origin.fetch',
'+refs/branch-heads/*:refs/remotes/branch-heads/*',
'^\\+refs/branch-heads/\\*:.*$']
self._Run(config_cmd, options)
# Update the "branch-heads" remote-tracking branches, since we might
# need it to checkout a specific revision below.
fetch_cmd = ['fetch', 'origin']
if options.verbose:
fetch_cmd.append('--verbose')
self._Run(fetch_cmd, options)
break
except subprocess2.CalledProcessError, e:
print(str(e))
print('Retrying...')
continue
if detach_head: if detach_head:
# Squelch git's very verbose detached HEAD warning and use our own # Squelch git's very verbose detached HEAD warning and use our own
...@@ -870,6 +851,28 @@ class GitWrapper(SCMWrapper): ...@@ -870,6 +851,28 @@ class GitWrapper(SCMWrapper):
stderr=subprocess2.PIPE, stderr=subprocess2.PIPE,
cwd=self.checkout_path).strip() cwd=self.checkout_path).strip()
def _UpdateBranchHeads(self, options, fetch=False):
"""Adds, and optionally fetches, "branch-heads" refspecs if requested."""
if hasattr(options, 'with_branch_heads') and options.with_branch_heads:
backoff_time = 5
for _ in range(3):
try:
config_cmd = ['config', 'remote.origin.fetch',
'+refs/branch-heads/*:refs/remotes/branch-heads/*',
'^\\+refs/branch-heads/\\*:.*$']
self._Run(config_cmd, options)
if fetch:
fetch_cmd = ['fetch', 'origin']
if options.verbose:
fetch_cmd.append('--verbose')
self._Run(fetch_cmd, options)
break
except subprocess2.CalledProcessError, e:
print(str(e))
print('Retrying in %.1f seconds...' % backoff_time)
time.sleep(backoff_time)
backoff_time *= 1.3
def _Run(self, args, options, **kwargs): def _Run(self, args, options, **kwargs):
kwargs.setdefault('cwd', self.checkout_path) kwargs.setdefault('cwd', self.checkout_path)
kwargs.setdefault('print_stdout', True) kwargs.setdefault('print_stdout', True)
......
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