Changed "gclient sync -D" logic to compare against the expected DEPS version

Also add a better warning if 'gclient sync -D' fails due to a modified file.
I've tested this code via deleting a DEP and running gclient sync -D.

Bug: 981149
Change-Id: I97035ac238d163ccb1684c3ee423c223ed0f6299
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1891830
Reviewed-by: Edward Lesmes <ehmaldonado@chromium.org>
Commit-Queue: Anthony Polito <apolito@google.com>
changes/30/1891830/7
Anthony Polito 6 years ago committed by Commit Bot
parent 46689b09c5
commit bb45734988

@ -1687,6 +1687,13 @@ it or fix the checkout.
should_recurse=False, should_recurse=False,
relative=None, relative=None,
condition=None)) condition=None))
if modified_files and self._options.delete_unversioned_trees:
print('\nWARNING: \'%s\' is no longer part of this client.\n'
'Despite running \'gclient sync -D\' no action was taken '
'as there are modifications.\nIt is recommended you revert '
'all changes or run \'gclient sync -D --force\' next '
'time.' % entry_fixed)
else:
print('\nWARNING: \'%s\' is no longer part of this client.\n' print('\nWARNING: \'%s\' is no longer part of this client.\n'
'It is recommended that you manually remove it or use ' 'It is recommended that you manually remove it or use '
'\'gclient sync -D\' next time.' % entry_fixed) '\'gclient sync -D\' next time.' % entry_fixed)

@ -912,10 +912,11 @@ class GitWrapper(SCMWrapper):
self.Print('________ couldn\'t run status in %s:\n' self.Print('________ couldn\'t run status in %s:\n'
'The directory does not exist.' % self.checkout_path) 'The directory does not exist.' % self.checkout_path)
else: else:
try:
merge_base = [self._Capture(['merge-base', 'HEAD', self.remote])]
except subprocess2.CalledProcessError:
merge_base = [] merge_base = []
if self.url:
_, base_rev = gclient_utils.SplitUrlRevision(self.url)
if base_rev:
merge_base = [base_rev]
self._Run( self._Run(
['-c', 'core.quotePath=false', 'diff', '--name-status'] + merge_base, ['-c', 'core.quotePath=false', 'diff', '--name-status'] + merge_base,
options, always_show_header=options.verbose) options, always_show_header=options.verbose)

@ -307,7 +307,8 @@ class ManagedGitWrapperTestCase(BaseGitWrapperTestCase):
file_path = join(self.base_path, 'a') file_path = join(self.base_path, 'a')
with open(file_path, 'a') as f: with open(file_path, 'a') as f:
f.writelines('touched\n') f.writelines('touched\n')
scm = gclient_scm.GitWrapper(self.url, self.root_dir, scm = gclient_scm.GitWrapper(
self.url + '@069c602044c5388d2d15c3f875b057c852003458', self.root_dir,
self.relpath) self.relpath)
file_list = [] file_list = []
scm.status(options, self.args, file_list) scm.status(options, self.args, file_list)
@ -317,6 +318,22 @@ class ManagedGitWrapperTestCase(BaseGitWrapperTestCase):
'069c602044c5388d2d15c3f875b057c852003458\' in \'%s\'\n\nM\ta\n') % '069c602044c5388d2d15c3f875b057c852003458\' in \'%s\'\n\nM\ta\n') %
join(self.root_dir, '.')) join(self.root_dir, '.'))
def testStatusNewNoBaseRev(self):
if not self.enabled:
return
options = self.Options()
file_path = join(self.base_path, 'a')
with open(file_path, 'a') as f:
f.writelines('touched\n')
scm = gclient_scm.GitWrapper(self.url, self.root_dir, self.relpath)
file_list = []
scm.status(options, self.args, file_list)
self.assertEqual(file_list, [file_path])
self.checkstdout(
('\n________ running \'git -c core.quotePath=false diff --name-status'
'\' in \'%s\'\n\nM\ta\n') % join(self.root_dir, '.'))
def testStatus2New(self): def testStatus2New(self):
if not self.enabled: if not self.enabled:
return return
@ -327,7 +344,8 @@ class ManagedGitWrapperTestCase(BaseGitWrapperTestCase):
with open(file_path, 'a') as f: with open(file_path, 'a') as f:
f.writelines('touched\n') f.writelines('touched\n')
expected_file_list.extend([file_path]) expected_file_list.extend([file_path])
scm = gclient_scm.GitWrapper(self.url, self.root_dir, scm = gclient_scm.GitWrapper(
self.url + '@069c602044c5388d2d15c3f875b057c852003458', self.root_dir,
self.relpath) self.relpath)
file_list = [] file_list = []
scm.status(options, self.args, file_list) scm.status(options, self.args, file_list)

Loading…
Cancel
Save