From 56dbf9a4b50ca5cab6d1588272092fd8b62079dc Mon Sep 17 00:00:00 2001 From: Edward Lesmes Date: Tue, 31 Mar 2020 22:52:54 +0000 Subject: [PATCH] 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/+/2127968 Reviewed-by: Josip Sokcevic Commit-Queue: Edward Lesmes --- scm.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/scm.py b/scm.py index aa65dacf1..b216ff576 100644 --- a/scm.py +++ b/scm.py @@ -378,14 +378,16 @@ class GIT(object): @staticmethod def ResolveCommit(cwd, rev): - if sys.platform.startswith('win'): - # Windows .bat scripts use ^ as escape sequence, which means we have to - # escape it with itself for every .bat invocation. - needle = '%s^^{commit}' % rev - else: - needle = '%s^{commit}' % rev + # We do this instead of rev-parse --verify rev^{commit}, since on Windows + # git can be either an executable or batch script, each of which requires + # escaping the caret (^) a different way. + if gclient_utils.IsFullGitSha(rev): + # git-rev parse --verify FULL_GIT_SHA always succeeds, even if we don't + # 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: - return GIT.Capture(['rev-parse', '--quiet', '--verify', needle], cwd=cwd) + return GIT.Capture(['rev-parse', '--quiet', '--verify', rev], cwd=cwd) except subprocess2.CalledProcessError: return None