OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # | 2 # |
3 # Copyright 2008 Google Inc. All Rights Reserved. | 3 # Copyright 2008 Google Inc. All Rights Reserved. |
4 # | 4 # |
5 # Licensed under the Apache License, Version 2.0 (the "License"); | 5 # Licensed under the Apache License, Version 2.0 (the "License"); |
6 # you may not use this file except in compliance with the License. | 6 # you may not use this file except in compliance with the License. |
7 # You may obtain a copy of the License at | 7 # You may obtain a copy of the License at |
8 # | 8 # |
9 # http://www.apache.org/licenses/LICENSE-2.0 | 9 # http://www.apache.org/licenses/LICENSE-2.0 |
10 # | 10 # |
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 | 745 |
746 def update(self, options, args, file_list): | 746 def update(self, options, args, file_list): |
747 """Runs SCM to update or transparently checkout the working copy. | 747 """Runs SCM to update or transparently checkout the working copy. |
748 | 748 |
749 All updated files will be appended to file_list. | 749 All updated files will be appended to file_list. |
750 | 750 |
751 Raises: | 751 Raises: |
752 Error: if can't get URL for relative path. | 752 Error: if can't get URL for relative path. |
753 """ | 753 """ |
754 # Only update if git is not controlling the directory. | 754 # Only update if git is not controlling the directory. |
755 git_path = os.path.join(self._root_dir, self.relpath, '.git') | 755 checkout_path = os.path.join(self._root_dir, self.relpath) |
| 756 git_path = os.path.join(checkout_path, '.git') |
756 if options.path_exists(git_path): | 757 if options.path_exists(git_path): |
757 print("________ found .git directory; skipping %s" % self.relpath) | 758 print("________ found .git directory; skipping %s" % self.relpath) |
758 return | 759 return |
759 | 760 |
760 if args: | 761 if args: |
761 raise Error("Unsupported argument(s): %s" % ",".join(args)) | 762 raise Error("Unsupported argument(s): %s" % ",".join(args)) |
762 | 763 |
763 url = self.url | 764 url = self.url |
764 components = url.split("@") | 765 components = url.split("@") |
765 revision = None | 766 revision = None |
766 forced_revision = False | 767 forced_revision = False |
767 if options.revision: | 768 if options.revision: |
768 # Override the revision number. | 769 # Override the revision number. |
769 url = '%s@%s' % (components[0], str(options.revision)) | 770 url = '%s@%s' % (components[0], str(options.revision)) |
770 revision = int(options.revision) | 771 revision = int(options.revision) |
771 forced_revision = True | 772 forced_revision = True |
772 elif len(components) == 2: | 773 elif len(components) == 2: |
773 revision = int(components[1]) | 774 revision = int(components[1]) |
774 forced_revision = True | 775 forced_revision = True |
775 | 776 |
776 rev_str = "" | 777 rev_str = "" |
777 if revision: | 778 if revision: |
778 rev_str = ' at %d' % revision | 779 rev_str = ' at %d' % revision |
779 | 780 |
780 if not options.path_exists(os.path.join(self._root_dir, self.relpath)): | 781 if not options.path_exists(checkout_path): |
781 # We need to checkout. | 782 # We need to checkout. |
782 command = ['checkout', url, os.path.join(self._root_dir, self.relpath)] | 783 command = ['checkout', url, checkout_path] |
783 if revision: | 784 if revision: |
784 command.extend(['--revision', str(revision)]) | 785 command.extend(['--revision', str(revision)]) |
785 RunSVNAndGetFileList(command, self._root_dir, file_list) | 786 RunSVNAndGetFileList(command, self._root_dir, file_list) |
786 return | 787 return |
787 | 788 |
788 # Get the existing scm url and the revision number of the current checkout. | 789 # Get the existing scm url and the revision number of the current checkout. |
789 from_info = CaptureSVNInfo(os.path.join(self._root_dir, self.relpath, '.'), | 790 from_info = CaptureSVNInfo(os.path.join(checkout_path, '.'), '.') |
790 '.') | |
791 | 791 |
792 if options.manually_grab_svn_rev: | 792 if options.manually_grab_svn_rev: |
793 # Retrieve the current HEAD version because svn is slow at null updates. | 793 # Retrieve the current HEAD version because svn is slow at null updates. |
794 if not revision: | 794 if not revision: |
795 from_info_live = CaptureSVNInfo(from_info['URL'], '.') | 795 from_info_live = CaptureSVNInfo(from_info['URL'], '.') |
796 revision = int(from_info_live['Revision']) | 796 revision = int(from_info_live['Revision']) |
797 rev_str = ' at %d' % revision | 797 rev_str = ' at %d' % revision |
798 | 798 |
799 if from_info['URL'] != components[0]: | 799 if from_info['URL'] != components[0]: |
800 to_info = CaptureSVNInfo(url, '.') | 800 to_info = CaptureSVNInfo(url, '.') |
801 if from_info['Repository Root'] != to_info['Repository Root']: | 801 can_switch = ((from_info['Repository Root'] != to_info['Repository Root']) |
| 802 and (from_info['UUID'] == to_info['UUID'])) |
| 803 if can_switch: |
| 804 print("\n_____ relocating %s to a new checkout" % self.relpath) |
802 # We have different roots, so check if we can switch --relocate. | 805 # We have different roots, so check if we can switch --relocate. |
803 # Subversion only permits this if the repository UUIDs match. | 806 # Subversion only permits this if the repository UUIDs match. |
804 if from_info['UUID'] != to_info['UUID']: | |
805 raise Error("Can't switch the checkout to %s; UUID don't match. That " | |
806 "simply means in theory, gclient should verify you don't " | |
807 "have a local change, remove the old checkout and do a " | |
808 "fresh new checkout of the new repo. Contributions are " | |
809 "welcome." % url) | |
810 | |
811 # Perform the switch --relocate, then rewrite the from_url | 807 # Perform the switch --relocate, then rewrite the from_url |
812 # to reflect where we "are now." (This is the same way that | 808 # to reflect where we "are now." (This is the same way that |
813 # Subversion itself handles the metadata when switch --relocate | 809 # Subversion itself handles the metadata when switch --relocate |
814 # is used.) This makes the checks below for whether we | 810 # is used.) This makes the checks below for whether we |
815 # can update to a revision or have to switch to a different | 811 # can update to a revision or have to switch to a different |
816 # branch work as expected. | 812 # branch work as expected. |
817 # TODO(maruel): TEST ME ! | 813 # TODO(maruel): TEST ME ! |
818 command = ["switch", "--relocate", | 814 command = ["switch", "--relocate", |
819 from_info['Repository Root'], | 815 from_info['Repository Root'], |
820 to_info['Repository Root'], | 816 to_info['Repository Root'], |
821 self.relpath] | 817 self.relpath] |
822 RunSVN(command, self._root_dir) | 818 RunSVN(command, self._root_dir) |
823 from_info['URL'] = from_info['URL'].replace( | 819 from_info['URL'] = from_info['URL'].replace( |
824 from_info['Repository Root'], | 820 from_info['Repository Root'], |
825 to_info['Repository Root']) | 821 to_info['Repository Root']) |
| 822 else: |
| 823 if CaptureSVNStatus(checkout_path): |
| 824 raise Error("Can't switch the checkout to %s; UUID don't match and " |
| 825 "there is local changes in %s. Delete the directory and " |
| 826 "try again." % (url, checkout_path)) |
| 827 # Ok delete it. |
| 828 print("\n_____ switching %s to a new checkout" % self.relpath) |
| 829 RemoveDirectory(checkout_path) |
| 830 # We need to checkout. |
| 831 command = ['checkout', url, checkout_path] |
| 832 if revision: |
| 833 command.extend(['--revision', str(revision)]) |
| 834 RunSVNAndGetFileList(command, self._root_dir, file_list) |
| 835 return |
| 836 |
826 | 837 |
827 # If the provided url has a revision number that matches the revision | 838 # If the provided url has a revision number that matches the revision |
828 # number of the existing directory, then we don't need to bother updating. | 839 # number of the existing directory, then we don't need to bother updating. |
829 if not options.force and from_info['Revision'] == revision: | 840 if not options.force and from_info['Revision'] == revision: |
830 if options.verbose or not forced_revision: | 841 if options.verbose or not forced_revision: |
831 print("\n_____ %s%s" % (self.relpath, rev_str)) | 842 print("\n_____ %s%s" % (self.relpath, rev_str)) |
832 return | 843 return |
833 | 844 |
834 command = ["update", os.path.join(self._root_dir, self.relpath)] | 845 command = ["update", checkout_path] |
835 if revision: | 846 if revision: |
836 command.extend(['--revision', str(revision)]) | 847 command.extend(['--revision', str(revision)]) |
837 RunSVNAndGetFileList(command, self._root_dir, file_list) | 848 RunSVNAndGetFileList(command, self._root_dir, file_list) |
838 | 849 |
839 def revert(self, options, args, file_list): | 850 def revert(self, options, args, file_list): |
840 """Reverts local modifications. Subversion specific. | 851 """Reverts local modifications. Subversion specific. |
841 | 852 |
842 All reverted files will be appended to file_list, even if Subversion | 853 All reverted files will be appended to file_list, even if Subversion |
843 doesn't know about them. | 854 doesn't know about them. |
844 """ | 855 """ |
(...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1711 | 1722 |
1712 if "__main__" == __name__: | 1723 if "__main__" == __name__: |
1713 try: | 1724 try: |
1714 result = Main(sys.argv) | 1725 result = Main(sys.argv) |
1715 except Error, e: | 1726 except Error, e: |
1716 print >> sys.stderr, "Error: %s" % str(e) | 1727 print >> sys.stderr, "Error: %s" % str(e) |
1717 result = 1 | 1728 result = 1 |
1718 sys.exit(result) | 1729 sys.exit(result) |
1719 | 1730 |
1720 # vim: ts=2:sw=2:tw=80:et: | 1731 # vim: ts=2:sw=2:tw=80:et: |
OLD | NEW |