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 <sokcevic@google.com>
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
diff --git a/git_common.py b/git_common.py
index 8df16a8..91ddeb4 100644
--- a/git_common.py
+++ b/git_common.py
@@ -1043,7 +1043,8 @@
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