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,9 +1687,16 @@ it or fix the checkout.
should_recurse=False,
relative=None,
condition=None))
print('\nWARNING: \'%s\' is no longer part of this client.\n'
'It is recommended that you manually remove it or use '
'\'gclient sync -D\' next time.' % entry_fixed)
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'
'It is recommended that you manually remove it or use '
'\'gclient sync -D\' next time.' % entry_fixed)
else:
# Delete the entry
print('\n________ deleting \'%s\' in \'%s\'' % (

@ -912,10 +912,11 @@ class GitWrapper(SCMWrapper):
self.Print('________ couldn\'t run status in %s:\n'
'The directory does not exist.' % self.checkout_path)
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(
['-c', 'core.quotePath=false', 'diff', '--name-status'] + merge_base,
options, always_show_header=options.verbose)

@ -307,8 +307,9 @@ class ManagedGitWrapperTestCase(BaseGitWrapperTestCase):
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)
scm = gclient_scm.GitWrapper(
self.url + '@069c602044c5388d2d15c3f875b057c852003458', self.root_dir,
self.relpath)
file_list = []
scm.status(options, self.args, file_list)
self.assertEqual(file_list, [file_path])
@ -317,6 +318,22 @@ class ManagedGitWrapperTestCase(BaseGitWrapperTestCase):
'069c602044c5388d2d15c3f875b057c852003458\' in \'%s\'\n\nM\ta\n') %
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):
if not self.enabled:
return
@ -327,8 +344,9 @@ class ManagedGitWrapperTestCase(BaseGitWrapperTestCase):
with open(file_path, 'a') as f:
f.writelines('touched\n')
expected_file_list.extend([file_path])
scm = gclient_scm.GitWrapper(self.url, self.root_dir,
self.relpath)
scm = gclient_scm.GitWrapper(
self.url + '@069c602044c5388d2d15c3f875b057c852003458', self.root_dir,
self.relpath)
file_list = []
scm.status(options, self.args, file_list)
expected_file_list = [join(self.base_path, x) for x in ['a', 'b']]

Loading…
Cancel
Save