55from dulwich .repo import Repo
66
77from infrahub_sdk .repository import GitRepoManager
8+ from infrahub_sdk .testing .repository import GitRepo
9+ from infrahub_sdk .utils import get_fixtures_dir
810
911
1012@pytest .fixture
@@ -29,21 +31,12 @@ def test_initialize_repo_creates_new_repo(temp_dir):
2931def test_initialize_repo_uses_existing_repo (temp_dir ):
3032 """Test that the GitRepoManager uses an existing repository without an active branch."""
3133 # Manually initialize a repo
32- Repo .init (temp_dir )
34+ Repo .init (temp_dir , default_branch = b"main" )
3335
34- with pytest .raises (ValueError , match = "Git repository does not have an active branch." ):
35- manager = GitRepoManager (temp_dir )
36- assert manager .git is not None
37- assert isinstance (manager .git , Repo )
38- assert (Path (temp_dir ) / ".git" ).is_dir ()
39-
40-
41- def test_create_initial_commit (temp_dir ):
42- """Test that an initial commit is created."""
4336 manager = GitRepoManager (temp_dir )
44-
45- # Verify there is at least one commit
46- assert len ( list ( manager .git . get_walker ())) == 1
37+ assert manager . git is not None
38+ assert isinstance ( manager . git , Repo )
39+ assert ( Path ( temp_dir ) / " .git" ). is_dir ()
4740
4841
4942def test_active_branch_returns_correct_branch (temp_dir ):
@@ -62,16 +55,13 @@ def mock_init(*args, **kwargs): # noqa: ANN002, ANN003
6255
6356 monkeypatch .setattr (Repo , "init" , mock_init )
6457
65- with pytest .raises (ValueError , match = "Git repository not initialized ." ):
58+ with pytest .raises (ValueError , match = "Failed to initialize or open a repository ." ):
6659 GitRepoManager (temp_dir )
6760
6861
69- def test_active_branch_raises_error_if_repo_not_initialized (temp_dir ):
70- """Test that accessing the active branch raises an error if the repo is not initialized."""
71- manager = GitRepoManager (temp_dir )
72-
73- # Manually unset the repository to simulate uninitialized state
74- manager .git = None
75-
76- with pytest .raises (ValueError , match = "Repository is not initialized." ):
77- _ = manager .active_branch
62+ def test_gitrepo_init (temp_dir ):
63+ src_directory = get_fixtures_dir () / "integration/repo"
64+ repo = GitRepo (name = "test" , src_directory = src_directory , dst_directory = Path (temp_dir ))
65+ assert len (list (repo ._repo .git .get_walker ())) == 1
66+ commit = repo ._repo .git [repo ._repo .git .head ()]
67+ assert commit .message .decode ("utf-8" ) == "First commit"
0 commit comments