Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Fix check-line-width CI script (#6326)
Browse files Browse the repository at this point in the history
* Compare lines to the hash that the PR branched off from

* Use git merge-base to determine common ancestor

* Fixup
  • Loading branch information
athei committed Jun 12, 2020
1 parent 883c89a commit 6b45e24
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions .maintain/gitlab/check_line_width.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 6b45e24

Please sign in to comment.