Skip to content

Commit fa1146d

Browse files
author
MarcoFalke
committed
lint: Fix COMMIT_RANGE issues
1 parent 71b6319 commit fa1146d

File tree

3 files changed

+19
-29
lines changed

3 files changed

+19
-29
lines changed

ci/lint/06_script.sh

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,24 @@ export LC_ALL=C
88

99
set -ex
1010

11-
if [ -n "$LOCAL_BRANCH" ]; then
12-
# To faithfully recreate CI linting locally, specify all commits on the current
13-
# branch.
14-
COMMIT_RANGE="$(git merge-base HEAD master)..HEAD"
15-
elif [ -n "$CIRRUS_PR" ]; then
11+
if [ -n "$CIRRUS_PR" ]; then
1612
COMMIT_RANGE="HEAD~..HEAD"
17-
echo
18-
git log --no-merges --oneline "$COMMIT_RANGE"
19-
echo
20-
test/lint/commit-script-check.sh "$COMMIT_RANGE"
13+
if [ "$(git rev-list -1 HEAD)" != "$(git rev-list -1 --merges HEAD)" ]; then
14+
echo "Error: The top commit must be a merge commit, usually the remote 'pull/${PR_NUMBER}/merge' branch."
15+
false
16+
fi
2117
else
22-
COMMIT_RANGE="SKIP_EMPTY_NOT_A_PR"
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"
2322
fi
2423
export COMMIT_RANGE
2524

25+
echo
26+
git log --no-merges --oneline "$COMMIT_RANGE"
27+
echo
28+
test/lint/commit-script-check.sh "$COMMIT_RANGE"
2629
RUST_BACKTRACE=1 "${LINT_RUNNER_PATH}/test_runner"
2730

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

ci/lint/container-entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export PATH="/python_build/bin:${PATH}"
1414
export LINT_RUNNER_PATH="/lint_test_runner"
1515

1616
if [ -z "$1" ]; then
17-
LOCAL_BRANCH=1 bash -ic "./ci/lint/06_script.sh"
17+
bash -ic "./ci/lint/06_script.sh"
1818
else
1919
exec "$@"
2020
fi

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

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,18 @@ def parse_args():
2323
""",
2424
epilog=f"""
2525
You can manually set the commit-range with the COMMIT_RANGE
26-
environment variable (e.g. "COMMIT_RANGE='47ba2c3...ee50c9e'
27-
{sys.argv[0]}"). Defaults to current merge base when neither
28-
prev-commits nor the environment variable is set.
26+
environment variable (e.g. "COMMIT_RANGE='HEAD~n..HEAD'
27+
{sys.argv[0]}") for the last 'n' commits.
2928
""")
30-
31-
parser.add_argument("--prev-commits", "-p", required=False, help="The previous n commits to check")
32-
3329
return parser.parse_args()
3430

3531

3632
def main():
37-
args = parse_args()
33+
parse_args()
3834
exit_code = 0
3935

40-
if not os.getenv("COMMIT_RANGE"):
41-
if args.prev_commits:
42-
commit_range = "HEAD~" + args.prev_commits + "...HEAD"
43-
else:
44-
# This assumes that the target branch of the pull request will be master.
45-
merge_base = check_output(["git", "merge-base", "HEAD", "master"], text=True, encoding="utf8").rstrip("\n")
46-
commit_range = merge_base + "..HEAD"
47-
else:
48-
commit_range = os.getenv("COMMIT_RANGE")
49-
if commit_range == "SKIP_EMPTY_NOT_A_PR":
50-
sys.exit(0)
36+
assert os.getenv("COMMIT_RANGE") # E.g. COMMIT_RANGE='HEAD~n..HEAD'
37+
commit_range = os.getenv("COMMIT_RANGE")
5138

5239
commit_hashes = check_output(["git", "log", commit_range, "--format=%H"], text=True, encoding="utf8").splitlines()
5340

0 commit comments

Comments
 (0)