From ed9e5acd61d7de5301e51fc0744b4f6aaf4aed0f Mon Sep 17 00:00:00 2001 From: Edward Lesmes Date: Wed, 15 Jul 2020 21:17:28 +0000 Subject: [PATCH] bot_update: Don't checkout 'master' after clone. Checkout 'HEAD' instead. This is needed to have a detached HEAD, so we can fetch refs/heads/main:refs/heads/main, where main is the default branch. Bug: 1104182 Change-Id: I7b7457b21b7d98d29583555b62e27e96e900adb4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2300533 Commit-Queue: Edward Lesmes Reviewed-by: Josip Sokcevic --- recipes/recipe_modules/bot_update/resources/bot_update.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/recipes/recipe_modules/bot_update/resources/bot_update.py b/recipes/recipe_modules/bot_update/resources/bot_update.py index 9607ae89e..4e9c103c4 100755 --- a/recipes/recipe_modules/bot_update/resources/bot_update.py +++ b/recipes/recipe_modules/bot_update/resources/bot_update.py @@ -771,8 +771,11 @@ def _git_checkout(sln, sln_dir, revisions, refs, no_fetch_tags, git_cache_dir, if not path.isdir(sln_dir): git('clone', '--no-checkout', '--local', '--shared', mirror_dir, sln_dir) - # Detach HEAD to be consistent with the non-clone case - git('checkout', 'master', '--detach', cwd=sln_dir) + # When bot_update clones a git repository, it results in HEAD referring + # to master in contrast with the non-clone case, which results in a + # detached HEAD. This prevents fetching the default branch so detach the + # HEAD after cloning. + git('checkout', 'HEAD', '--detach', cwd=sln_dir) _git_disable_gc(sln_dir) else: _git_disable_gc(sln_dir)