Commit 56dbf9a4 authored by Edward Lesmes's avatar Edward Lesmes Committed by LUCI CQ

depot_tools: Don't use carets when checking if a revision exists.

On Windows, git can be either an executable or batch script, each of
which requires carets (^) to be escaped in different ways.

This makes it hard to use `git rev-parse --verify REV^{commit}`, so we
truncate full hash revisions to achieve the same effect instead.

Change-Id: I01578620706a1bab75a2decc55d9b4f1ac3afe28
Bug: 1065307
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2127968Reviewed-by: 's avatarJosip Sokcevic <sokcevic@google.com>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
parent beec6607
...@@ -378,14 +378,16 @@ class GIT(object): ...@@ -378,14 +378,16 @@ class GIT(object):
@staticmethod @staticmethod
def ResolveCommit(cwd, rev): def ResolveCommit(cwd, rev):
if sys.platform.startswith('win'): # We do this instead of rev-parse --verify rev^{commit}, since on Windows
# Windows .bat scripts use ^ as escape sequence, which means we have to # git can be either an executable or batch script, each of which requires
# escape it with itself for every .bat invocation. # escaping the caret (^) a different way.
needle = '%s^^{commit}' % rev if gclient_utils.IsFullGitSha(rev):
else: # git-rev parse --verify FULL_GIT_SHA always succeeds, even if we don't
needle = '%s^{commit}' % rev # have FULL_GIT_SHA locally. Removing the last character forces git to
# check if FULL_GIT_SHA refers to an object in the local database.
rev = rev[:-1]
try: try:
return GIT.Capture(['rev-parse', '--quiet', '--verify', needle], cwd=cwd) return GIT.Capture(['rev-parse', '--quiet', '--verify', rev], cwd=cwd)
except subprocess2.CalledProcessError: except subprocess2.CalledProcessError:
return None return 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