from __future__ import annotations

from pathlib import Path

from ablate.gitutil import current_commit, diff_name_only, diff_text


def test_diff_name_only_tracked_and_untracked(git_repo: Path):
    base = current_commit(git_repo)
    (git_repo / "src.py").write_text("def add(a, b):\n    return a + b  # patched\n")
    (git_repo / "tests").mkdir()
    (git_repo / "tests" / "test_new.py").write_text("def test_x(): pass\n")

    touched = diff_name_only(git_repo, base)

    assert "src.py" in touched
    assert "tests/test_new.py" in touched


def test_diff_text_includes_untracked_content(git_repo: Path):
    base = current_commit(git_repo)
    (git_repo / "new_file.py").write_text("VALUE = 42\n")

    text = diff_text(git_repo, base)

    assert "VALUE = 42" in text


def test_diff_name_only_empty_when_nothing_changed(git_repo: Path):
    base = current_commit(git_repo)
    assert diff_name_only(git_repo, base) == []
