mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 10:41:31 +00:00
[git_cache] Check if HEAD still points to existing ref
It's possible that HEAD points to a different branch, and old one was deleted. This ensures that cache still has the correct HEAD information. Change-Id: Iab0b6badfd1f3e2c0e09fe542ee603b78d4a0041 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5218257 Commit-Queue: Josip Sokcevic <sokcevic@chromium.org> Reviewed-by: Gavin Mak <gavinmak@google.com>
This commit is contained in:
37
git_cache.py
37
git_cache.py
@@ -248,7 +248,7 @@ class Mirror(object):
|
||||
env.setdefault('GIT_ASKPASS', 'true')
|
||||
env.setdefault('SSH_ASKPASS', 'true')
|
||||
self.print('running "git %s" in "%s"' % (' '.join(cmd), cwd))
|
||||
gclient_utils.CheckCallAndFilter([self.git_exe] + cmd, **kwargs)
|
||||
return gclient_utils.CheckCallAndFilter([self.git_exe] + cmd, **kwargs)
|
||||
|
||||
def config(self, reset_fetch_config=False):
|
||||
if reset_fetch_config:
|
||||
@@ -467,20 +467,7 @@ class Mirror(object):
|
||||
with open(self._init_sentient_file, 'w'):
|
||||
# Create sentient file
|
||||
pass
|
||||
# Set appropriate symbolic-ref
|
||||
remote_info = exponential_backoff_retry(
|
||||
lambda: subprocess.check_output(
|
||||
[
|
||||
self.git_exe, '--git-dir',
|
||||
os.path.abspath(self.mirror_path), 'remote', 'show',
|
||||
self.url
|
||||
],
|
||||
cwd=self.mirror_path).decode('utf-8', 'ignore').strip())
|
||||
default_branch_regexp = re.compile(r'HEAD branch: (.*)$')
|
||||
m = default_branch_regexp.search(remote_info, re.MULTILINE)
|
||||
if m:
|
||||
self.RunGit(
|
||||
['symbolic-ref', 'HEAD', 'refs/heads/' + m.groups()[0]])
|
||||
self._set_symbolic_ref()
|
||||
else:
|
||||
# Bootstrap failed, previous cache exists; warn and continue.
|
||||
logging.warning(
|
||||
@@ -488,6 +475,19 @@ class Mirror(object):
|
||||
're-bootstrap but failed. Continuing with non-optimized '
|
||||
'repository.' % len(pack_files))
|
||||
|
||||
def _set_symbolic_ref(self):
|
||||
remote_info = exponential_backoff_retry(lambda: subprocess.check_output(
|
||||
[
|
||||
self.git_exe, '--git-dir',
|
||||
os.path.abspath(self.mirror_path), 'remote', 'show', self.url
|
||||
],
|
||||
cwd=self.mirror_path).decode('utf-8', 'ignore').strip())
|
||||
default_branch_regexp = re.compile(r'HEAD branch: (.*)')
|
||||
m = default_branch_regexp.search(remote_info, re.MULTILINE)
|
||||
if m:
|
||||
self.RunGit(['symbolic-ref', 'HEAD', 'refs/heads/' + m.groups()[0]])
|
||||
|
||||
|
||||
def _fetch(self,
|
||||
verbose,
|
||||
depth,
|
||||
@@ -534,6 +534,13 @@ class Mirror(object):
|
||||
if os.path.isfile(self._init_sentient_file):
|
||||
os.remove(self._init_sentient_file)
|
||||
|
||||
# Since --prune is used, it's possible that HEAD no longer exists (e.g.
|
||||
# a repo uses new HEAD and old is removed). This ensures that HEAD still
|
||||
# points to a valid commit, otherwise gets a new HEAD.
|
||||
out = self.RunGit(['rev-parse', 'HEAD'], print_stdout=False)
|
||||
if out.startswith(b'HEAD'):
|
||||
self._set_symbolic_ref()
|
||||
|
||||
def populate(self,
|
||||
depth=None,
|
||||
no_fetch_tags=False,
|
||||
|
||||
Reference in New Issue
Block a user