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

Side by Side Diff: gclient.py

Issue 133073015: Re-reland r245404 ("If the destination directory doesn't contain the desired repo, delete it") (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Clean up check_output call, print hostname on bots Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | gclient_scm.py » ('j') | no next file with comments »
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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 80
81 import copy 81 import copy
82 import json 82 import json
83 import logging 83 import logging
84 import optparse 84 import optparse
85 import os 85 import os
86 import platform 86 import platform
87 import posixpath 87 import posixpath
88 import pprint 88 import pprint
89 import re 89 import re
90 import socket
90 import sys 91 import sys
91 import time 92 import time
92 import urllib 93 import urllib
93 import urlparse 94 import urlparse
94 95
95 import breakpad # pylint: disable=W0611 96 import breakpad # pylint: disable=W0611
96 97
97 import fix_encoding 98 import fix_encoding
98 import gclient_scm 99 import gclient_scm
99 import gclient_utils 100 import gclient_utils
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 self._used_scm.RunCommand('updatesingle', 662 self._used_scm.RunCommand('updatesingle',
662 options, args + [parsed_url.GetFilename()], file_list) 663 options, args + [parsed_url.GetFilename()], file_list)
663 else: 664 else:
664 # Create a shallow copy to mutate revision. 665 # Create a shallow copy to mutate revision.
665 options = copy.copy(options) 666 options = copy.copy(options)
666 options.revision = revision_overrides.get(self.name) 667 options.revision = revision_overrides.get(self.name)
667 self.maybeGetParentRevision( 668 self.maybeGetParentRevision(
668 command, options, parsed_url, self.parent.name, revision_overrides) 669 command, options, parsed_url, self.parent.name, revision_overrides)
669 self._used_scm = gclient_scm.CreateSCM( 670 self._used_scm = gclient_scm.CreateSCM(
670 parsed_url, self.root.root_dir, self.name) 671 parsed_url, self.root.root_dir, self.name)
672
673 def enable_deletion_of_conflicting_checkouts():
674 """Determines whether to enable new checkout deletion behavior.
675
676 Initially, enables the experimental functionality on a small set of
677 bots.
678 """
679 # TODO(borenet): Remove this hack as soon as we've verified that it
680 # doesn't cause the bots to break.
681 if not os.environ.get('CHROME_HEADLESS'):
682 return False
683 hostname = socket.gethostname()
684 logging.warning('Hostname of this machine: %s' % hostname)
685 return hostname in ('vm859-m1', 'build1-m1', 'vm630-m1')
686
687 # When updating, determine whether the destination directory contains a
688 # checkout of the desired repository. If not, avoid conflicts by
689 # deleting the directory before running the update.
690 if command == 'update' and enable_deletion_of_conflicting_checkouts():
691 logging.warning('Experimental deletion of mismatching checkouts '
692 'enabled.')
693 actual_remote_url = self._used_scm.GetRemoteURL(options)
694 url, _ = gclient_utils.SplitUrlRevision(parsed_url)
695 url = url.rstrip('/')
696 dest_dir = os.path.join(self.root.root_dir, self.name)
697 if os.path.isdir(dest_dir) and actual_remote_url != url:
698 if options.force:
699 logging.warning('%s does not contain a checkout of %s. Removing '
700 ' %s' % (dest_dir, url, dest_dir))
701 gclient_utils.rmtree(dest_dir)
702 else:
703 raise gclient_utils.Error('%s does not contain a checkout of %s '
704 '(found %s instead). Please fix the '
705 'solution manually or run with --force '
706 'to delete automatically.' % (
707 dest_dir, url, actual_remote_url))
708
671 self._got_revision = self._used_scm.RunCommand(command, options, args, 709 self._got_revision = self._used_scm.RunCommand(command, options, args,
672 file_list) 710 file_list)
673 if file_list: 711 if file_list:
674 file_list = [os.path.join(self.name, f.strip()) for f in file_list] 712 file_list = [os.path.join(self.name, f.strip()) for f in file_list]
675 713
676 # TODO(phajdan.jr): We should know exactly when the paths are absolute. 714 # TODO(phajdan.jr): We should know exactly when the paths are absolute.
677 # Convert all absolute paths to relative. 715 # Convert all absolute paths to relative.
678 for i in range(len(file_list or [])): 716 for i in range(len(file_list or [])):
679 # It depends on the command being executed (like runhooks vs sync). 717 # It depends on the command being executed (like runhooks vs sync).
680 if not os.path.isabs(file_list[i]): 718 if not os.path.isabs(file_list[i]):
(...skipping 1238 matching lines...) Expand 10 before | Expand all | Expand 10 after
1919 raise 1957 raise
1920 except (gclient_utils.Error, subprocess2.CalledProcessError), e: 1958 except (gclient_utils.Error, subprocess2.CalledProcessError), e:
1921 print >> sys.stderr, 'Error: %s' % str(e) 1959 print >> sys.stderr, 'Error: %s' % str(e)
1922 return 1 1960 return 1
1923 1961
1924 1962
1925 if '__main__' == __name__: 1963 if '__main__' == __name__:
1926 sys.exit(Main(sys.argv[1:])) 1964 sys.exit(Main(sys.argv[1:]))
1927 1965
1928 # vim: ts=2:sw=2:tw=80:et: 1966 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« no previous file with comments | « no previous file | gclient_scm.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698