Force set HEAD to refs/heads/main for git_cache
We only build git_cache if main branch exists, and newly boostrap caches
have main as default. This sets HEAD for already boostrapped caches, in
case they were boostrapped before the default branch change.
R=gavinmak@google.com
Bug: 1251783
Change-Id: I715329ee06cf523f9fe2e6a324381dc5703bac34
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3218281
Auto-Submit: Josip Sokcevic <sokcevic@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
diff --git a/git_cache.py b/git_cache.py
index a76816d..82a3108 100755
--- a/git_cache.py
+++ b/git_cache.py
@@ -390,6 +390,10 @@
if depth and os.path.exists(os.path.join(self.mirror_path, 'shallow')):
logging.warning(
'Shallow fetch requested, but repo cache already exists.')
+ # Old boostraps may have old default HEAD, so this ensures main is always
+ # used.
+ self.RunGit(['symbolic-ref', 'HEAD', 'refs/heads/main'],
+ cwd=self.mirror_path)
return
if not self.exists():