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

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: Address comments from meeting (first upload failed) Created 7 years 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 # TODO(borenet): Only enabling this on a few bots at first.
649 import socket
650 if (command == 'update' and
651 socket.gethostname() in ('vm859-m1', 'build1-m1', 'vm630-m1')):
652 logging.warning('Experimental deletion of mismatching checkouts '
653 '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.
654 actual_remote_url = self._used_scm.GetRemoteURL(options)
655 url, _ = gclient_utils.SplitUrlRevision(parsed_url)
656 url = url.rstrip('/')
657 dest_dir = os.path.join(self.root.root_dir, self.name)
658 if os.path.isdir(dest_dir) and actual_remote_url != url:
659 should_delete = options.force or os.environ.get('CHROME_HEADLESS')
660 if sys.__stdout__.isatty() and not should_delete:
661 usr_input = ''
662 while usr_input not in ('y', 'n'):
663 usr_input = raw_input('%s does not contain a checkout of %s. '
664 'Do you want to delete the directory? '
665 'If not, the update will be canceled '
666 '(y/n): ' % (dest_dir, url)).lower()
667 should_delete = (usr_input == 'y')
668 if should_delete:
669 logging.warning('%s does not contain a checkout of %s. Removing '
670 ' %s' % (dest_dir, url, dest_dir))
671 gclient_utils.rmtree(dest_dir)
672 else:
673 raise gclient_utils.Error('%s does not contain a checkout of %s. '
674 'Please fix the solution manually or '
675 'run with --force to delete '
676 'automatically.' % (dest_dir, url))
677
644 self._got_revision = self._used_scm.RunCommand(command, options, args, 678 self._got_revision = self._used_scm.RunCommand(command, options, args,
645 file_list) 679 file_list)
646 if file_list: 680 if file_list:
647 file_list = [os.path.join(self.name, f.strip()) for f in file_list] 681 file_list = [os.path.join(self.name, f.strip()) for f in file_list]
648 682
649 # TODO(phajdan.jr): We should know exactly when the paths are absolute. 683 # TODO(phajdan.jr): We should know exactly when the paths are absolute.
650 # Convert all absolute paths to relative. 684 # Convert all absolute paths to relative.
651 for i in range(len(file_list or [])): 685 for i in range(len(file_list or [])):
652 # It depends on the command being executed (like runhooks vs sync). 686 # It depends on the command being executed (like runhooks vs sync).
653 if not os.path.isabs(file_list[i]): 687 if not os.path.isabs(file_list[i]):
(...skipping 1235 matching lines...) Expand 10 before | Expand all | Expand 10 after
1889 raise 1923 raise
1890 except (gclient_utils.Error, subprocess2.CalledProcessError), e: 1924 except (gclient_utils.Error, subprocess2.CalledProcessError), e:
1891 print >> sys.stderr, 'Error: %s' % str(e) 1925 print >> sys.stderr, 'Error: %s' % str(e)
1892 return 1 1926 return 1
1893 1927
1894 1928
1895 if '__main__' == __name__: 1929 if '__main__' == __name__:
1896 sys.exit(Main(sys.argv[1:])) 1930 sys.exit(Main(sys.argv[1:]))
1897 1931
1898 # vim: ts=2:sw=2:tw=80:et: 1932 # 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