2
2
from pathlib import Path
3
3
import git
4
4
from mcp_server_git .server import git_checkout
5
+ import shutil
5
6
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 )
12
11
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" )
16
23
17
24
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"
19
26
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 ):
22
28
23
29
with pytest .raises (git .GitCommandError ):
24
- git_checkout (repo , "nonexistent-branch" )
30
+ git_checkout (test_repository , "nonexistent-branch" )
0 commit comments