lint: Move commit range printing to test_runner

Having a single test_runner for all logic improves the consistency and
UX.
This commit is contained in:
MarcoFalke
2025-01-14 14:02:26 +01:00
parent fa673cf344
commit fa99728b0c
2 changed files with 17 additions and 12 deletions

View File

@@ -180,7 +180,17 @@ fn get_git_root() -> PathBuf {
/// Return the commit range, or panic
fn commit_range() -> String {
env::var("COMMIT_RANGE").unwrap()
// Use the env var, if set. E.g. COMMIT_RANGE='HEAD~n..HEAD' for the last 'n' commits.
env::var("COMMIT_RANGE").unwrap_or_else(|_| {
// Otherwise, assume that a merge commit exists. This merge commit is assumed
// to be the base, after which linting will be done. If the merge commit is
// HEAD, the range will be empty.
format!(
"{}..HEAD",
check_output(git().args(["rev-list", "--max-count=1", "--merges", "HEAD"]))
.expect("check_output failed")
)
})
}
/// Return all subtree paths
@@ -673,6 +683,10 @@ fn main() -> ExitCode {
};
let git_root = get_git_root();
let commit_range = commit_range();
let commit_log = check_output(git().args(["log", "--no-merges", "--oneline", &commit_range]))
.expect("check_output failed");
println!("Checking commit range ({commit_range}):\n{commit_log}\n");
let mut test_failed = false;
for linter in linters_to_run {