Skip to content

Commit 9151c38

Browse files
committed
Test "installing" another git and refreshing
This is trickier to test than the other cases, but important enough that I think it deserves its own test.
1 parent 626a550 commit 9151c38

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

‎test/test_git.py

+25
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import mock # To be able to examine call_args.kwargs on a mock.
2525

2626
import ddt
27+
import pytest
2728

2829
from git import Git, refresh, GitCommandError, GitCommandNotFound, Repo, cmd
2930
from git.util import cwd, finalize_process
@@ -611,6 +612,30 @@ def test_successful_refresh_with_same_env_invalidates_cached_version_info(self):
611612
refresh() # The fake git at path1 has a different version now.
612613
self.assertEqual(new_git.version_info, (22, 222, 2))
613614

615+
@pytest.mark.xfail(
616+
os.name == "nt",
617+
reason="""Name "git" won't find .bat/.cmd (need shim, custom name, or shell)""",
618+
raises=GitCommandNotFound,
619+
)
620+
def test_successful_refresh_in_default_scenario_invalidates_cached_version(self):
621+
"""Refreshing updates version after a filesystem change adds a git command."""
622+
with contextlib.ExitStack() as stack:
623+
stack.enter_context(_rollback_refresh())
624+
path1 = Path(stack.enter_context(_fake_git(11, 111, 1)))
625+
path2 = Path(stack.enter_context(_fake_git(22, 222, 2)))
626+
sep = os.pathsep
627+
new_path_var = f"{path1.parent}{sep}{path2.parent}{sep}{os.environ['PATH']}"
628+
stack.enter_context(mock.patch.dict(os.environ, {"PATH": new_path_var}))
629+
stack.enter_context(_patch_out_env("GIT_PYTHON_GIT_EXECUTABLE"))
630+
new_git = Git()
631+
path2.rename(path2.with_stem("git"))
632+
refresh()
633+
self.assertEqual(new_git.version_info, (22, 222, 2), 'before "downgrade"')
634+
path1.rename(path1.with_stem("git"))
635+
self.assertEqual(new_git.version_info, (22, 222, 2), "stale version")
636+
refresh()
637+
self.assertEqual(new_git.version_info, (11, 111, 1), "fresh version")
638+
614639
def test_options_are_passed_to_git(self):
615640
# This works because any command after git --version is ignored.
616641
git_version = self.git(version=True).NoOp()

0 commit comments

Comments
 (0)