gclient: Fix cache_dir functionality

BUG=361155

Review URL: https://codereview.chromium.org/228793002

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@262478 0039d316-1c4b-4281-b951-d872f2087c98
experimental/szager/collated-output
borenet@google.com 11 years ago
parent 9788236b59
commit 4e9be26d99

@ -1051,8 +1051,8 @@ solutions = [
for dep in self.dependencies:
if dep.managed and dep.url:
scm = gclient_scm.CreateSCM(dep.url, self.root_dir, dep.name)
actual_url = scm.GetActualRemoteURL()
if actual_url and not scm.DoesRemoteURLMatch():
actual_url = scm.GetActualRemoteURL(self._options)
if actual_url and not scm.DoesRemoteURLMatch(self._options):
raise gclient_utils.Error('''
Your .gclient file seems to be broken. The requested URL is different from what
is actually checked out in %(checkout_path)s.

@ -140,23 +140,41 @@ class SCMWrapper(object):
return getattr(self, command)(options, args, file_list)
def GetActualRemoteURL(self):
def GetActualRemoteURL(self, options):
"""Attempt to determine the remote URL for this SCMWrapper."""
# Git
if os.path.exists(os.path.join(self.checkout_path, '.git')):
return shlex.split(scm.GIT.Capture(
actual_remote_url = shlex.split(scm.GIT.Capture(
['config', '--local', '--get-regexp', r'remote.*.url'],
self.checkout_path))[1]
# If a cache_dir is used, obtain the actual remote URL from the cache.
if getattr(self, 'cache_dir', None):
try:
full_cache_dir = self._Run(['cache', 'exists', '--cache-dir',
self.cache_dir, self.url],
options, cwd=self._root_dir).strip()
except subprocess2.CalledProcessError:
full_cache_dir = None
if (full_cache_dir.replace('\\', '/') ==
actual_remote_url.replace('\\', '/')):
actual_remote_url = shlex.split(scm.GIT.Capture(
['config', '--local', '--get-regexp', r'remote.*.url'],
os.path.join(self._root_dir, full_cache_dir)))[1]
return actual_remote_url
# Svn
if os.path.exists(os.path.join(self.checkout_path, '.svn')):
return scm.SVN.CaptureLocalInfo([], self.checkout_path)['URL']
return None
def DoesRemoteURLMatch(self):
def DoesRemoteURLMatch(self, options):
"""Determine whether the remote URL of this checkout is the expected URL."""
if not os.path.exists(self.checkout_path):
# A checkout which doesn't exist can't be broken.
return True
actual_remote_url = self.GetActualRemoteURL()
actual_remote_url = self.GetActualRemoteURL(options)
if actual_remote_url:
return (gclient_utils.SplitUrlRevision(actual_remote_url)[0].rstrip('/')
== gclient_utils.SplitUrlRevision(self.url)[0].rstrip('/'))

@ -45,10 +45,10 @@ class SCMMock(object):
return self.url + url
# pylint: disable=R0201
def DoesRemoteURLMatch(self):
def DoesRemoteURLMatch(self, _):
return True
def GetActualRemoteURL(self):
def GetActualRemoteURL(self, _):
return self.url

Loading…
Cancel
Save