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

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: Rebase, fix conflicts, remove unused variable Created 6 years, 11 months 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 650 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 self._used_scm.RunCommand('updatesingle', 661 self._used_scm.RunCommand('updatesingle',
662 options, args + [parsed_url.GetFilename()], file_list) 662 options, args + [parsed_url.GetFilename()], file_list)
663 else: 663 else:
664 # Create a shallow copy to mutate revision. 664 # Create a shallow copy to mutate revision.
665 options = copy.copy(options) 665 options = copy.copy(options)
666 options.revision = revision_overrides.get(self.name) 666 options.revision = revision_overrides.get(self.name)
667 self.maybeGetParentRevision( 667 self.maybeGetParentRevision(
668 command, options, parsed_url, self.parent.name, revision_overrides) 668 command, options, parsed_url, self.parent.name, revision_overrides)
669 self._used_scm = gclient_scm.CreateSCM( 669 self._used_scm = gclient_scm.CreateSCM(
670 parsed_url, self.root.root_dir, self.name) 670 parsed_url, self.root.root_dir, self.name)
671
672 # When updating, determine whether the destination directory contains a
673 # checkout of the desired repository. If not, avoid conflicts by
674 # deleting the directory before running the update.
675 # TODO(borenet): Only enabling this on a few bots at first.
676 import socket
677 if (command == 'update' and
678 socket.gethostname() in ('vm859-m1', 'build1-m1', 'vm630-m1') and
M-A Ruel 2014/01/10 16:41:47 Extract this in a function. I highly dislike this,
borenet 2014/01/10 19:27:23 Done. When this is submitted, I will submit a try
679 os.environ.get('CHROME_HEADLESS')):
680 logging.warning('Experimental deletion of mismatching checkouts '
681 'enabled.')
682 actual_remote_url = self._used_scm.GetRemoteURL(options)
683 url, _ = gclient_utils.SplitUrlRevision(parsed_url)
684 url = url.rstrip('/')
685 dest_dir = os.path.join(self.root.root_dir, self.name)
686 if os.path.isdir(dest_dir) and actual_remote_url != url:
687 should_delete = options.force or os.environ.get('CHROME_HEADLESS')
688 if sys.__stdout__.isatty() and not should_delete:
M-A Ruel 2014/01/10 16:41:47 Move the check/prompt into a function. This should
borenet 2014/01/10 19:27:23 Done. The prompt is not displayed with --force.
M-A Ruel 2014/01/13 17:31:38 Yes, I prefer failing to prompting. Prompting the
borenet 2014/01/13 18:17:57 Done.
689 usr_input = ''
690 while usr_input not in ('y', 'n'):
691 usr_input = raw_input('%s does not contain a checkout of %s. '
692 'Do you want to delete the directory? '
693 'If not, the update will be canceled '
694 '(y/n): ' % (dest_dir, url)).lower()
695 should_delete = (usr_input == 'y')
696 if should_delete:
697 logging.warning('%s does not contain a checkout of %s. Removing '
698 ' %s' % (dest_dir, url, dest_dir))
699 gclient_utils.rmtree(dest_dir)
700 else:
701 raise gclient_utils.Error('%s does not contain a checkout of %s. '
702 'Please fix the solution manually or '
703 'run with --force to delete '
704 'automatically.' % (dest_dir, url))
705
671 self._got_revision = self._used_scm.RunCommand(command, options, args, 706 self._got_revision = self._used_scm.RunCommand(command, options, args,
672 file_list) 707 file_list)
673 if file_list: 708 if file_list:
674 file_list = [os.path.join(self.name, f.strip()) for f in file_list] 709 file_list = [os.path.join(self.name, f.strip()) for f in file_list]
675 710
676 # TODO(phajdan.jr): We should know exactly when the paths are absolute. 711 # TODO(phajdan.jr): We should know exactly when the paths are absolute.
677 # Convert all absolute paths to relative. 712 # Convert all absolute paths to relative.
678 for i in range(len(file_list or [])): 713 for i in range(len(file_list or [])):
679 # It depends on the command being executed (like runhooks vs sync). 714 # It depends on the command being executed (like runhooks vs sync).
680 if not os.path.isabs(file_list[i]): 715 if not os.path.isabs(file_list[i]):
(...skipping 1235 matching lines...) Expand 10 before | Expand all | Expand 10 after
1916 raise 1951 raise
1917 except (gclient_utils.Error, subprocess2.CalledProcessError), e: 1952 except (gclient_utils.Error, subprocess2.CalledProcessError), e:
1918 print >> sys.stderr, 'Error: %s' % str(e) 1953 print >> sys.stderr, 'Error: %s' % str(e)
1919 return 1 1954 return 1
1920 1955
1921 1956
1922 if '__main__' == __name__: 1957 if '__main__' == __name__:
1923 sys.exit(Main(sys.argv[1:])) 1958 sys.exit(Main(sys.argv[1:]))
1924 1959
1925 # vim: ts=2:sw=2:tw=80:et: 1960 # 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