OLD | NEW |
---|---|
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 Loading... | |
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 def enable_deletion_of_conflicting_checkouts(): | |
673 """This function determines whether the new behavior of deleting | |
M-A Ruel
2014/01/13 17:31:39
"""Determines ..
borenet
2014/01/13 18:17:57
Done.
| |
674 checkouts which conflict with those in DEPS should be enabled. It | |
M-A Ruel
2014/01/13 17:31:39
Empty line between one liner summary and detailed
borenet
2014/01/13 18:17:57
Done.
| |
675 enables the new functionality on a small set of bots initially.""" | |
676 # TODO(borenet): Remove this hack as soon as we've verified that it | |
677 # doesn't cause the bots to break. | |
678 import socket | |
M-A Ruel
2014/01/13 17:31:39
I'd prefer the import at the top of the file. Even
borenet
2014/01/13 18:17:57
Done.
| |
679 return (socket.gethostname() in ('vm859-m1', 'build1-m1', 'vm630-m1') | |
680 and os.environ.get('CHROME_HEADLESS')) | |
M-A Ruel
2014/01/13 17:31:39
You should inverse the check. Checking for os.envi
borenet
2014/01/13 18:17:57
Done.
| |
681 | |
682 def should_delete_conflicting_checkout(options): | |
683 """Determine whether a checkout which conflicts with the DEPS entry | |
M-A Ruel
2014/01/13 17:31:39
imperactive
| |
684 should be deleted. Returns True if running with --force or when | |
M-A Ruel
2014/01/13 17:31:39
empty line
| |
685 running on a bot. Otherwise, prompts for deletion.""" | |
686 should_delete = options.force or os.environ.get('CHROME_HEADLESS') | |
M-A Ruel
2014/01/13 17:31:39
Do not use an environment variable to determine th
| |
687 if sys.__stdout__.isatty() and not should_delete: | |
688 usr_input = '' | |
689 while usr_input not in ('y', 'n'): | |
690 usr_input = raw_input('%s does not contain a checkout of %s. ' | |
691 'Do you want to delete the directory? ' | |
692 'If not, the update will be canceled ' | |
693 '(y/n): ' % (dest_dir, url)).lower() | |
694 should_delete = (usr_input == 'y') | |
695 return should_delete | |
696 | |
697 # When updating, determine whether the destination directory contains a | |
698 # checkout of the desired repository. If not, avoid conflicts by | |
699 # deleting the directory before running the update. | |
700 if (command == 'update' and enable_deletion_of_conflicting_checkouts()): | |
M-A Ruel
2014/01/13 17:31:39
() are not needed
borenet
2014/01/13 18:17:57
Done.
| |
701 logging.warning('Experimental deletion of mismatching checkouts ' | |
702 'enabled.') | |
703 actual_remote_url = self._used_scm.GetRemoteURL(options) | |
704 url, _ = gclient_utils.SplitUrlRevision(parsed_url) | |
705 url = url.rstrip('/') | |
706 dest_dir = os.path.join(self.root.root_dir, self.name) | |
707 if os.path.isdir(dest_dir) and actual_remote_url != url: | |
708 if should_delete_conflicting_checkout(options): | |
709 logging.warning('%s does not contain a checkout of %s. Removing ' | |
710 ' %s' % (dest_dir, url, dest_dir)) | |
711 gclient_utils.rmtree(dest_dir) | |
712 else: | |
713 raise gclient_utils.Error('%s does not contain a checkout of %s. ' | |
714 'Please fix the solution manually or ' | |
715 'run with --force to delete ' | |
716 'automatically.' % (dest_dir, url)) | |
717 | |
671 self._got_revision = self._used_scm.RunCommand(command, options, args, | 718 self._got_revision = self._used_scm.RunCommand(command, options, args, |
672 file_list) | 719 file_list) |
673 if file_list: | 720 if file_list: |
674 file_list = [os.path.join(self.name, f.strip()) for f in file_list] | 721 file_list = [os.path.join(self.name, f.strip()) for f in file_list] |
675 | 722 |
676 # TODO(phajdan.jr): We should know exactly when the paths are absolute. | 723 # TODO(phajdan.jr): We should know exactly when the paths are absolute. |
677 # Convert all absolute paths to relative. | 724 # Convert all absolute paths to relative. |
678 for i in range(len(file_list or [])): | 725 for i in range(len(file_list or [])): |
679 # It depends on the command being executed (like runhooks vs sync). | 726 # It depends on the command being executed (like runhooks vs sync). |
680 if not os.path.isabs(file_list[i]): | 727 if not os.path.isabs(file_list[i]): |
(...skipping 1235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1916 raise | 1963 raise |
1917 except (gclient_utils.Error, subprocess2.CalledProcessError), e: | 1964 except (gclient_utils.Error, subprocess2.CalledProcessError), e: |
1918 print >> sys.stderr, 'Error: %s' % str(e) | 1965 print >> sys.stderr, 'Error: %s' % str(e) |
1919 return 1 | 1966 return 1 |
1920 | 1967 |
1921 | 1968 |
1922 if '__main__' == __name__: | 1969 if '__main__' == __name__: |
1923 sys.exit(Main(sys.argv[1:])) | 1970 sys.exit(Main(sys.argv[1:])) |
1924 | 1971 |
1925 # vim: ts=2:sw=2:tw=80:et: | 1972 # vim: ts=2:sw=2:tw=80:et: |
OLD | NEW |