Chromium Code Reviews| 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 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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(): | |
| 656 usr_input = None | |
| 657 print ('%s does not contain a checkout of %s. Do you want to ' | |
| 658 'delete it before attempting to update?' % (dest_dir, | |
| 659 url)) | |
| 660 while usr_input not in ('y', 'n'): | |
| 661 print 'Please type "y" or "n".' | |
| 662 usr_input = raw_input() | |
|
iannucci
2013/11/14 07:38:15
raw_input() takes a prompt, which would be a bit b
borenet
2013/11/14 18:31:21
Done.
| |
| 663 should_delete = (usr_input == 'y') | |
| 664 else: | |
| 665 logging.warning('%s does not contain a checkout of %s. Not ' | |
| 666 'attempting to remove automatically. Re-run ' | |
| 667 'with "--force" to automatically remove ' | |
| 668 'conflicting checkouts.' % (dest_dir, url)) | |
| 669 if should_delete: | |
| 670 logging.warning('%s does not contain a checkout of %s. Removing ' | |
| 671 ' %s' % (dest_dir, url, dest_dir)) | |
| 672 gclient_utils.rmtree(dest_dir) | |
| 673 | |
|
borenet
2013/11/13 19:12:24
I'd like to point out that this causes some strang
iannucci
2013/11/14 07:38:15
I'm inclined to just abort if we didn't end up del
borenet
2013/11/14 18:31:21
Sounds fine to me, but I think it might also be ok
iannucci
2013/11/14 18:45:25
Yeah, I agree, the thing is that the gclient solut
borenet
2013/11/15 13:46:48
SGTM. Changed to raise Error if the directory isn
| |
| 644 self._got_revision = self._used_scm.RunCommand(command, options, args, | 674 self._got_revision = self._used_scm.RunCommand(command, options, args, |
| 645 file_list) | 675 file_list) |
| 646 if file_list: | 676 if file_list: |
| 647 file_list = [os.path.join(self.name, f.strip()) for f in file_list] | 677 file_list = [os.path.join(self.name, f.strip()) for f in file_list] |
| 648 | 678 |
| 649 # TODO(phajdan.jr): We should know exactly when the paths are absolute. | 679 # TODO(phajdan.jr): We should know exactly when the paths are absolute. |
| 650 # Convert all absolute paths to relative. | 680 # Convert all absolute paths to relative. |
| 651 for i in range(len(file_list or [])): | 681 for i in range(len(file_list or [])): |
| 652 # It depends on the command being executed (like runhooks vs sync). | 682 # It depends on the command being executed (like runhooks vs sync). |
| 653 if not os.path.isabs(file_list[i]): | 683 if not os.path.isabs(file_list[i]): |
| (...skipping 1235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1889 raise | 1919 raise |
| 1890 except (gclient_utils.Error, subprocess2.CalledProcessError), e: | 1920 except (gclient_utils.Error, subprocess2.CalledProcessError), e: |
| 1891 print >> sys.stderr, 'Error: %s' % str(e) | 1921 print >> sys.stderr, 'Error: %s' % str(e) |
| 1892 return 1 | 1922 return 1 |
| 1893 | 1923 |
| 1894 | 1924 |
| 1895 if '__main__' == __name__: | 1925 if '__main__' == __name__: |
| 1896 sys.exit(Main(sys.argv[1:])) | 1926 sys.exit(Main(sys.argv[1:])) |
| 1897 | 1927 |
| 1898 # vim: ts=2:sw=2:tw=80:et: | 1928 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |