Reset origin/HEAD in git_cache if it points to master

This change resets refs/remotes/origin/HEAD if it points to master. With the master to main migration going on with chromium repositories, some of the cached git repositories end up pointing to master instead of main. This change aids in fixing this issue.

Bug: 1364030
Change-Id: Ic181b0179daf7b2b842cff7f7187d94d9fb20007
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4029356
Auto-Submit: Aravind Vasudevan <aravindvasudev@google.com>
Reviewed-by: Josip Sokcevic <sokcevic@google.com>
Commit-Queue: Josip Sokcevic <sokcevic@google.com>
changes/56/4029356/3
Aravind Vasudevan 2 years ago committed by LUCI CQ
parent 8de7b2d51b
commit 63fea808b0

@ -439,6 +439,15 @@ class Mirror(object):
'Git cache has a lot of pack files (%d). Tried to re-bootstrap '
'but failed. Continuing with non-optimized repository.' %
len(pack_files))
else:
# Reset head when refs/remotes/origin/HEAD points to master.
# https://crbug.com/1364030
origin_head = subprocess.check_output(
[self.git_exe, 'symbolic-ref', 'refs/remotes/origin/HEAD'],
cwd=self.mirror_path).decode('utf-8', 'ignore').strip()
if origin_head.endswith('master'):
self.RunGit(['remote', 'set-head', '-a', 'origin'])
def _fetch(self,
rundir,

Loading…
Cancel
Save