From 009150b7afe1f47dabc5537d0e42649bf7f193a3 Mon Sep 17 00:00:00 2001 From: Andrii Shyshkalov Date: Thu, 30 Nov 2017 16:03:16 -0800 Subject: [PATCH] bot_update: be explicit when checking out branches. $ git checkout may be interpreted by git as checking out a file named if has slashes. Thus, $ git checkout infra/config ends up checking out infra/config directory of the (typically) master branch that was checked out before. To avoid confusion, we have to add '--' separator between branch name and file names: $ git checkout -- This in turns allows to run CQ-based presubmit on infra/config branches. R=nodir@chromium.org Bug: 790738 Change-Id: I6ce31a8f0fbd66fd59ac7c2ea9cccd3ff97d1f0e Reviewed-on: https://chromium-review.googlesource.com/802136 Commit-Queue: Andrii Shyshkalov Reviewed-by: Nodir Turakulov --- .../recipe_modules/bot_update/resources/bot_update.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/recipes/recipe_modules/bot_update/resources/bot_update.py b/recipes/recipe_modules/bot_update/resources/bot_update.py index cd697575a..f711e702d 100755 --- a/recipes/recipe_modules/bot_update/resources/bot_update.py +++ b/recipes/recipe_modules/bot_update/resources/bot_update.py @@ -527,7 +527,7 @@ def force_solution_revision(solution_name, git_url, revisions, cwd): branch, revision = _get_target_branch_and_revision( solution_name, git_url, revisions) if revision and revision.upper() != 'HEAD': - git('checkout', '--force', revision, cwd=cwd) + treeish = revision else: # TODO(machenbach): This won't work with branch-heads, as Gerrit's # destination branch would be e.g. refs/branch-heads/123. But here @@ -535,8 +535,12 @@ def force_solution_revision(solution_name, git_url, revisions, cwd): # This will also not work if somebody passes a local refspec like # refs/heads/master. It needs to translate to refs/remotes/origin/master # first. See also https://crbug.com/740456 . - ref = branch if branch.startswith('refs/') else 'origin/%s' % branch - git('checkout', '--force', ref, cwd=cwd) + treeish = branch if branch.startswith('refs/') else 'origin/%s' % branch + + # Note that -- argument is necessary to ensure that git treats `treeish` + # argument as revision or ref, and not as a file/directory which happens to + # have the exact same name. + git('checkout', '--force', treeish, '--', cwd=cwd) def is_broken_repo_dir(repo_dir):