From 19794fe91fc88ccf6fc31c65da6f32c0b5938ae0 Mon Sep 17 00:00:00 2001 From: Aravind Vasudevan Date: Tue, 28 Feb 2023 18:58:56 +0000 Subject: [PATCH] Reset origin/HEAD when it points to master This change tries resetting origin/HEAD when it points to master and the ref cannot be found. Post master->main migration, some cached repositories seem to point origin/HEAD to master. Bug: 1418866 Change-Id: I83942901b105cace4d51deeac7e400f98d200168 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4296441 Reviewed-by: Fumitoshi Ukai Commit-Queue: Aravind Vasudevan Reviewed-by: Josip Sokcevic --- .../bot_update/resources/bot_update.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/recipes/recipe_modules/bot_update/resources/bot_update.py b/recipes/recipe_modules/bot_update/resources/bot_update.py index 681305f4f..d9d6e9bae 100755 --- a/recipes/recipe_modules/bot_update/resources/bot_update.py +++ b/recipes/recipe_modules/bot_update/resources/bot_update.py @@ -735,7 +735,19 @@ def _git_checkout(sln, sln_dir, revisions, refs, no_fetch_tags, git_cache_dir, # Note that the '--' argument is needed to ensure that git treats # 'pin or branch' as revision or ref, and not as file/directory which # happens to have the exact same name. - git('checkout', '--force', pin or branch, '--', cwd=sln_dir) + ref = pin or branch + try: + git('checkout', '--force', ref, '--', cwd=sln_dir) + except SubprocessFailed as e: + # TODO(crbug.com/1418866): master->main migration leaves some builders + # broken with outdated ref for origin/HEAD in cache. In this case, + # reset the ref and retry. + if ref != 'refs/remotes/origin/HEAD': + raise e + + git('remote', 'set-head', '-a', 'origin', cwd=sln_dir) + git('checkout', '--force', ref, '--', cwd=sln_dir) + git('clean', '-dff', cwd=sln_dir) return except SubprocessFailed as e: