Commit 2b29d0f8 authored by Gavin Mak's avatar Gavin Mak Committed by LUCI CQ

Fix invalid reference: refs/remotes/origin/HEAD error

Change-Id: Iac298a7a14b5c0b55fd199ec120fe5c37ef88fdc
Bug: 1178944
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2757129Reviewed-by: 's avatarEdward Lesmes <ehmaldonado@chromium.org>
Commit-Queue: Gavin Mak <gavinmak@google.com>
parent 55a12fba
......@@ -770,6 +770,7 @@ def _git_checkout(sln, sln_dir, revisions, refs, no_fetch_tags, git_cache_dir,
# Step 2: populate a checkout from local cache. All operations are local.
mirror_dir = git(
'cache', 'exists', '--quiet', '--cache-dir', git_cache_dir, url).strip()
_set_remote_head(mirror_dir)
first_try = True
while True:
try:
......@@ -789,6 +790,7 @@ def _git_checkout(sln, sln_dir, revisions, refs, no_fetch_tags, git_cache_dir,
git('remote', 'set-url', 'origin', mirror_dir, cwd=sln_dir)
git('fetch', 'origin', cwd=sln_dir)
git('remote', 'set-url', '--push', 'origin', url, cwd=sln_dir)
_set_remote_head(sln_dir)
for ref in refs:
refspec = '%s:%s' % (ref, ref_to_remote_ref(ref.lstrip('+')))
git('fetch', 'origin', refspec, cwd=sln_dir)
......@@ -821,6 +823,19 @@ def _git_disable_gc(cwd):
git('config', 'gc.autopacklimit', '0', cwd=cwd)
def _set_remote_head(cwd):
if len(git('ls-remote', 'origin', 'HEAD', cwd=cwd)) > 0:
return
try:
git('remote', 'set-head', 'origin', '--auto', cwd=cwd)
except SubprocessFailed:
# If remote HEAD cannot be set automatically, prefer main over master.
try:
git('remote', 'set-head', 'origin', 'main', cwd=cwd)
except SubprocessFailed:
git('remote', 'set-head', 'origin', 'master', cwd=cwd)
def get_commit_position(git_path, revision='HEAD'):
"""Dumps the 'git' log for a specific revision and parses out the commit
position.
......
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