Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions repoReleaseAudit/repo_release_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,13 @@ def audit(root: Path, max_file_mb: float = 50.0, strict: bool = False) -> dict[s
scan_markdown_links(root, path, relative, findings)

status = run_git(root, "status", "--porcelain")
dirty = bool(status.stdout.strip())
if dirty:
findings.append(Finding("error" if strict else "warning", "dirty-worktree", "."))
if status.returncode:
dirty = True
findings.append(Finding("error", "git-status-failed", "."))
else:
dirty = bool(status.stdout.strip())
if dirty:
findings.append(Finding("error" if strict else "warning", "dirty-worktree", "."))

findings.sort(key=lambda item: (item.level != "error", item.code, item.path, item.line or 0))
errors = sum(item.level == "error" for item in findings)
Expand Down
17 changes: 17 additions & 0 deletions repoReleaseAudit/tests/test_repo_release_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,20 @@ def test_invalid_utf8_text_is_not_silently_skipped(tmp_path: Path) -> None:
git(root, "add", "invalid.txt")
result = audit_module.audit(root)
assert any(item["code"] == "unreadable-text" and item["path"] == "invalid.txt" for item in result["findings"])


def test_git_status_failure_is_not_reported_as_clean(tmp_path: Path, monkeypatch) -> None:
root = tmp_path / "repo"
init_repo(root)
original = audit_module.run_git

def run_git_with_failed_status(root: Path, *args: str):
if args == ("status", "--porcelain"):
return subprocess.CompletedProcess(args, 1, stdout=b"", stderr=b"private git error")
return original(root, *args)

monkeypatch.setattr(audit_module, "run_git", run_git_with_failed_status)
result = audit_module.audit(root)
assert result["summary"]["dirty"] is True
assert any(item["code"] == "git-status-failed" and item["level"] == "error" for item in result["findings"])
assert "private git error" not in audit_module.render_text(result)
Loading