Chromium Code Reviews| Index: gclient_scm.py |
| diff --git a/gclient_scm.py b/gclient_scm.py |
| index 913d9a57e6746eba82bda263d430a11163696e08..0672ab154248ff663b9910e6224f1745705af9e0 100644 |
| --- a/gclient_scm.py |
| +++ b/gclient_scm.py |
| @@ -4,6 +4,8 @@ |
| """Gclient-specific SCM-specific operations.""" |
| +# TODO(borenet): Uncomment this once SCMWrapper._DeleteOrMove is enabled. |
| +#import errno |
|
iannucci
2014/04/04 00:49:54
Probably should just leave these comments out and
borenet
2014/04/07 14:24:02
Done.
|
| import logging |
| import os |
| import posixpath |
| @@ -17,6 +19,8 @@ import urlparse |
| import download_from_google_storage |
| import gclient_utils |
| import scm |
| +# TODO(borenet): Uncomment this once SCMWrapper._DeleteOrMove is enabled. |
| +#import shutil |
| import subprocess2 |
| @@ -165,6 +169,45 @@ class SCMWrapper(object): |
| # valid git or svn checkout. |
| return False |
| + # TODO(borenet): Remove this once SCMWrapper._DeleteOrMove is enabled. |
| + # pylint: disable=R0201 |
| + def _DeleteOrMove(self, force): |
| + """Delete the checkout directory or move it out of the way. |
| + |
| + Args: |
| + force: bool; if True, delete the directory. Otherwise, just move it. |
| + """ |
| + # TODO(borenet): Uncomment the below implementation once we're sure nobody |
| + # will trigger it accidentally. |
| + gclient_utils.AddWarning('WARNING: Upcoming changes would cause %s to be ' |
|
iannucci
2014/04/04 00:49:54
Prep the cl to turn this feature on, and mention i
borenet
2014/04/07 14:24:02
Done.
|
| + 'deleted or moved to the side. This is intended ' |
| + 'to ease changes to DEPS in the future. If you ' |
| + 'are seeing this warning and haven\'t changed the ' |
| + 'DEPS file, please contact borenet@ immediately.' |
| + % self.checkout_path) |
| +# if force: |
| +# print('_____ Conflicting directory found in %s. Removing.' |
| +# % self.checkout_path) |
| +# gclient_utils.rmtree(self.checkout_path) |
| +# else: |
| +# bad_scm_dir = os.path.join(self._root_dir, '_bad_scm', |
| +# os.path.dirname(self.relpath)) |
| +# |
| +# try: |
| +# os.makedirs(bad_scm_dir) |
| +# except OSError as e: |
| +# if e.errno != errno.EEXIST: |
| +# raise |
| +# |
| +# dest_path = tempfile.mkdtemp( |
| +# prefix=os.path.basename(self.relpath), |
| +# dir=bad_scm_dir) |
| +# print('_____ Conflicting directory found in %s. Moving to %s.' |
| +# % (self.checkout_path, dest_path)) |
| +# gclient_utils.AddWarning('Conflicting directory %s moved to %s.' |
| +# % (self.checkout_path, dest_path)) |
| +# shutil.move(self.checkout_path, dest_path) |
| + |
| class GitWrapper(SCMWrapper): |
| """Wrapper for Git""" |
| @@ -326,6 +369,9 @@ class GitWrapper(SCMWrapper): |
| if (not os.path.exists(self.checkout_path) or |
| (os.path.isdir(self.checkout_path) and |
| not os.path.exists(os.path.join(self.checkout_path, '.git')))): |
| + if (os.path.isdir(self.checkout_path) and |
| + not os.path.exists(os.path.join(self.checkout_path, '.git'))): |
| + self._DeleteOrMove(options.force) |
| self._Clone(revision, url, options) |
| self.UpdateSubmoduleConfig() |
| if file_list is not None: |
| @@ -343,14 +389,6 @@ class GitWrapper(SCMWrapper): |
| print ('________ unmanaged solution; skipping %s' % self.relpath) |
| return self._Capture(['rev-parse', '--verify', 'HEAD']) |
| - if not os.path.exists(os.path.join(self.checkout_path, '.git')): |
| - raise gclient_utils.Error('\n____ %s%s\n' |
| - '\tPath is not a git repo. No .git dir.\n' |
| - '\tTo resolve:\n' |
| - '\t\trm -rf %s\n' |
| - '\tAnd run gclient sync again\n' |
| - % (self.relpath, rev_str, self.relpath)) |
| - |
| # See if the url has changed (the unittests use git://foo for the url, let |
| # that through). |
| current_url = self._Capture(['config', 'remote.%s.url' % self.remote]) |
| @@ -360,7 +398,7 @@ class GitWrapper(SCMWrapper): |
| # Skip url auto-correction if remote.origin.gclient-auto-fix-url is set. |
| # This allows devs to use experimental repos which have a different url |
| # but whose branch(s) are the same as official repos. |
| - if (current_url != url and |
| + if (current_url.rstrip('/') != url.rstrip('/') and |
| url != 'git://foo' and |
| subprocess2.capture( |
| ['git', 'config', 'remote.%s.gclient-auto-fix-url' % self.remote], |
| @@ -1024,12 +1062,7 @@ class SVNWrapper(SCMWrapper): |
| Raises: |
| Error: if can't get URL for relative path. |
| """ |
| - # Only update if git or hg is not controlling the directory. |
| - git_path = os.path.join(self.checkout_path, '.git') |
| - if os.path.exists(git_path): |
| - print('________ found .git directory; skipping %s' % self.relpath) |
| - return |
| - |
| + # Only update if hg is not controlling the directory. |
| hg_path = os.path.join(self.checkout_path, '.hg') |
| if os.path.exists(hg_path): |
| print('________ found .hg directory; skipping %s' % self.relpath) |
| @@ -1060,21 +1093,26 @@ class SVNWrapper(SCMWrapper): |
| forced_revision = False |
| rev_str = '' |
| - # Get the existing scm url and the revision number of the current checkout. |
| exists = os.path.exists(self.checkout_path) |
| if exists and managed: |
| + # Git is only okay if it's a git-svn checkout of the right repo. |
| + if scm.GIT.IsGitSvn(self.checkout_path): |
| + remote_url = scm.GIT.Capture(['config', '--local', '--get', |
| + 'svn-remote.svn.url'], |
| + cwd=self.checkout_path).rstrip() |
| + if remote_url.rstrip('/') == base_url.rstrip('/'): |
| + print('\n_____ %s looks like a git-svn checkout. Skipping.' |
| + % self.relpath) |
| + return # TODO(borenet): Get the svn revision number? |
| + |
| + # Get the existing scm url and the revision number of the current checkout. |
| + if exists and managed: |
| try: |
| from_info = scm.SVN.CaptureLocalInfo( |
| [], os.path.join(self.checkout_path, '.')) |
| except (gclient_utils.Error, subprocess2.CalledProcessError): |
| - if options.reset and options.delete_unversioned_trees: |
| - print 'Removing troublesome path %s' % self.checkout_path |
| - gclient_utils.rmtree(self.checkout_path) |
| - exists = False |
| - else: |
| - msg = ('Can\'t update/checkout %s if an unversioned directory is ' |
| - 'present. Delete the directory and try again.') |
| - raise gclient_utils.Error(msg % self.checkout_path) |
| + self._DeleteOrMove(options.force) |
| + exists = False |
| BASE_URLS = { |
| '/chrome/trunk/src': 'gs://chromium-svn-checkout/chrome/', |
| @@ -1154,7 +1192,9 @@ class SVNWrapper(SCMWrapper): |
| if not managed: |
| print ('________ unmanaged solution; skipping %s' % self.relpath) |
| - return self.Svnversion() |
| + if os.path.exists(os.path.join(self.checkout_path, '.svn')): |
| + return self.Svnversion() |
| + return |
| if 'URL' not in from_info: |
| raise gclient_utils.Error( |
| @@ -1197,7 +1237,7 @@ class SVNWrapper(SCMWrapper): |
| revision = str(from_info_live['Revision']) |
| rev_str = ' at %s' % revision |
| - if from_info['URL'] != base_url: |
| + if from_info['URL'].rstrip('/') != base_url.rstrip('/'): |
| # The repository url changed, need to switch. |
| try: |
| to_info = scm.SVN.CaptureRemoteInfo(url) |