OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Gclient-specific SCM-specific operations.""" | 5 """Gclient-specific SCM-specific operations.""" |
6 | 6 |
7 import logging | 7 import logging |
8 import os | 8 import os |
9 import posixpath | 9 import posixpath |
10 import re | 10 import re |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 if self._IsRebasing(): | 435 if self._IsRebasing(): |
436 raise gclient_utils.Error('\n____ %s%s\n' | 436 raise gclient_utils.Error('\n____ %s%s\n' |
437 '\nConflict while rebasing this branch.\n' | 437 '\nConflict while rebasing this branch.\n' |
438 'Fix the conflict and run gclient again.\n' | 438 'Fix the conflict and run gclient again.\n' |
439 'See man git-rebase for details.\n' | 439 'See man git-rebase for details.\n' |
440 % (self.relpath, rev_str)) | 440 % (self.relpath, rev_str)) |
441 | 441 |
442 if verbose: | 442 if verbose: |
443 print('Checked out revision %s' % self.revinfo(options, (), None)) | 443 print('Checked out revision %s' % self.revinfo(options, (), None)) |
444 | 444 |
| 445 # If --reset and --delete_unversioned_trees are specified, remove any |
| 446 # untracked directories. |
| 447 if options.reset and options.delete_unversioned_trees: |
| 448 # GIT.CaptureStatus() uses 'dit diff' to compare to a specific SHA1 (the |
| 449 # merge-base by default), so doesn't include untracked files. So we use |
| 450 # 'git ls-files --directory --others --exclude-standard' here directly. |
| 451 paths = scm.GIT.Capture( |
| 452 ['ls-files', '--directory', '--others', '--exclude-standard'], |
| 453 self.checkout_path) |
| 454 for path in (p for p in paths.splitlines() if p.endswith('/')): |
| 455 full_path = os.path.join(self.checkout_path, path) |
| 456 if not os.path.islink(full_path): |
| 457 print('\n_____ removing unversioned directory %s' % path) |
| 458 gclient_utils.RemoveDirectory(full_path) |
| 459 |
| 460 |
445 def revert(self, options, args, file_list): | 461 def revert(self, options, args, file_list): |
446 """Reverts local modifications. | 462 """Reverts local modifications. |
447 | 463 |
448 All reverted files will be appended to file_list. | 464 All reverted files will be appended to file_list. |
449 """ | 465 """ |
450 if not os.path.isdir(self.checkout_path): | 466 if not os.path.isdir(self.checkout_path): |
451 # revert won't work if the directory doesn't exist. It needs to | 467 # revert won't work if the directory doesn't exist. It needs to |
452 # checkout instead. | 468 # checkout instead. |
453 print('\n_____ %s is missing, synching instead' % self.relpath) | 469 print('\n_____ %s is missing, synching instead' % self.relpath) |
454 # Don't reuse the args. | 470 # Don't reuse the args. |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
915 to_info['Repository Root'], | 931 to_info['Repository Root'], |
916 self.relpath] | 932 self.relpath] |
917 self._Run(command, options, cwd=self._root_dir) | 933 self._Run(command, options, cwd=self._root_dir) |
918 from_info['URL'] = from_info['URL'].replace( | 934 from_info['URL'] = from_info['URL'].replace( |
919 from_info['Repository Root'], | 935 from_info['Repository Root'], |
920 to_info['Repository Root']) | 936 to_info['Repository Root']) |
921 else: | 937 else: |
922 if not options.force and not options.reset: | 938 if not options.force and not options.reset: |
923 # Look for local modifications but ignore unversioned files. | 939 # Look for local modifications but ignore unversioned files. |
924 for status in scm.SVN.CaptureStatus(None, self.checkout_path): | 940 for status in scm.SVN.CaptureStatus(None, self.checkout_path): |
925 if status[0] != '?': | 941 if status[0][0] != '?': |
926 raise gclient_utils.Error( | 942 raise gclient_utils.Error( |
927 ('Can\'t switch the checkout to %s; UUID don\'t match and ' | 943 ('Can\'t switch the checkout to %s; UUID don\'t match and ' |
928 'there is local changes in %s. Delete the directory and ' | 944 'there is local changes in %s. Delete the directory and ' |
929 'try again.') % (url, self.checkout_path)) | 945 'try again.') % (url, self.checkout_path)) |
930 # Ok delete it. | 946 # Ok delete it. |
931 print('\n_____ switching %s to a new checkout' % self.relpath) | 947 print('\n_____ switching %s to a new checkout' % self.relpath) |
932 gclient_utils.RemoveDirectory(self.checkout_path) | 948 gclient_utils.RemoveDirectory(self.checkout_path) |
933 # We need to checkout. | 949 # We need to checkout. |
934 command = ['checkout', url, self.checkout_path] | 950 command = ['checkout', url, self.checkout_path] |
935 command = self._AddAdditionalUpdateFlags(command, options, revision) | 951 command = self._AddAdditionalUpdateFlags(command, options, revision) |
936 self._RunAndGetFileList(command, options, file_list, self._root_dir) | 952 self._RunAndGetFileList(command, options, file_list, self._root_dir) |
937 return | 953 return |
938 | 954 |
939 # If the provided url has a revision number that matches the revision | 955 # If the provided url has a revision number that matches the revision |
940 # number of the existing directory, then we don't need to bother updating. | 956 # number of the existing directory, then we don't need to bother updating. |
941 if not options.force and str(from_info['Revision']) == revision: | 957 if not options.force and str(from_info['Revision']) == revision: |
942 if options.verbose or not forced_revision: | 958 if options.verbose or not forced_revision: |
943 print('\n_____ %s%s' % (self.relpath, rev_str)) | 959 print('\n_____ %s%s' % (self.relpath, rev_str)) |
944 return | 960 else: |
| 961 command = ['update', self.checkout_path] |
| 962 command = self._AddAdditionalUpdateFlags(command, options, revision) |
| 963 self._RunAndGetFileList(command, options, file_list, self._root_dir) |
945 | 964 |
946 command = ['update', self.checkout_path] | 965 # If --reset and --delete_unversioned_trees are specified, remove any |
947 command = self._AddAdditionalUpdateFlags(command, options, revision) | 966 # untracked files and directories. |
948 self._RunAndGetFileList(command, options, file_list, self._root_dir) | 967 if options.reset and options.delete_unversioned_trees: |
| 968 for status in scm.SVN.CaptureStatus(None, self.checkout_path): |
| 969 full_path = os.path.join(self.checkout_path, status[1]) |
| 970 if (status[0][0] == '?' |
| 971 and os.path.isdir(full_path) |
| 972 and not os.path.islink(full_path)): |
| 973 print('\n_____ removing unversioned directory %s' % status[1]) |
| 974 gclient_utils.RemoveDirectory(full_path) |
949 | 975 |
950 def updatesingle(self, options, args, file_list): | 976 def updatesingle(self, options, args, file_list): |
951 filename = args.pop() | 977 filename = args.pop() |
952 if scm.SVN.AssertVersion("1.5")[0]: | 978 if scm.SVN.AssertVersion("1.5")[0]: |
953 if not os.path.exists(os.path.join(self.checkout_path, '.svn')): | 979 if not os.path.exists(os.path.join(self.checkout_path, '.svn')): |
954 # Create an empty checkout and then update the one file we want. Future | 980 # Create an empty checkout and then update the one file we want. Future |
955 # operations will only apply to the one file we checked out. | 981 # operations will only apply to the one file we checked out. |
956 command = ["checkout", "--depth", "empty", self.url, self.checkout_path] | 982 command = ["checkout", "--depth", "empty", self.url, self.checkout_path] |
957 self._Run(command, options, cwd=self._root_dir) | 983 self._Run(command, options, cwd=self._root_dir) |
958 if os.path.exists(os.path.join(self.checkout_path, filename)): | 984 if os.path.exists(os.path.join(self.checkout_path, filename)): |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1101 new_command.append('--force') | 1127 new_command.append('--force') |
1102 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1128 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1103 new_command.extend(('--accept', 'theirs-conflict')) | 1129 new_command.extend(('--accept', 'theirs-conflict')) |
1104 elif options.manually_grab_svn_rev: | 1130 elif options.manually_grab_svn_rev: |
1105 new_command.append('--force') | 1131 new_command.append('--force') |
1106 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1132 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1107 new_command.extend(('--accept', 'postpone')) | 1133 new_command.extend(('--accept', 'postpone')) |
1108 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1134 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1109 new_command.extend(('--accept', 'postpone')) | 1135 new_command.extend(('--accept', 'postpone')) |
1110 return new_command | 1136 return new_command |
OLD | NEW |