11import pytest
22from pathlib import Path
33import git
4+ from git .exc import BadName
45from mcp_server_git .server import (
56 git_checkout ,
67 git_branch ,
@@ -40,7 +41,7 @@ def test_git_checkout_existing_branch(test_repository):
4041
4142def test_git_checkout_nonexistent_branch (test_repository ):
4243
43- with pytest .raises (git . exc . BadName ):
44+ with pytest .raises (BadName ):
4445 git_checkout (test_repository , "nonexistent-branch" )
4546
4647def test_git_branch_local (test_repository ):
@@ -316,25 +317,25 @@ def test_validate_repo_path_symlink_escape(tmp_path: Path):
316317
317318def test_git_diff_rejects_flag_injection (test_repository ):
318319 """git_diff should reject flags that could be used for argument injection."""
319- with pytest .raises (git . exc . BadName ):
320+ with pytest .raises (BadName ):
320321 git_diff (test_repository , "--output=/tmp/evil" )
321322
322- with pytest .raises (git . exc . BadName ):
323+ with pytest .raises (BadName ):
323324 git_diff (test_repository , "--help" )
324325
325- with pytest .raises (git . exc . BadName ):
326+ with pytest .raises (BadName ):
326327 git_diff (test_repository , "-p" )
327328
328329
329330def test_git_checkout_rejects_flag_injection (test_repository ):
330331 """git_checkout should reject flags that could be used for argument injection."""
331- with pytest .raises (git . exc . BadName ):
332+ with pytest .raises (BadName ):
332333 git_checkout (test_repository , "--help" )
333334
334- with pytest .raises (git . exc . BadName ):
335+ with pytest .raises (BadName ):
335336 git_checkout (test_repository , "--orphan=evil" )
336337
337- with pytest .raises (git . exc . BadName ):
338+ with pytest .raises (BadName ):
338339 git_checkout (test_repository , "-f" )
339340
340341
@@ -398,7 +399,7 @@ def test_git_diff_rejects_malicious_refs(test_repository):
398399 malicious_ref_path .write_text (sha )
399400
400401 # Even though the ref exists, it should be rejected
401- with pytest .raises (git . exc . BadName ):
402+ with pytest .raises (BadName ):
402403 git_diff (test_repository , "--output=evil.txt" )
403404
404405 # Verify no file was created (the attack was blocked)
@@ -417,7 +418,7 @@ def test_git_checkout_rejects_malicious_refs(test_repository):
417418 malicious_ref_path .write_text (sha )
418419
419420 # Even though the ref exists, it should be rejected
420- with pytest .raises (git . exc . BadName ):
421+ with pytest .raises (BadName ):
421422 git_checkout (test_repository , "--orphan=evil" )
422423
423424 # Cleanup
0 commit comments