From bb45734988bb4860ba2bfd1adc1123968ff3cdca Mon Sep 17 00:00:00 2001 From: Anthony Polito Date: Fri, 15 Nov 2019 22:26:01 +0000 Subject: [PATCH] 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 Commit-Queue: Anthony Polito --- gclient.py | 13 ++++++++++--- gclient_scm.py | 9 +++++---- tests/gclient_scm_test.py | 26 ++++++++++++++++++++++---- 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/gclient.py b/gclient.py index 102cd43f1..f6bb822de 100755 --- a/gclient.py +++ b/gclient.py @@ -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\'' % ( diff --git a/gclient_scm.py b/gclient_scm.py index ae6dc5978..fc0272cd7 100644 --- a/gclient_scm.py +++ b/gclient_scm.py @@ -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) diff --git a/tests/gclient_scm_test.py b/tests/gclient_scm_test.py index f7490e1fe..6fb0b76da 100755 --- a/tests/gclient_scm_test.py +++ b/tests/gclient_scm_test.py @@ -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']]