Index: gclient.py |
diff --git a/gclient.py b/gclient.py |
index c3e295c42e1dca0fff893a61352cfa7deee4fe36..9df3d0cf324e7bbb06bfbf6fbba7a3e46fbfd83a 100755 |
--- a/gclient.py |
+++ b/gclient.py |
@@ -641,6 +641,35 @@ 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. |
+ if command == 'update': |
+ actual_remote_url = self._used_scm.GetRemoteURL(options) |
+ url, _ = gclient_utils.SplitUrlRevision(parsed_url) |
+ 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 |
+ if not should_delete: |
+ if sys.__stdout__.isatty(): |
iannucci
2013/11/15 18:25:25
I would combine these two conditions, I think
borenet
2013/11/25 13:55:42
Done.
|
+ usr_input = None |
+ while usr_input not in ('y', 'n'): |
iannucci
2013/11/15 18:25:25
maybe while `usr_input.lower() not in` and initial
borenet
2013/11/25 13:55:42
Changed to do raw_input(...).lower() since I would
|
+ 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)) |
iannucci
2013/11/15 18:25:25
I think you may want to re-formulate the end of th
borenet
2013/11/25 13:55:42
Done.
|
+ 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: |