Skip to content

Commit 65e4eca

Browse files
author
MarcoFalke
committed
Merge #19654: lint: Don't use TRAVIS_COMMIT_RANGE in commit message linter
7235178 lint: Remove travis env var from commit linter (Fabian Jahr) Pull request description: #19439 was recently merged and seemed to work fine but I now noticed strange behavior when it was running in Travis, which I could not reproduce locally. It turns out `TRAVIS_COMMIT_RANGE` which is used in Travis to get the commits for the linter, uses all the commits that were in a push, which includes all rebase commits for example. This means that the linter can fail on a commit that the developer has never even seen before, which can be very confusing. See an example here which caused me to look into this: https://travis-ci.org/github/bitcoin/bitcoin/jobs/714296381 The commit that is reported as failing in my PR is not part of my PR. I think we rather want to use something like `git merge-base` to get the commit range by default and in Travis. I am leaving the env variable functionality in place with a different name but this is not a variable that can be expected to be present in the CI environments so the `merge-base` range should be used there by default. ACKs for top commit: hebasto: ACK 7235178, I have reviewed the code and it looks OK, I agree it can be merged. Tree-SHA512: afb27bb386855cb8d5cf84fd3a6c11ef1160b25af6175ed0aa146bf04b9a26eb77298df70df0a855f8c46f19f08b3f62c49872c12974fcfa5526a15ee05b3c10
2 parents 0f16212 + 7235178 commit 65e4eca

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,22 @@ while getopts "?" opt; do
1414
case $opt in
1515
?)
1616
echo "Usage: $0 [N]"
17-
echo " TRAVIS_COMMIT_RANGE='<commit range>' $0"
17+
echo " COMMIT_RANGE='<commit range>' $0"
1818
echo " $0 -?"
1919
echo "Checks unmerged commits, the previous N commits, or a commit range."
20-
echo "TRAVIS_COMMIT_RANGE='47ba2c3...ee50c9e' $0"
20+
echo "COMMIT_RANGE='47ba2c3...ee50c9e' $0"
2121
exit ${EXIT_CODE}
2222
;;
2323
esac
2424
done
2525

26-
if [ -z "${TRAVIS_COMMIT_RANGE}" ]; then
27-
if [ -n "$1" ]; then
28-
TRAVIS_COMMIT_RANGE="HEAD~$1...HEAD"
29-
else
30-
TRAVIS_COMMIT_RANGE="origin/master..HEAD"
31-
fi
26+
if [ -z "${COMMIT_RANGE}" ]; then
27+
if [ -n "$1" ]; then
28+
COMMIT_RANGE="HEAD~$1...HEAD"
29+
else
30+
MERGE_BASE=$(git merge-base HEAD master)
31+
COMMIT_RANGE="$MERGE_BASE..HEAD"
32+
fi
3233
fi
3334

3435
while IFS= read -r commit_hash || [[ -n "$commit_hash" ]]; do
@@ -41,6 +42,6 @@ while IFS= read -r commit_hash || [[ -n "$commit_hash" ]]; do
4142
EXIT_CODE=1
4243
fi
4344
done < <(git log --format=%B -n 1 "$commit_hash")
44-
done < <(git log "${TRAVIS_COMMIT_RANGE}" --format=%H)
45+
done < <(git log "${COMMIT_RANGE}" --format=%H)
4546

4647
exit ${EXIT_CODE}

0 commit comments

Comments
 (0)