 Chromium Code Reviews
 Chromium Code Reviews Issue 61623008:
  If the destination directory doesn't contain the desired repo, delete it  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
    
  
    Issue 61623008:
  If the destination directory doesn't contain the desired repo, delete it  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master| Index: gclient_scm.py | 
| diff --git a/gclient_scm.py b/gclient_scm.py | 
| index f5a434b1edaada44cfcc93e64cf897f2d3ca5ae7..3f1bfcc87b4917e6d8f5dc06e03fcc11bb68137d 100644 | 
| --- a/gclient_scm.py | 
| +++ b/gclient_scm.py | 
| @@ -215,6 +215,13 @@ class GitWrapper(SCMWrapper): | 
| def GetCheckoutRoot(self): | 
| return scm.GIT.GetCheckoutRoot(self.checkout_path) | 
| + def GetRemoteURL(self, options, cwd=None): | 
| + try: | 
| + return self._Capture(['config', 'remote.origin.url'], | 
| + cwd=cwd or self.checkout_path).rstrip() | 
| + except (OSError, subprocess2.CalledProcessError): | 
| + return None | 
| + | 
| def GetRevisionDate(self, _revision): | 
| """Returns the given revision's date in ISO-8601 format (which contains the | 
| time zone).""" | 
| @@ -272,22 +279,6 @@ class GitWrapper(SCMWrapper): | 
| gclient_utils.CheckCallAndFilter(cmd4, **kwargs) | 
| - def _FetchAndReset(self, revision, file_list, options): | 
| - """Equivalent to git fetch; git reset.""" | 
| - quiet = [] | 
| - if not options.verbose: | 
| - quiet = ['--quiet'] | 
| - self._UpdateBranchHeads(options, fetch=False) | 
| - | 
| - fetch_cmd = [ | 
| - '-c', 'core.deltaBaseCacheLimit=2g', 'fetch', 'origin', '--prune'] | 
| - self._Run(fetch_cmd + quiet, options, retry=True) | 
| - self._Run(['reset', '--hard', revision] + quiet, options) | 
| - self.UpdateSubmoduleConfig() | 
| - if file_list is not None: | 
| - files = self._Capture(['ls-files']).splitlines() | 
| - file_list.extend([os.path.join(self.checkout_path, f) for f in files]) | 
| - | 
| def update(self, options, args, file_list): | 
| """Runs git to update or transparently checkout the working copy. | 
| @@ -373,35 +364,10 @@ class GitWrapper(SCMWrapper): | 
| '\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.origin.url']) | 
| - return_early = False | 
| - # TODO(maruel): Delete url != 'git://foo' since it's just to make the | 
| - # unit test pass. (and update the comment above) | 
| - # 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 | 
| - url != 'git://foo' and | 
| - subprocess2.capture( | 
| - ['git', 'config', 'remote.origin.gclient-auto-fix-url'], | 
| - cwd=self.checkout_path).strip() != 'False'): | 
| - print('_____ switching %s to a new upstream' % self.relpath) | 
| - # Make sure it's clean | 
| - self._CheckClean(rev_str) | 
| - # Switch over to the new upstream | 
| - self._Run(['remote', 'set-url', 'origin', url], options) | 
| - self._FetchAndReset(revision, file_list, options) | 
| - return_early = True | 
| - | 
| # Need to do this in the normal path as well as in the post-remote-switch | 
| # path. | 
| self._PossiblySwitchCache(url, options) | 
| - if return_early: | 
| - return self._Capture(['rev-parse', '--verify', 'HEAD']) | 
| - | 
| cur_branch = self._GetCurrentBranch() | 
| # Cases: | 
| @@ -807,8 +773,7 @@ class GitWrapper(SCMWrapper): | 
| # to relax this restriction in the future to allow for smarter cache | 
| # repo update schemes (such as pulling the same repo, but from a | 
| # different host). | 
| - existing_url = self._Capture(['config', 'remote.origin.url'], | 
| - cwd=folder) | 
| + existing_url = self.GetRemoteURL(options, cwd=folder) | 
| assert self._NormalizeGitURL(existing_url) == self._NormalizeGitURL(url) | 
| if use_reference: | 
| @@ -1077,6 +1042,13 @@ class SVNWrapper(SCMWrapper): | 
| def GetCheckoutRoot(self): | 
| return scm.SVN.GetCheckoutRoot(self.checkout_path) | 
| + def GetRemoteURL(self, options): | 
| + try: | 
| + local_info = scm.SVN.CaptureLocalInfo([os.curdir], self.checkout_path) | 
| + except (OSError, subprocess2.CalledProcessError): | 
| + return None | 
| + return local_info.get('URL') | 
| + | 
| def GetRevisionDate(self, revision): | 
| """Returns the given revision's date in ISO-8601 format (which contains the | 
| time zone).""" | 
| @@ -1221,53 +1193,6 @@ class SVNWrapper(SCMWrapper): | 
| revision = str(from_info_live['Revision']) | 
| rev_str = ' at %s' % revision | 
| 
borenet
2013/12/10 18:48:27
I missed this section before - Isaac, this URL rew
 
Isaac (away)
2013/12/11 03:17:33
I'm not very familiar with this, having essentiall
 
borenet
2013/12/11 20:42:19
It does conflict.  When I overrode the googlecode_
 
iannucci
2014/01/07 22:23:28
So IIUC, the new behavior will simply nuke the con
 
borenet
2014/01/08 18:25:33
Exactly.
 | 
| - if from_info['URL'] != base_url: | 
| - # The repository url changed, need to switch. | 
| - try: | 
| - to_info = scm.SVN.CaptureRemoteInfo(url) | 
| - except (gclient_utils.Error, subprocess2.CalledProcessError): | 
| - # The url is invalid or the server is not accessible, it's safer to bail | 
| - # out right now. | 
| - raise gclient_utils.Error('This url is unreachable: %s' % url) | 
| - can_switch = ((from_info['Repository Root'] != to_info['Repository Root']) | 
| - and (from_info['UUID'] == to_info['UUID'])) | 
| - if can_switch: | 
| - print('\n_____ relocating %s to a new checkout' % self.relpath) | 
| - # We have different roots, so check if we can switch --relocate. | 
| - # Subversion only permits this if the repository UUIDs match. | 
| - # Perform the switch --relocate, then rewrite the from_url | 
| - # to reflect where we "are now." (This is the same way that | 
| - # Subversion itself handles the metadata when switch --relocate | 
| - # is used.) This makes the checks below for whether we | 
| - # can update to a revision or have to switch to a different | 
| - # branch work as expected. | 
| - # TODO(maruel): TEST ME ! | 
| - command = ['switch', '--relocate', | 
| - from_info['Repository Root'], | 
| - to_info['Repository Root'], | 
| - self.relpath] | 
| - self._Run(command, options, cwd=self._root_dir) | 
| - from_info['URL'] = from_info['URL'].replace( | 
| - from_info['Repository Root'], | 
| - to_info['Repository Root']) | 
| - else: | 
| - if not options.force and not options.reset: | 
| - # Look for local modifications but ignore unversioned files. | 
| - for status in scm.SVN.CaptureStatus(None, self.checkout_path): | 
| - if status[0][0] != '?': | 
| - raise gclient_utils.Error( | 
| - ('Can\'t switch the checkout to %s; UUID don\'t match and ' | 
| - 'there is local changes in %s. Delete the directory and ' | 
| - 'try again.') % (url, self.checkout_path)) | 
| - # Ok delete it. | 
| - print('\n_____ switching %s to a new checkout' % self.relpath) | 
| - gclient_utils.rmtree(self.checkout_path) | 
| - # We need to checkout. | 
| - command = ['checkout', url, self.checkout_path] | 
| - command = self._AddAdditionalUpdateFlags(command, options, revision) | 
| - self._RunAndGetFileList(command, options, file_list, self._root_dir) | 
| - return self.Svnversion() | 
| - | 
| # If the provided url has a revision number that matches the revision | 
| # number of the existing directory, then we don't need to bother updating. | 
| if not options.force and str(from_info['Revision']) == revision: |