Skip to content

Commit 92c19ed

Browse files
committed
tests/cmd(test[GitReflog]): add tests for reflog operations
why: Ensure GitReflogManager and GitReflogEntryCmd work correctly what: - Add ReflogShowFixture with parametrized tests for show operation - Add tests for ls, get, filter, exists, expire operations - Add test for GitReflogEntryCmd.show via entry.cmd - All 8 tests verify core reflog functionality
1 parent 7917a58 commit 92c19ed

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

tests/cmd/test_git.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,3 +1441,104 @@ def test_notes_get_ref(git_repo: GitSync) -> None:
14411441
result = git_repo.cmd.notes.get_ref()
14421442
# Should return the ref name or be empty if not set
14431443
assert result == "refs/notes/commits" or result == "" or "notes" in result
1444+
1445+
1446+
# GitReflog tests
1447+
1448+
1449+
class ReflogShowFixture(t.NamedTuple):
1450+
"""Fixture for git reflog show tests."""
1451+
1452+
test_id: str
1453+
ref: str
1454+
number: int | None
1455+
1456+
1457+
REFLOG_SHOW_FIXTURES: list[ReflogShowFixture] = [
1458+
ReflogShowFixture(
1459+
test_id="head-no-limit",
1460+
ref="HEAD",
1461+
number=None,
1462+
),
1463+
ReflogShowFixture(
1464+
test_id="head-limit-5",
1465+
ref="HEAD",
1466+
number=5,
1467+
),
1468+
]
1469+
1470+
1471+
@pytest.mark.parametrize(
1472+
list(ReflogShowFixture._fields),
1473+
REFLOG_SHOW_FIXTURES,
1474+
ids=[test.test_id for test in REFLOG_SHOW_FIXTURES],
1475+
)
1476+
def test_reflog_show(
1477+
git_repo: GitSync,
1478+
test_id: str,
1479+
ref: str,
1480+
number: int | None,
1481+
) -> None:
1482+
"""Test GitReflogManager.show()."""
1483+
result = git_repo.cmd.reflog.show(ref=ref, number=number)
1484+
# Should return reflog output
1485+
assert isinstance(result, str)
1486+
assert len(result) > 0
1487+
1488+
1489+
def test_reflog_list(git_repo: GitSync) -> None:
1490+
"""Test GitReflogManager.ls()."""
1491+
entries = git_repo.cmd.reflog.ls()
1492+
assert isinstance(entries, list)
1493+
assert len(entries) > 0
1494+
1495+
# Each entry should have required fields
1496+
for entry in entries:
1497+
assert entry.sha is not None
1498+
assert entry.refspec is not None
1499+
assert entry.action is not None
1500+
1501+
1502+
def test_reflog_get(git_repo: GitSync) -> None:
1503+
"""Test GitReflogManager.get()."""
1504+
# Get the first entry (HEAD@{0})
1505+
entry = git_repo.cmd.reflog.get(refspec="HEAD@{0}")
1506+
assert entry is not None
1507+
assert entry.refspec == "HEAD@{0}"
1508+
1509+
1510+
def test_reflog_filter(git_repo: GitSync) -> None:
1511+
"""Test GitReflogManager.filter()."""
1512+
# Filter by action type (commit actions are common)
1513+
entries = git_repo.cmd.reflog.filter(action="commit")
1514+
assert isinstance(entries, list)
1515+
# May or may not have commit actions depending on repo state
1516+
1517+
1518+
def test_reflog_entry_show(git_repo: GitSync) -> None:
1519+
"""Test GitReflogEntryCmd.show()."""
1520+
# Get an entry from the list
1521+
entries = git_repo.cmd.reflog.ls()
1522+
assert len(entries) > 0
1523+
1524+
# Get the first entry's cmd and show it
1525+
entry = entries[0]
1526+
result = entry.cmd.show()
1527+
assert isinstance(result, str)
1528+
assert len(result) > 0
1529+
1530+
1531+
def test_reflog_exists(git_repo: GitSync) -> None:
1532+
"""Test GitReflogManager.exists()."""
1533+
# HEAD should always have a reflog
1534+
assert git_repo.cmd.reflog.exists("HEAD") is True
1535+
1536+
# Non-existent ref should return False
1537+
assert git_repo.cmd.reflog.exists("refs/heads/nonexistent-xyz123456") is False
1538+
1539+
1540+
def test_reflog_expire(git_repo: GitSync) -> None:
1541+
"""Test GitReflogManager.expire()."""
1542+
# Expire with dry_run should succeed
1543+
result = git_repo.cmd.reflog.expire(dry_run=True)
1544+
assert result == "" or "error" not in result.lower()

0 commit comments

Comments
 (0)