diff --git a/test/test_git.py b/test/test_git.py index 1c610ccc5..c54971a83 100644 --- a/test/test_git.py +++ b/test/test_git.py @@ -23,6 +23,7 @@ import mock # To be able to examine call_args.kwargs on a mock. import ddt +import pytest from git import Git, refresh, GitCommandError, GitCommandNotFound, Repo, cmd from git.util import cwd, finalize_process @@ -602,6 +603,30 @@ def test_successful_refresh_with_same_env_invalidates_cached_version_info(self): refresh() # The fake git at path1 has a different version now. self.assertEqual(new_git.version_info, (22, 222, 2)) + @pytest.mark.xfail( + os.name == "nt", + reason="""Name "git" won't find .bat/.cmd (need shim, custom name, or shell)""", + raises=GitCommandNotFound, + ) + def test_successful_refresh_in_default_scenario_invalidates_cached_version(self): + """Refreshing updates version after a filesystem change adds a git command.""" + with contextlib.ExitStack() as stack: + stack.enter_context(_rollback_refresh()) + path1 = Path(stack.enter_context(_fake_git(11, 111, 1))) + path2 = Path(stack.enter_context(_fake_git(22, 222, 2))) + sep = os.pathsep + new_path_var = f"{path1.parent}{sep}{path2.parent}{sep}{os.environ["PATH"]}" + stack.enter_context(mock.patch.dict(os.environ, {"PATH": new_path_var})) + stack.enter_context(_patch_out_env("GIT_PYTHON_GIT_EXECUTABLE")) + new_git = Git() + path2.rename(path2.with_stem("git")) + refresh() + self.assertEqual(new_git.version_info, (22, 222, 2), 'before "downgrade"') + path1.rename(path1.with_stem("git")) + self.assertEqual(new_git.version_info, (22, 222, 2), "stale version") + refresh() + self.assertEqual(new_git.version_info, (11, 111, 1), "fresh version") + def test_options_are_passed_to_git(self): # This works because any command after git --version is ignored. git_version = self.git(version=True).NoOp()