From 63fea808b00889ca603f083febe010a8fa7dded7 Mon Sep 17 00:00:00 2001 From: Aravind Vasudevan Date: Wed, 16 Nov 2022 00:29:09 +0000 Subject: [PATCH] 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 Reviewed-by: Josip Sokcevic Commit-Queue: Josip Sokcevic --- git_cache.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/git_cache.py b/git_cache.py index 1c5a1fe38f..0c80ccfa83 100755 --- a/git_cache.py +++ b/git_cache.py @@ -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,