From 84dc18f7331a85c730b74ca731ccb61cd56b4d1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Thu, 11 Jun 2020 10:20:20 +0200 Subject: [PATCH 1/3] Compare lines to the hash that the PR branched off from --- .maintain/gitlab/check_line_width.sh | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/.maintain/gitlab/check_line_width.sh b/.maintain/gitlab/check_line_width.sh index 85092260b6a64..d980633d9c0af 100755 --- a/.maintain/gitlab/check_line_width.sh +++ b/.maintain/gitlab/check_line_width.sh @@ -5,19 +5,20 @@ set -e set -o pipefail -BASE_ORIGIN="origin" -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 1 -git diff --name-only ${BASE_BRANCH} -- \*.rs | ( while read file +if [ -z $CI_COMMIT_BEFORE_SHA ]; then + echo "No ancestor commit set in \$CI_COMMIT_BEFORE_SHA" + exit -1; +fi + +git diff --name-only ${CI_COMMIT_BEFORE_SHA} -- \*.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 ${CI_COMMIT_BEFORE_SHA} -- ${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 ${CI_COMMIT_BEFORE_SHA} -- ${file} \ | grep -n "^+.\{$(( $LINE_WIDTH + 1))\}" echo "|" else - if git diff ${BASE_BRANCH} -- ${file} | grep -q "^+.\{$(( $GOOD_LINE_WIDTH + 1 ))\}" + if git diff ${CI_COMMIT_BEFORE_SHA} -- ${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 ${CI_COMMIT_BEFORE_SHA} -- ${file} | grep -n "^+.\{$(( $GOOD_LINE_WIDTH + 1 ))\}" echo "|" fi fi From ddd550dc766165cfc32971fd470fdfbf5fd84248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Thu, 11 Jun 2020 17:12:17 +0200 Subject: [PATCH 2/3] Use git merge-base to determine common ancestor --- .maintain/gitlab/check_line_width.sh | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/.maintain/gitlab/check_line_width.sh b/.maintain/gitlab/check_line_width.sh index d980633d9c0af..85092260b6a64 100755 --- a/.maintain/gitlab/check_line_width.sh +++ b/.maintain/gitlab/check_line_width.sh @@ -5,20 +5,19 @@ set -e set -o pipefail +BASE_ORIGIN="origin" +BASE_BRANCH_NAME="master" LINE_WIDTH="120" GOOD_LINE_WIDTH="100" +BASE_BRANCH="${BASE_ORIGIN}/${BASE_BRANCH_NAME}" -if [ -z $CI_COMMIT_BEFORE_SHA ]; then - echo "No ancestor commit set in \$CI_COMMIT_BEFORE_SHA" - exit -1; -fi - -git diff --name-only ${CI_COMMIT_BEFORE_SHA} -- \*.rs | ( while read file +git fetch ${BASE_ORIGIN} ${BASE_BRANCH_NAME} --depth 1 +git diff --name-only ${BASE_BRANCH} -- \*.rs | ( while read file do if [ ! -f ${file} ]; then echo "Skipping removed file." - elif git diff ${CI_COMMIT_BEFORE_SHA} -- ${file} | grep -q "^+.\{$(( $LINE_WIDTH + 1 ))\}" + elif git diff ${BASE_BRANCH} -- ${file} | grep -q "^+.\{$(( $LINE_WIDTH + 1 ))\}" then if [ -z "${FAIL}" ] then @@ -30,11 +29,11 @@ do FAIL="true" fi echo "| file: ${file}" - git diff ${CI_COMMIT_BEFORE_SHA} -- ${file} \ + git diff ${BASE_BRANCH} -- ${file} \ | grep -n "^+.\{$(( $LINE_WIDTH + 1))\}" echo "|" else - if git diff ${CI_COMMIT_BEFORE_SHA} -- ${file} | grep -q "^+.\{$(( $GOOD_LINE_WIDTH + 1 ))\}" + if git diff ${BASE_BRANCH} -- ${file} | grep -q "^+.\{$(( $GOOD_LINE_WIDTH + 1 ))\}" then if [ -z "${FAIL}" ] then @@ -45,7 +44,7 @@ do echo "|" fi echo "| file: ${file}" - git diff ${CI_COMMIT_BEFORE_SHA} -- ${file} | grep -n "^+.\{$(( $GOOD_LINE_WIDTH + 1 ))\}" + git diff ${BASE_BRANCH} -- ${file} | grep -n "^+.\{$(( $GOOD_LINE_WIDTH + 1 ))\}" echo "|" fi fi From c01e734301e426dec8ba905849b7e0c97c6c580a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Thu, 11 Jun 2020 17:14:09 +0200 Subject: [PATCH 3/3] Fixup --- .maintain/gitlab/check_line_width.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.maintain/gitlab/check_line_width.sh b/.maintain/gitlab/check_line_width.sh index 85092260b6a64..611d3ae2681e2 100755 --- a/.maintain/gitlab/check_line_width.sh +++ b/.maintain/gitlab/check_line_width.sh @@ -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