Commit 39d870e1 authored by Sylvain Defresne's avatar Sylvain Defresne Committed by LUCI CQ

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/+/2475773Reviewed-by: 's avatarJosip Sokcevic <sokcevic@google.com>
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
parent 5d099fcb
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment