gclient: Fix auto-fetching refs.

gclient executes `git rev-parse <ref>` to check if <ref>
already exists in the local clone, which succeeds when
<ref> is a git revision hash, even if it doesn't exist.

We execute `git rev-parse <ref>^{commit}` instead, which only
succeeds when <ref> resolves to a valid commit in the local
repo.

Change-Id: Ia1cdf7162c4c82a7e4214c6af375c1a9522d7b07
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2095745
Reviewed-by: Josip Sokcevic <sokcevic@google.com>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
changes/45/2095745/24
Edward Lemur 5 years ago committed by LUCI CQ
parent d52eddaad2
commit e0ba7b8e7a

@ -1374,9 +1374,7 @@ class GitWrapper(SCMWrapper):
"""Attempts to fetch |revision| if not available in local repo.
Returns possibly updated revision."""
try:
self._Capture(['rev-parse', revision])
except subprocess2.CalledProcessError:
if not scm.GIT.IsValidRevision(self.checkout_path, revision):
self._Fetch(options, refspec=revision)
revision = self._Capture(['rev-parse', 'FETCH_HEAD'])
return revision

Loading…
Cancel
Save