From 39d870e1f07f8908701d160b5445782cdd3f1541 Mon Sep 17 00:00:00 2001 From: Sylvain Defresne Date: Thu, 15 Oct 2020 16:27:45 +0000 Subject: [PATCH] Fix `git map-branches` when branch is named after a file/directory If there is a branch named after a file in the repository root, the command `git rev-list --count $branch ^$base` is ambiguous. This is because `git` does not know whether $branch needs to be parsed as a revision or a filename. Adding a trailing `--` parameter to the command-line resolves this ambiguity since when present, everything before the `--` cannot be a filename and everything after `--` has to one. From git documentation: Paths may need to be prefixed with -- to separate them from options or the revision range, when confusion arises. Bug: none Change-Id: Ieb10aa8701e12fc3c88d5f75ff624f61ee8d8aaa Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2475773 Reviewed-by: Josip Sokcevic Commit-Queue: Sylvain Defresne --- git_common.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/git_common.py b/git_common.py index 8df16a857..91ddeb49a 100644 --- a/git_common.py +++ b/git_common.py @@ -1043,7 +1043,8 @@ def get_branches_info(include_tracking_status): commits = None base = get_or_create_merge_base(branch) if base: - commits = int(run('rev-list', '--count', branch, '^%s' % base)) or None + commits_list = run('rev-list', '--count', branch, '^%s' % base, '--') + commits = int(commits_list) or None behind_match = re.search(r'behind (\d+)', tracking_status) behind = int(behind_match.group(1)) if behind_match else None