Skip to content

Commit faf8fc5

Browse files
author
MarcoFalke
committed
lint: Call lint_commit_msg from test_runner
Allowing to call the check from the test_runner allows for consistent error messages. Also, manually setting the commit range is no longer needed.
1 parent fa99728 commit faf8fc5

File tree

2 files changed

+41
-52
lines changed

2 files changed

+41
-52
lines changed

test/lint/lint-git-commit-check.py

Lines changed: 0 additions & 52 deletions
This file was deleted.

test/lint/test_runner/src/main.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ fn get_linter_list() -> Vec<&'static Linter> {
7373
name: "scripted_diff",
7474
lint_fn: lint_scripted_diff
7575
},
76+
&Linter {
77+
description: "Check that commit messages have a new line before the body or no body at all.",
78+
name: "commit_msg",
79+
lint_fn: lint_commit_msg
80+
},
7681
&Linter {
7782
description: "Check that tabs are not used as whitespace",
7883
name: "tabs_whitespace",
@@ -243,6 +248,42 @@ fn lint_scripted_diff() -> LintResult {
243248
}
244249
}
245250

251+
fn lint_commit_msg() -> LintResult {
252+
let mut good = true;
253+
let commit_hashes = check_output(git().args(&[
254+
"-c",
255+
"log.showSignature=false",
256+
"log",
257+
&commit_range(),
258+
"--format=%H",
259+
]))?;
260+
for hash in commit_hashes.lines() {
261+
let commit_info = check_output(git().args([
262+
"-c",
263+
"log.showSignature=false",
264+
"log",
265+
"--format=%B",
266+
"-n",
267+
"1",
268+
hash,
269+
]))?;
270+
if let Some(line) = commit_info.lines().nth(1) {
271+
if !line.is_empty() {
272+
println!(
273+
"The subject line of commit hash {} is followed by a non-empty line. Subject lines should always be followed by a blank line.",
274+
hash
275+
);
276+
good = false;
277+
}
278+
}
279+
}
280+
if good {
281+
Ok(())
282+
} else {
283+
Err("".to_string())
284+
}
285+
}
286+
246287
fn lint_py_lint() -> LintResult {
247288
let bin_name = "ruff";
248289
let checks = format!(

0 commit comments

Comments
 (0)