Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2011 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 --force and --delete_unversioned_trees are specified, remove any | |
| 446 # untracked directories. | |
| 447 if options.force 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 if paths: | |
|
M-A Ruel
2012/02/10 15:56:40
nit: Not necessary to do "if paths:", just this wi
| |
| 455 for path in paths.splitlines(): | |
| 456 if path.endswith('/'): | |
| 457 print('\n_____ removing unversioned directory %s' % path) | |
| 458 gclient_utils.RemoveDirectory(os.path.join(self.checkout_path, | |
| 459 path)) | |
| 460 | |
| 461 | |
| 445 def revert(self, options, args, file_list): | 462 def revert(self, options, args, file_list): |
| 446 """Reverts local modifications. | 463 """Reverts local modifications. |
| 447 | 464 |
| 448 All reverted files will be appended to file_list. | 465 All reverted files will be appended to file_list. |
| 449 """ | 466 """ |
| 450 if not os.path.isdir(self.checkout_path): | 467 if not os.path.isdir(self.checkout_path): |
| 451 # revert won't work if the directory doesn't exist. It needs to | 468 # revert won't work if the directory doesn't exist. It needs to |
| 452 # checkout instead. | 469 # checkout instead. |
| 453 print('\n_____ %s is missing, synching instead' % self.relpath) | 470 print('\n_____ %s is missing, synching instead' % self.relpath) |
| 454 # Don't reuse the args. | 471 # Don't reuse the args. |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 907 to_info['Repository Root'], | 924 to_info['Repository Root'], |
| 908 self.relpath] | 925 self.relpath] |
| 909 self._Run(command, options, cwd=self._root_dir) | 926 self._Run(command, options, cwd=self._root_dir) |
| 910 from_info['URL'] = from_info['URL'].replace( | 927 from_info['URL'] = from_info['URL'].replace( |
| 911 from_info['Repository Root'], | 928 from_info['Repository Root'], |
| 912 to_info['Repository Root']) | 929 to_info['Repository Root']) |
| 913 else: | 930 else: |
| 914 if not options.force and not options.reset: | 931 if not options.force and not options.reset: |
| 915 # Look for local modifications but ignore unversioned files. | 932 # Look for local modifications but ignore unversioned files. |
| 916 for status in scm.SVN.CaptureStatus(None, self.checkout_path): | 933 for status in scm.SVN.CaptureStatus(None, self.checkout_path): |
| 917 if status[0] != '?': | 934 if status[0][0] != '?': |
| 918 raise gclient_utils.Error( | 935 raise gclient_utils.Error( |
| 919 ('Can\'t switch the checkout to %s; UUID don\'t match and ' | 936 ('Can\'t switch the checkout to %s; UUID don\'t match and ' |
| 920 'there is local changes in %s. Delete the directory and ' | 937 'there is local changes in %s. Delete the directory and ' |
| 921 'try again.') % (url, self.checkout_path)) | 938 'try again.') % (url, self.checkout_path)) |
| 922 # Ok delete it. | 939 # Ok delete it. |
| 923 print('\n_____ switching %s to a new checkout' % self.relpath) | 940 print('\n_____ switching %s to a new checkout' % self.relpath) |
| 924 gclient_utils.RemoveDirectory(self.checkout_path) | 941 gclient_utils.RemoveDirectory(self.checkout_path) |
| 925 # We need to checkout. | 942 # We need to checkout. |
| 926 command = ['checkout', url, self.checkout_path] | 943 command = ['checkout', url, self.checkout_path] |
| 927 command = self._AddAdditionalUpdateFlags(command, options, revision) | 944 command = self._AddAdditionalUpdateFlags(command, options, revision) |
| 928 self._RunAndGetFileList(command, options, file_list, self._root_dir) | 945 self._RunAndGetFileList(command, options, file_list, self._root_dir) |
| 929 return | 946 return |
| 930 | 947 |
| 931 # If the provided url has a revision number that matches the revision | 948 # If the provided url has a revision number that matches the revision |
| 932 # number of the existing directory, then we don't need to bother updating. | 949 # number of the existing directory, then we don't need to bother updating. |
| 933 if not options.force and str(from_info['Revision']) == revision: | 950 if not options.force and str(from_info['Revision']) == revision: |
| 934 if options.verbose or not forced_revision: | 951 if options.verbose or not forced_revision: |
| 935 print('\n_____ %s%s' % (self.relpath, rev_str)) | 952 print('\n_____ %s%s' % (self.relpath, rev_str)) |
| 936 return | 953 return |
| 937 | 954 |
| 938 command = ['update', self.checkout_path] | 955 command = ['update', self.checkout_path] |
| 939 command = self._AddAdditionalUpdateFlags(command, options, revision) | 956 command = self._AddAdditionalUpdateFlags(command, options, revision) |
| 940 self._RunAndGetFileList(command, options, file_list, self._root_dir) | 957 self._RunAndGetFileList(command, options, file_list, self._root_dir) |
| 941 | 958 |
| 959 # If --force and --delete_unversioned_trees are specified, remove any | |
| 960 # untracked files and directories. | |
| 961 if options.force and options.delete_unversioned_trees: | |
| 962 for status in scm.SVN.CaptureStatus(None, self.checkout_path): | |
| 963 path = os.path.join(self.checkout_path, status[1]) | |
| 964 if (status[0][0] == '?' and os.path.isdir(path)): | |
| 965 print('\n_____ removing unversioned directory %s' % status[1]) | |
| 966 gclient_utils.RemoveDirectory(os.path.join(path)) | |
| 967 | |
| 942 def updatesingle(self, options, args, file_list): | 968 def updatesingle(self, options, args, file_list): |
| 943 filename = args.pop() | 969 filename = args.pop() |
| 944 if scm.SVN.AssertVersion("1.5")[0]: | 970 if scm.SVN.AssertVersion("1.5")[0]: |
| 945 if not os.path.exists(os.path.join(self.checkout_path, '.svn')): | 971 if not os.path.exists(os.path.join(self.checkout_path, '.svn')): |
| 946 # Create an empty checkout and then update the one file we want. Future | 972 # Create an empty checkout and then update the one file we want. Future |
| 947 # operations will only apply to the one file we checked out. | 973 # operations will only apply to the one file we checked out. |
| 948 command = ["checkout", "--depth", "empty", self.url, self.checkout_path] | 974 command = ["checkout", "--depth", "empty", self.url, self.checkout_path] |
| 949 self._Run(command, options, cwd=self._root_dir) | 975 self._Run(command, options, cwd=self._root_dir) |
| 950 if os.path.exists(os.path.join(self.checkout_path, filename)): | 976 if os.path.exists(os.path.join(self.checkout_path, filename)): |
| 951 os.remove(os.path.join(self.checkout_path, filename)) | 977 os.remove(os.path.join(self.checkout_path, filename)) |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1093 new_command.append('--force') | 1119 new_command.append('--force') |
| 1094 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1120 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
| 1095 new_command.extend(('--accept', 'theirs-conflict')) | 1121 new_command.extend(('--accept', 'theirs-conflict')) |
| 1096 elif options.manually_grab_svn_rev: | 1122 elif options.manually_grab_svn_rev: |
| 1097 new_command.append('--force') | 1123 new_command.append('--force') |
| 1098 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1124 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
| 1099 new_command.extend(('--accept', 'postpone')) | 1125 new_command.extend(('--accept', 'postpone')) |
| 1100 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1126 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
| 1101 new_command.extend(('--accept', 'postpone')) | 1127 new_command.extend(('--accept', 'postpone')) |
| 1102 return new_command | 1128 return new_command |
| OLD | NEW |