From d1259b49c5b41bc4939ba7c5bb8e8e08083a05f6 Mon Sep 17 00:00:00 2001 From: Helmut Januschka Date: Mon, 23 Sep 2024 15:35:37 +0000 Subject: [PATCH] show-scope is only available git>=2.26 Change-Id: Ie83edb34f2e582ccca177e36010344788a090376 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5874040 Reviewed-by: Josip Sokcevic Commit-Queue: Josip Sokcevic --- scm.py | 6 +++++- tests/scm_unittest.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/scm.py b/scm.py index 6bc912505..7cbf0ea35 100644 --- a/scm.py +++ b/scm.py @@ -387,7 +387,11 @@ class GitConfigStateReal(GitConfigStateBase): def load_config(self) -> GitFlatConfigData: # NOTE: `git config --list` already canonicalizes keys. try: - rawConfig = GIT.Capture(['config', '--list', '-z', '--show-scope'], + gitConfigCmd = ['config', '--list', '-z', '--show-scope'] + if git_common.get_git_version() <= (2, 25): + gitConfigCmd = ['config', '--list', '-z'] + + rawConfig = GIT.Capture(gitConfigCmd, cwd=self.root, strip_out=False) except subprocess2.CalledProcessError: diff --git a/tests/scm_unittest.py b/tests/scm_unittest.py index 2d5622c7c..df8633561 100755 --- a/tests/scm_unittest.py +++ b/tests/scm_unittest.py @@ -514,6 +514,35 @@ class GitConfigStateTestTest(unittest.TestCase): }, }) + @mock.patch('git_common.get_git_version') + @mock.patch('scm.GIT.Capture') + def test_load_config_git_version_2_old(self, mock_capture, + mock_get_git_version): + mock_get_git_version.return_value = (2, 25) + mock_capture.return_value = "" + + config_state = scm.GitConfigStateReal("/fake/path") + config_state.load_config() + + mock_capture.assert_called_once_with(['config', '--list', '-z'], + cwd=config_state.root, + strip_out=False) + + @mock.patch('git_common.get_git_version') + @mock.patch('scm.GIT.Capture') + def test_load_config_git_version_new(self, mock_capture, + mock_get_git_version): + mock_get_git_version.return_value = (2, 26) + mock_capture.return_value = "" + + config_state = scm.GitConfigStateReal("/fake/path") + config_state.load_config() + + mock_capture.assert_called_once_with( + ['config', '--list', '-z', '--show-scope'], + cwd=config_state.root, + strip_out=False) + def test_construction_system(self): m, gs = self._make( global_state={'section.key': ['global']},