gclient: in managed mode, warn if .gclient has a mismatched URL
BUG=
Review URL: https://codereview.chromium.org/195913002
git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@258617 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/gclient_scm.py b/gclient_scm.py
index e8ab140..76b4d8d 100644
--- a/gclient_scm.py
+++ b/gclient_scm.py
@@ -8,6 +8,7 @@
import os
import posixpath
import re
+import shlex
import sys
import tempfile
import traceback
@@ -139,6 +140,34 @@
return getattr(self, command)(options, args, file_list)
+ def GetActualRemoteURL(self):
+ """Attempt to determine the remote URL for this SCMWrapper."""
+ try:
+ return shlex.split(scm.GIT.Capture(
+ ['config', '--local', '--get-regexp', r'remote.*.url'],
+ self.checkout_path))[1]
+ except Exception:
+ pass
+ try:
+ return scm.SVN.CaptureLocalInfo([], self.checkout_path)['URL']
+ except Exception:
+ pass
+ return None
+
+ def DoesRemoteURLMatch(self):
+ """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()
+ if actual_remote_url:
+ return actual_remote_url.rstrip('/') == self.url.rstrip('/')
+ else:
+ # This may occur if the self.checkout_path exists but does not contain a
+ # valid git or svn checkout.
+ return False
+
class GitWrapper(SCMWrapper):
"""Wrapper for Git"""