Skip to content

Commit fa99728

Browse files
author
MarcoFalke
committed
lint: Move commit range printing to test_runner
Having a single test_runner for all logic improves the consistency and UX.
1 parent fa673cf commit fa99728

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

ci/lint/06_script.sh

+2-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
#
3-
# Copyright (c) 2018-2022 The Bitcoin Core developers
3+
# Copyright (c) 2018-present The Bitcoin Core developers
44
# Distributed under the MIT software license, see the accompanying
55
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
66

@@ -9,22 +9,13 @@ export LC_ALL=C
99
set -ex
1010

1111
if [ -n "$CIRRUS_PR" ]; then
12-
COMMIT_RANGE="HEAD~..HEAD"
12+
export COMMIT_RANGE="HEAD~..HEAD"
1313
if [ "$(git rev-list -1 HEAD)" != "$(git rev-list -1 --merges HEAD)" ]; then
1414
echo "Error: The top commit must be a merge commit, usually the remote 'pull/${PR_NUMBER}/merge' branch."
1515
false
1616
fi
17-
else
18-
# Otherwise, assume that a merge commit exists. This merge commit is assumed
19-
# to be the base, after which linting will be done. If the merge commit is
20-
# HEAD, the range will be empty.
21-
COMMIT_RANGE="$( git rev-list --max-count=1 --merges HEAD )..HEAD"
2217
fi
23-
export COMMIT_RANGE
2418

25-
echo
26-
git log --no-merges --oneline "$COMMIT_RANGE"
27-
echo
2819
RUST_BACKTRACE=1 "${LINT_RUNNER_PATH}/test_runner"
2920

3021
if [ "$CIRRUS_REPO_FULL_NAME" = "bitcoin/bitcoin" ] && [ "$CIRRUS_PR" = "" ] ; then

test/lint/test_runner/src/main.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,17 @@ fn get_git_root() -> PathBuf {
180180

181181
/// Return the commit range, or panic
182182
fn commit_range() -> String {
183-
env::var("COMMIT_RANGE").unwrap()
183+
// Use the env var, if set. E.g. COMMIT_RANGE='HEAD~n..HEAD' for the last 'n' commits.
184+
env::var("COMMIT_RANGE").unwrap_or_else(|_| {
185+
// Otherwise, assume that a merge commit exists. This merge commit is assumed
186+
// to be the base, after which linting will be done. If the merge commit is
187+
// HEAD, the range will be empty.
188+
format!(
189+
"{}..HEAD",
190+
check_output(git().args(["rev-list", "--max-count=1", "--merges", "HEAD"]))
191+
.expect("check_output failed")
192+
)
193+
})
184194
}
185195

186196
/// Return all subtree paths
@@ -673,6 +683,10 @@ fn main() -> ExitCode {
673683
};
674684

675685
let git_root = get_git_root();
686+
let commit_range = commit_range();
687+
let commit_log = check_output(git().args(["log", "--no-merges", "--oneline", &commit_range]))
688+
.expect("check_output failed");
689+
println!("Checking commit range ({commit_range}):\n{commit_log}\n");
676690

677691
let mut test_failed = false;
678692
for linter in linters_to_run {

0 commit comments

Comments
 (0)