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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ commit-guard --range origin/main..HEAD --allow-empty
### Machine-readable output

Use `--output jsonl` to emit one JSON line per commit to stdout instead of the
default human-readable text on stderr:
default human-readable text:

```bash
commit-guard --range origin/main..HEAD --output jsonl
Expand Down
1 change: 1 addition & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ignore = [
"COM812", # missing-trailing-comma
"D", # pydocstyle (D)
"RET504", # Unnecessary assignment to X before `return` statement
"T201", # print is the intended output mechanism for this CLI
]

[lint.per-file-ignores]
Expand Down
8 changes: 4 additions & 4 deletions src/git_commit_guard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,17 +499,17 @@ def _report_jsonl(result, sha, subject):
for check, level, msg in result.errors
],
}
sys.stdout.write(json.dumps(record) + "\n")
print(json.dumps(record))
return 0 if result.ok else 1


def _report_text(result):
for check, level, msg in result.errors:
prefix = f"[{check}] " if check else ""
sys.stderr.write(f" {PREFIXES[level]} {prefix}{msg}\n")
print(f" {PREFIXES[level]} {prefix}{msg}")

if result.ok:
sys.stderr.write(" \033[32m✓\033[0m all checks passed\n")
print(" \033[32m✓\033[0m all checks passed")

return 0 if result.ok else 1

Expand Down Expand Up @@ -561,7 +561,7 @@ def main():
if _report_jsonl(result, rev, subject) != 0:
failed = True
else:
sys.stderr.write(f"{rev[:7]} {subject}\n")
print(f"{rev[:7]} {subject}")
if _report_text(result) != 0:
failed = True
return 1 if failed else 0
Expand Down
10 changes: 5 additions & 5 deletions tests/test_git_commit_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,21 +620,21 @@ def test_all_passed(self, capsys):
r = Result()
ret = _report_text(r)
assert ret == 0
assert "all checks passed" in capsys.readouterr().err
assert "all checks passed" in capsys.readouterr().out

def test_with_error(self, capsys):
r = Result()
r.error("something broke")
ret = _report_text(r)
assert ret == 1
assert "something broke" in capsys.readouterr().err
assert "something broke" in capsys.readouterr().out

def test_with_warning_returns_zero(self, capsys):
r = Result()
r.warn("heads up")
ret = _report_text(r)
assert ret == 0
captured = capsys.readouterr().err
captured = capsys.readouterr().out
assert "heads up" in captured
assert "all checks passed" in captured

Expand Down Expand Up @@ -702,7 +702,7 @@ def test_from_message_file(self, tmp_path, capsys):
["cg", "--message-file", str(f), "--disable", "signature"],
):
assert main() == 0
assert "all checks passed" in capsys.readouterr().err
assert "all checks passed" in capsys.readouterr().out

def test_from_stdin(self):
stdin = MagicMock()
Expand Down Expand Up @@ -761,7 +761,7 @@ def test_signature_skipped_without_rev(self, tmp_path, capsys):
):
ret = main()
assert ret == 0
assert "all checks passed" in capsys.readouterr().err
assert "all checks passed" in capsys.readouterr().out

def test_imperative_only_no_subject_check(self, tmp_path):
# imperative enabled, subject not — desc starts as None, parsed from line
Expand Down
Loading