"""Tests for myclaude.git_ops module.""" from pathlib import Path from unittest.mock import MagicMock, patch import pytest from git import GitCommandError from myclaude.git_ops import commit_and_push, temp_clone def test_i_can_clone_repo_to_temp_dir() -> None: mock_repo = MagicMock() with patch("myclaude.git_ops.Repo.clone_from", return_value=mock_repo) as mock_clone: with temp_clone("git@gitea.example.com:user/skills.git") as (path, repo): mock_clone.assert_called_once() assert isinstance(path, Path) assert repo is mock_repo @pytest.mark.parametrize("bad_url", ["not-a-url", "", "http://no-ssh.com/repo"]) def test_i_cannot_clone_invalid_repo(bad_url: str) -> None: with patch( "myclaude.git_ops.Repo.clone_from", side_effect=GitCommandError("clone", 128), ): with pytest.raises(RuntimeError, match="Failed to clone"): with temp_clone(bad_url): pass def test_i_can_commit_and_push() -> None: mock_repo = MagicMock() mock_repo.is_dirty.return_value = True commit_and_push(mock_repo, "chore: update skills skill_a") mock_repo.git.add.assert_called_once_with(A=True) mock_repo.index.commit.assert_called_once_with("chore: update skills skill_a") mock_repo.remotes.origin.push.assert_called_once() def test_i_cannot_push_when_nothing_to_commit() -> None: mock_repo = MagicMock() mock_repo.is_dirty.return_value = False with pytest.raises(RuntimeError, match="Nothing to commit"): commit_and_push(mock_repo, "chore: update skills skill_a")