22from pathlib import Path
33import git
44from mcp_server_git .server import git_checkout
5+ import shutil
56
6- def test_git_checkout_existing_branch (tmp_path : Path ):
7- # Setup test repo
8- repo = git .Repo .init (tmp_path )
9- Path (tmp_path / "test.txt" ).write_text ("test" )
10- repo .index .add (["test.txt" ])
11- repo .index .commit ("initial commit" )
7+ @pytest .fixture
8+ def test_repository (tmp_path : Path ):
9+ repo_path = tmp_path / "temp_test_repo"
10+ test_repo = git .Repo .init (repo_path )
1211
13- # Create and test branch
14- repo .git .branch ("test-branch" )
15- result = git_checkout (repo , "test-branch" )
12+ Path (repo_path / "test.txt" ).write_text ("test" )
13+ test_repo .index .add (["test.txt" ])
14+ test_repo .index .commit ("initial commit" )
15+
16+ yield test_repo
17+
18+ shutil .rmtree (repo_path )
19+
20+ def test_git_checkout_existing_branch (test_repository ):
21+ test_repository .git .branch ("test-branch" )
22+ result = git_checkout (test_repository , "test-branch" )
1623
1724 assert "Switched to branch 'test-branch'" in result
18- assert repo .active_branch .name == "test-branch"
25+ assert test_repository .active_branch .name == "test-branch"
1926
20- def test_git_checkout_nonexistent_branch (tmp_path : Path ):
21- repo = git .Repo .init (tmp_path )
27+ def test_git_checkout_nonexistent_branch (test_repository ):
2228
2329 with pytest .raises (git .GitCommandError ):
24- git_checkout (repo , "nonexistent-branch" )
30+ git_checkout (test_repository , "nonexistent-branch" )
0 commit comments