Skip to content

Commit

Permalink
Test "installing" another git and refreshing
Browse files Browse the repository at this point in the history
This is trickier to test than the other cases, but important enough
that I think it deserves its own test.
  • Loading branch information
EliahKagan committed Feb 22, 2024
1 parent c2db445 commit 5974125
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 5974125

Please sign in to comment.