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']},