Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Side by Side Diff: gclient.py

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
Patch Set: Error out if the conflicting directory isn't deleted. Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | gclient_scm.py » ('j') | gclient_scm.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Meta checkout manager supporting both Subversion and GIT.""" 6 """Meta checkout manager supporting both Subversion and GIT."""
7 # Files 7 # Files
8 # .gclient : Current client configuration, written by 'config' command. 8 # .gclient : Current client configuration, written by 'config' command.
9 # Format is a Python script defining 'solutions', a list whose 9 # Format is a Python script defining 'solutions', a list whose
10 # entries each are maps binding the strings "name" and "url" 10 # entries each are maps binding the strings "name" and "url"
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 self._used_scm.RunCommand('updatesingle', 634 self._used_scm.RunCommand('updatesingle',
635 options, args + [parsed_url.GetFilename()], file_list) 635 options, args + [parsed_url.GetFilename()], file_list)
636 else: 636 else:
637 # Create a shallow copy to mutate revision. 637 # Create a shallow copy to mutate revision.
638 options = copy.copy(options) 638 options = copy.copy(options)
639 options.revision = revision_overrides.get(self.name) 639 options.revision = revision_overrides.get(self.name)
640 self.maybeGetParentRevision( 640 self.maybeGetParentRevision(
641 command, options, parsed_url, self.parent.name, revision_overrides) 641 command, options, parsed_url, self.parent.name, revision_overrides)
642 self._used_scm = gclient_scm.CreateSCM( 642 self._used_scm = gclient_scm.CreateSCM(
643 parsed_url, self.root.root_dir, self.name) 643 parsed_url, self.root.root_dir, self.name)
644
645 # When updating, determine whether the destination directory contains a
646 # checkout of the desired repository. If not, avoid conflicts by
647 # deleting the directory before running the update.
648 if command == 'update':
649 actual_remote_url = self._used_scm.GetRemoteURL(options)
650 url, _ = gclient_utils.SplitUrlRevision(parsed_url)
651 dest_dir = os.path.join(self.root.root_dir, self.name)
652 if os.path.isdir(dest_dir) and actual_remote_url != url:
653 should_delete = options.force
654 if not should_delete:
655 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.
656 usr_input = None
657 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
658 usr_input = raw_input('%s does not contain a checkout of %s. '
659 'Do you want to delete the directory? '
660 'If not, the update will be canceled. '
661 '(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.
662 should_delete = (usr_input == 'y')
663 if should_delete:
664 logging.warning('%s does not contain a checkout of %s. Removing '
665 ' %s' % (dest_dir, url, dest_dir))
666 gclient_utils.rmtree(dest_dir)
667 else:
668 raise gclient_utils.Error('%s does not contain a checkout of %s. '
669 'Please fix the solution manually or '
670 'run with --force to delete '
671 'automatically.' % (dest_dir, url))
672
644 self._got_revision = self._used_scm.RunCommand(command, options, args, 673 self._got_revision = self._used_scm.RunCommand(command, options, args,
645 file_list) 674 file_list)
646 if file_list: 675 if file_list:
647 file_list = [os.path.join(self.name, f.strip()) for f in file_list] 676 file_list = [os.path.join(self.name, f.strip()) for f in file_list]
648 677
649 # TODO(phajdan.jr): We should know exactly when the paths are absolute. 678 # TODO(phajdan.jr): We should know exactly when the paths are absolute.
650 # Convert all absolute paths to relative. 679 # Convert all absolute paths to relative.
651 for i in range(len(file_list or [])): 680 for i in range(len(file_list or [])):
652 # It depends on the command being executed (like runhooks vs sync). 681 # It depends on the command being executed (like runhooks vs sync).
653 if not os.path.isabs(file_list[i]): 682 if not os.path.isabs(file_list[i]):
(...skipping 1235 matching lines...) Expand 10 before | Expand all | Expand 10 after
1889 raise 1918 raise
1890 except (gclient_utils.Error, subprocess2.CalledProcessError), e: 1919 except (gclient_utils.Error, subprocess2.CalledProcessError), e:
1891 print >> sys.stderr, 'Error: %s' % str(e) 1920 print >> sys.stderr, 'Error: %s' % str(e)
1892 return 1 1921 return 1
1893 1922
1894 1923
1895 if '__main__' == __name__: 1924 if '__main__' == __name__:
1896 sys.exit(Main(sys.argv[1:])) 1925 sys.exit(Main(sys.argv[1:]))
1897 1926
1898 # vim: ts=2:sw=2:tw=80:et: 1927 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« no previous file with comments | « no previous file | gclient_scm.py » ('j') | gclient_scm.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698