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

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: '' 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 is specified, remove any untracked directories.
446 if options.force:
447 # GIT.CaptureStatus() uses 'dit diff' to compare to a specific SHA1 (the
448 # merge-base by default), so doesn't include untracked files. So we use
449 # 'git ls-files --directory --others --exclude-standard' here directly.
450 paths = scm.GIT.Capture(
451 ['ls-files', '--directory', '--others', '--exclude-standard'],
M-A Ruel 2012/02/08 14:43:46 Note that this will be overzealous if .gitignore i
Steve Block 2012/02/09 17:55:04 I think that in this case, we want to delete untra
452 self.checkout_path)
453 if paths:
454 for path in paths.splitlines():
455 if path.endswith('/'):
456 print('\n_____ removing unversioned directory %s' % path)
457 gclient_utils.RemoveDirectory(os.path.join(self.checkout_path,
458 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 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 to_info['Repository Root'], 923 to_info['Repository Root'],
908 self.relpath] 924 self.relpath]
909 self._Run(command, options, cwd=self._root_dir) 925 self._Run(command, options, cwd=self._root_dir)
910 from_info['URL'] = from_info['URL'].replace( 926 from_info['URL'] = from_info['URL'].replace(
911 from_info['Repository Root'], 927 from_info['Repository Root'],
912 to_info['Repository Root']) 928 to_info['Repository Root'])
913 else: 929 else:
914 if not options.force and not options.reset: 930 if not options.force and not options.reset:
915 # Look for local modifications but ignore unversioned files. 931 # Look for local modifications but ignore unversioned files.
916 for status in scm.SVN.CaptureStatus(None, self.checkout_path): 932 for status in scm.SVN.CaptureStatus(None, self.checkout_path):
917 if status[0] != '?': 933 if status[0][0] != '?':
M-A Ruel 2012/02/08 14:43:46 Eh, that was bad.
918 raise gclient_utils.Error( 934 raise gclient_utils.Error(
919 ('Can\'t switch the checkout to %s; UUID don\'t match and ' 935 ('Can\'t switch the checkout to %s; UUID don\'t match and '
920 'there is local changes in %s. Delete the directory and ' 936 'there is local changes in %s. Delete the directory and '
921 'try again.') % (url, self.checkout_path)) 937 'try again.') % (url, self.checkout_path))
922 # Ok delete it. 938 # Ok delete it.
923 print('\n_____ switching %s to a new checkout' % self.relpath) 939 print('\n_____ switching %s to a new checkout' % self.relpath)
924 gclient_utils.RemoveDirectory(self.checkout_path) 940 gclient_utils.RemoveDirectory(self.checkout_path)
925 # We need to checkout. 941 # We need to checkout.
926 command = ['checkout', url, self.checkout_path] 942 command = ['checkout', url, self.checkout_path]
927 command = self._AddAdditionalUpdateFlags(command, options, revision) 943 command = self._AddAdditionalUpdateFlags(command, options, revision)
928 self._RunAndGetFileList(command, options, file_list, self._root_dir) 944 self._RunAndGetFileList(command, options, file_list, self._root_dir)
929 return 945 return
930 946
931 # If the provided url has a revision number that matches the revision 947 # 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. 948 # number of the existing directory, then we don't need to bother updating.
933 if not options.force and str(from_info['Revision']) == revision: 949 if not options.force and str(from_info['Revision']) == revision:
934 if options.verbose or not forced_revision: 950 if options.verbose or not forced_revision:
935 print('\n_____ %s%s' % (self.relpath, rev_str)) 951 print('\n_____ %s%s' % (self.relpath, rev_str))
936 return 952 return
937 953
938 command = ['update', self.checkout_path] 954 command = ['update', self.checkout_path]
939 command = self._AddAdditionalUpdateFlags(command, options, revision) 955 command = self._AddAdditionalUpdateFlags(command, options, revision)
940 self._RunAndGetFileList(command, options, file_list, self._root_dir) 956 self._RunAndGetFileList(command, options, file_list, self._root_dir)
941 957
958 # If --force is specified, remove any untracked files and directories.
M-A Ruel 2012/02/08 14:43:46 You are basically doing a revert only for director
Steve Block 2012/02/09 17:55:04 I considered this approach, but it seems less robu
959 if options.force:
960 for status in scm.SVN.CaptureStatus(None, self.checkout_path):
961 if (status[0][0] == '?'
962 and os.path.isdir(os.path.join(self.checkout_path, status[1]))):
963 print('\n_____ removing unversioned directory %s' % status[1])
964 gclient_utils.RemoveDirectory(os.path.join(self.checkout_path,
965 status[1]))
966
942 def updatesingle(self, options, args, file_list): 967 def updatesingle(self, options, args, file_list):
943 filename = args.pop() 968 filename = args.pop()
944 if scm.SVN.AssertVersion("1.5")[0]: 969 if scm.SVN.AssertVersion("1.5")[0]:
945 if not os.path.exists(os.path.join(self.checkout_path, '.svn')): 970 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 971 # 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. 972 # operations will only apply to the one file we checked out.
948 command = ["checkout", "--depth", "empty", self.url, self.checkout_path] 973 command = ["checkout", "--depth", "empty", self.url, self.checkout_path]
949 self._Run(command, options, cwd=self._root_dir) 974 self._Run(command, options, cwd=self._root_dir)
950 if os.path.exists(os.path.join(self.checkout_path, filename)): 975 if os.path.exists(os.path.join(self.checkout_path, filename)):
951 os.remove(os.path.join(self.checkout_path, filename)) 976 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') 1118 new_command.append('--force')
1094 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: 1119 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1095 new_command.extend(('--accept', 'theirs-conflict')) 1120 new_command.extend(('--accept', 'theirs-conflict'))
1096 elif options.manually_grab_svn_rev: 1121 elif options.manually_grab_svn_rev:
1097 new_command.append('--force') 1122 new_command.append('--force')
1098 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: 1123 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1099 new_command.extend(('--accept', 'postpone')) 1124 new_command.extend(('--accept', 'postpone'))
1100 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: 1125 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1101 new_command.extend(('--accept', 'postpone')) 1126 new_command.extend(('--accept', 'postpone'))
1102 return new_command 1127 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