From a654ff36bb3dba91a3d4f1ac8a2c6e2055e1f2df Mon Sep 17 00:00:00 2001 From: Joanna Wang Date: Tue, 18 Jul 2023 23:25:19 +0000 Subject: [PATCH] Convert branch revision to remote branch in status call. We pull the revision from the DEPS url, but if the revision is a branch, the string must be converted into the local branch names we have for remote branches. Bug: 1464985 Change-Id: I32c89c947319a04421c46d09d057e42043594e76 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4699021 Commit-Queue: Joanna Wang Auto-Submit: Joanna Wang Reviewed-by: Aravind Vasudevan Commit-Queue: Aravind Vasudevan --- gclient_scm.py | 2 ++ tests/gclient_scm_test.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/gclient_scm.py b/gclient_scm.py index 8bb1a20a30..64db8a576e 100644 --- a/gclient_scm.py +++ b/gclient_scm.py @@ -1044,6 +1044,8 @@ class GitWrapper(SCMWrapper): if self.url: _, base_rev = gclient_utils.SplitUrlRevision(self.url) if base_rev: + if base_rev.startswith('refs/'): + base_rev = ''.join(scm.GIT.RefToRemoteRef(base_rev, self.remote)) merge_base = [base_rev] self._Run( ['-c', 'core.quotePath=false', 'diff', '--name-status'] + merge_base, diff --git a/tests/gclient_scm_test.py b/tests/gclient_scm_test.py index 06220ed8b3..67f2031fe4 100755 --- a/tests/gclient_scm_test.py +++ b/tests/gclient_scm_test.py @@ -325,6 +325,24 @@ class ManagedGitWrapperTestCase(BaseGitWrapperTestCase): 'a7142dc9f0009350b96a11f372b6ea658592aa95') sys.stdout.close() + def testStatusRef(self): + if not self.enabled: + return + options = self.Options() + file_paths = [join(self.base_path, 'a')] + with open(file_paths[0], 'a') as f: + f.writelines('touched\n') + scm = gclient_scm.GitWrapper(self.url + '@refs/heads/feature', + self.root_dir, self.relpath) + file_paths.append(join(self.base_path, 'c')) # feature branch touches c + file_list = [] + scm.status(options, self.args, file_list) + self.assertEqual(file_list, file_paths) + self.checkstdout( + ('\n________ running \'git -c core.quotePath=false diff --name-status ' + 'refs/remotes/origin/feature\' in \'%s\'\n\nM\ta\n') % + join(self.root_dir, '.')) + def testStatusNew(self): if not self.enabled: return