Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(678)

Side by Side Diff: gclient_scm.py

Issue 9348054: If --force is specified when updating, remove unversioned directories (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools/
Patch Set: If both -f and -D are specified when updating, remove all untracked directories Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gclient.py ('k') | tests/gclient_scm_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 for path in (p for p in paths.splitlines() if p.endswith('/')):
455 print('\n_____ removing unversioned directory %s' % path)
456 gclient_utils.RemoveDirectory(os.path.join(self.checkout_path, path))
457
458
445 def revert(self, options, args, file_list): 459 def revert(self, options, args, file_list):
446 """Reverts local modifications. 460 """Reverts local modifications.
447 461
448 All reverted files will be appended to file_list. 462 All reverted files will be appended to file_list.
449 """ 463 """
450 if not os.path.isdir(self.checkout_path): 464 if not os.path.isdir(self.checkout_path):
451 # revert won't work if the directory doesn't exist. It needs to 465 # revert won't work if the directory doesn't exist. It needs to
452 # checkout instead. 466 # checkout instead.
453 print('\n_____ %s is missing, synching instead' % self.relpath) 467 print('\n_____ %s is missing, synching instead' % self.relpath)
454 # Don't reuse the args. 468 # Don't reuse the args.
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 to_info['Repository Root'], 921 to_info['Repository Root'],
908 self.relpath] 922 self.relpath]
909 self._Run(command, options, cwd=self._root_dir) 923 self._Run(command, options, cwd=self._root_dir)
910 from_info['URL'] = from_info['URL'].replace( 924 from_info['URL'] = from_info['URL'].replace(
911 from_info['Repository Root'], 925 from_info['Repository Root'],
912 to_info['Repository Root']) 926 to_info['Repository Root'])
913 else: 927 else:
914 if not options.force and not options.reset: 928 if not options.force and not options.reset:
915 # Look for local modifications but ignore unversioned files. 929 # Look for local modifications but ignore unversioned files.
916 for status in scm.SVN.CaptureStatus(None, self.checkout_path): 930 for status in scm.SVN.CaptureStatus(None, self.checkout_path):
917 if status[0] != '?': 931 if status[0][0] != '?':
918 raise gclient_utils.Error( 932 raise gclient_utils.Error(
919 ('Can\'t switch the checkout to %s; UUID don\'t match and ' 933 ('Can\'t switch the checkout to %s; UUID don\'t match and '
920 'there is local changes in %s. Delete the directory and ' 934 'there is local changes in %s. Delete the directory and '
921 'try again.') % (url, self.checkout_path)) 935 'try again.') % (url, self.checkout_path))
922 # Ok delete it. 936 # Ok delete it.
923 print('\n_____ switching %s to a new checkout' % self.relpath) 937 print('\n_____ switching %s to a new checkout' % self.relpath)
924 gclient_utils.RemoveDirectory(self.checkout_path) 938 gclient_utils.RemoveDirectory(self.checkout_path)
925 # We need to checkout. 939 # We need to checkout.
926 command = ['checkout', url, self.checkout_path] 940 command = ['checkout', url, self.checkout_path]
927 command = self._AddAdditionalUpdateFlags(command, options, revision) 941 command = self._AddAdditionalUpdateFlags(command, options, revision)
928 self._RunAndGetFileList(command, options, file_list, self._root_dir) 942 self._RunAndGetFileList(command, options, file_list, self._root_dir)
929 return 943 return
930 944
931 # If the provided url has a revision number that matches the revision 945 # 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. 946 # number of the existing directory, then we don't need to bother updating.
933 if not options.force and str(from_info['Revision']) == revision: 947 if not options.force and str(from_info['Revision']) == revision:
934 if options.verbose or not forced_revision: 948 if options.verbose or not forced_revision:
935 print('\n_____ %s%s' % (self.relpath, rev_str)) 949 print('\n_____ %s%s' % (self.relpath, rev_str))
936 return 950 return
937 951
938 command = ['update', self.checkout_path] 952 command = ['update', self.checkout_path]
939 command = self._AddAdditionalUpdateFlags(command, options, revision) 953 command = self._AddAdditionalUpdateFlags(command, options, revision)
940 self._RunAndGetFileList(command, options, file_list, self._root_dir) 954 self._RunAndGetFileList(command, options, file_list, self._root_dir)
941 955
956 # If --force and --delete_unversioned_trees are specified, remove any
957 # untracked files and directories.
958 if options.force and options.delete_unversioned_trees:
959 for status in scm.SVN.CaptureStatus(None, self.checkout_path):
960 path = os.path.join(self.checkout_path, status[1])
961 if (status[0][0] == '?' and os.path.isdir(path)):
962 print('\n_____ removing unversioned directory %s' % status[1])
963 gclient_utils.RemoveDirectory(os.path.join(path))
964
942 def updatesingle(self, options, args, file_list): 965 def updatesingle(self, options, args, file_list):
943 filename = args.pop() 966 filename = args.pop()
944 if scm.SVN.AssertVersion("1.5")[0]: 967 if scm.SVN.AssertVersion("1.5")[0]:
945 if not os.path.exists(os.path.join(self.checkout_path, '.svn')): 968 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 969 # 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. 970 # operations will only apply to the one file we checked out.
948 command = ["checkout", "--depth", "empty", self.url, self.checkout_path] 971 command = ["checkout", "--depth", "empty", self.url, self.checkout_path]
949 self._Run(command, options, cwd=self._root_dir) 972 self._Run(command, options, cwd=self._root_dir)
950 if os.path.exists(os.path.join(self.checkout_path, filename)): 973 if os.path.exists(os.path.join(self.checkout_path, filename)):
951 os.remove(os.path.join(self.checkout_path, filename)) 974 os.remove(os.path.join(self.checkout_path, filename))
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 new_command.append('--force') 1116 new_command.append('--force')
1094 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: 1117 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1095 new_command.extend(('--accept', 'theirs-conflict')) 1118 new_command.extend(('--accept', 'theirs-conflict'))
1096 elif options.manually_grab_svn_rev: 1119 elif options.manually_grab_svn_rev:
1097 new_command.append('--force') 1120 new_command.append('--force')
1098 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: 1121 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1099 new_command.extend(('--accept', 'postpone')) 1122 new_command.extend(('--accept', 'postpone'))
1100 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: 1123 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1101 new_command.extend(('--accept', 'postpone')) 1124 new_command.extend(('--accept', 'postpone'))
1102 return new_command 1125 return new_command
OLDNEW
« no previous file with comments | « gclient.py ('k') | tests/gclient_scm_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698