Skip to content

Commit 24453fe

Browse files
committed
tests/sync(test[update_repo]): Add test for rev-list HEAD failure path
why: The rev-list HEAD error handler had no test coverage, which allowed the missing add_error() bug to go undetected. what: - Add test_update_repo_rev_list_head_failure_returns_sync_result
1 parent fcbf595 commit 24453fe

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

tests/sync/test_git.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,3 +1025,37 @@ def test_update_repo_checkout_failure_returns_sync_result(
10251025
assert result.errors[0].step == "checkout"
10261026
assert result.errors[0].exception is not None
10271027
assert isinstance(result.errors[0].exception, exc.CommandError)
1028+
1029+
1030+
def test_update_repo_rev_list_head_failure_returns_sync_result(
1031+
create_git_remote_bare_repo: CreateRepoPytestFixtureFn,
1032+
tmp_path: pathlib.Path,
1033+
) -> None:
1034+
"""update_repo() records rev-list HEAD failure in SyncResult."""
1035+
git_server = create_git_remote_bare_repo()
1036+
git_repo = GitSync(
1037+
path=tmp_path / "myrepo",
1038+
url=git_server.as_uri(),
1039+
)
1040+
git_repo.obtain()
1041+
1042+
# Make a commit and push so the repo has a valid HEAD
1043+
initial_file = git_repo.path / "initial_file"
1044+
initial_file.write_text("content", encoding="utf-8")
1045+
git_repo.run(["add", str(initial_file)])
1046+
git_repo.run(["commit", "-m", "initial commit"])
1047+
git_repo.run(["push"])
1048+
1049+
# Corrupt HEAD so rev-list HEAD fails
1050+
head_file = git_repo.path / ".git" / "HEAD"
1051+
head_file.write_text("ref: refs/heads/nonexistent\n")
1052+
1053+
result = git_repo.update_repo()
1054+
1055+
assert isinstance(result, SyncResult)
1056+
assert result.ok is False
1057+
assert bool(result) is False
1058+
assert len(result.errors) > 0
1059+
assert result.errors[0].step == "rev-list-head"
1060+
assert result.errors[0].exception is not None
1061+
assert isinstance(result.errors[0].exception, exc.CommandError)

0 commit comments

Comments
 (0)