Fix check-line-width CI script (#6326)

* Compare lines to the hash that the PR branched off from

* Use git merge-base to determine common ancestor

* Fixup
This commit is contained in:
Alexander Theißen
2020-06-12 13:47:14 +02:00
committed by GitHub
parent 9eb6da5c71
commit 50604fb445
@@ -10,14 +10,15 @@ BASE_BRANCH_NAME="master"
LINE_WIDTH="120"
GOOD_LINE_WIDTH="100"
BASE_BRANCH="${BASE_ORIGIN}/${BASE_BRANCH_NAME}"
git fetch ${BASE_ORIGIN} ${BASE_BRANCH_NAME} --depth 100
BASE_HASH=$(git merge-base ${BASE_BRANCH} HEAD)
git fetch ${BASE_ORIGIN} ${BASE_BRANCH_NAME} --depth 1
git diff --name-only ${BASE_BRANCH} -- \*.rs | ( while read file
git diff --name-only ${BASE_HASH} -- \*.rs | ( while read file
do
if [ ! -f ${file} ];
then
echo "Skipping removed file."
elif git diff ${BASE_BRANCH} -- ${file} | grep -q "^+.\{$(( $LINE_WIDTH + 1 ))\}"
elif git diff ${BASE_HASH} -- ${file} | grep -q "^+.\{$(( $LINE_WIDTH + 1 ))\}"
then
if [ -z "${FAIL}" ]
then
@@ -29,11 +30,11 @@ do
FAIL="true"
fi
echo "| file: ${file}"
git diff ${BASE_BRANCH} -- ${file} \
git diff ${BASE_HASH} -- ${file} \
| grep -n "^+.\{$(( $LINE_WIDTH + 1))\}"
echo "|"
else
if git diff ${BASE_BRANCH} -- ${file} | grep -q "^+.\{$(( $GOOD_LINE_WIDTH + 1 ))\}"
if git diff ${BASE_HASH} -- ${file} | grep -q "^+.\{$(( $GOOD_LINE_WIDTH + 1 ))\}"
then
if [ -z "${FAIL}" ]
then
@@ -44,7 +45,7 @@ do
echo "|"
fi
echo "| file: ${file}"
git diff ${BASE_BRANCH} -- ${file} | grep -n "^+.\{$(( $GOOD_LINE_WIDTH + 1 ))\}"
git diff ${BASE_HASH} -- ${file} | grep -n "^+.\{$(( $GOOD_LINE_WIDTH + 1 ))\}"
echo "|"
fi
fi