 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.py | 
| diff --git a/gclient.py b/gclient.py | 
| index c3e295c42e1dca0fff893a61352cfa7deee4fe36..f3a11c72984f175e9be7cf0f410b607b9de9653e 100755 | 
| --- a/gclient.py | 
| +++ b/gclient.py | 
| @@ -641,6 +641,40 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): | 
| command, options, parsed_url, self.parent.name, revision_overrides) | 
| self._used_scm = gclient_scm.CreateSCM( | 
| parsed_url, self.root.root_dir, self.name) | 
| + | 
| + # When updating, determine whether the destination directory contains a | 
| + # checkout of the desired repository. If not, avoid conflicts by | 
| + # deleting the directory before running the update. | 
| + # TODO(borenet): Only enabling this on a few bots at first. | 
| + import socket | 
| + if (command == 'update' and | 
| + socket.gethostname() in ('vm859-m1', 'build1-m1', 'vm630-m1')): | 
| + logging.warning('Experimental deletion of mismatching checkouts ' | 
| + 'enabled.') | 
| 
borenet
2013/12/10 18:48:27
Per Isaac's suggestion, using the hostname to enab
 
Isaac (away)
2013/12/11 03:17:33
This looks good to me.  To be extra safe, maybe al
 
borenet
2013/12/11 20:42:19
Done.
 | 
| + actual_remote_url = self._used_scm.GetRemoteURL(options) | 
| + url, _ = gclient_utils.SplitUrlRevision(parsed_url) | 
| + url = url.rstrip('/') | 
| + dest_dir = os.path.join(self.root.root_dir, self.name) | 
| + if os.path.isdir(dest_dir) and actual_remote_url != url: | 
| + should_delete = options.force or os.environ.get('CHROME_HEADLESS') | 
| + if sys.__stdout__.isatty() and not should_delete: | 
| + usr_input = '' | 
| + while usr_input not in ('y', 'n'): | 
| + usr_input = raw_input('%s does not contain a checkout of %s. ' | 
| + 'Do you want to delete the directory? ' | 
| + 'If not, the update will be canceled ' | 
| + '(y/n): ' % (dest_dir, url)).lower() | 
| + should_delete = (usr_input == 'y') | 
| + if should_delete: | 
| + logging.warning('%s does not contain a checkout of %s. Removing ' | 
| + ' %s' % (dest_dir, url, dest_dir)) | 
| + gclient_utils.rmtree(dest_dir) | 
| + else: | 
| + raise gclient_utils.Error('%s does not contain a checkout of %s. ' | 
| + 'Please fix the solution manually or ' | 
| + 'run with --force to delete ' | 
| + 'automatically.' % (dest_dir, url)) | 
| + | 
| self._got_revision = self._used_scm.RunCommand(command, options, args, | 
| file_list) | 
| if file_list: |