Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix commitcheck on FreeBSD #11070

Merged
merged 1 commit into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ checkbashisms:
-o -name 'make_gitrev.sh' -prune \
-o -type f ! -name 'config*' \
! -name 'libtool' \
-exec bash -c 'awk "NR==1 && /\#\!.*bin\/sh.*/ {print FILENAME;}" "{}"' \;); \
-exec sh -c 'awk "NR==1 && /\#\!.*bin\/sh.*/ {print FILENAME;}" "{}"' \;); \
else \
echo "skipping checkbashisms because checkbashisms is not installed"; \
fi
Expand Down
54 changes: 10 additions & 44 deletions scripts/commitcheck.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
#!/usr/bin/env bash
#!/bin/sh

REF="HEAD"

# test a url
function test_url()
{
url="$1"
if ! curl --output /dev/null --max-time 60 \
--silent --head --fail "$url" ; then
echo "\"$url\" is unreachable"
return 1
fi

return 0
}

# test commit body for length
# lines containing urls are exempt for the length limit.
function test_commit_bodylength()
test_commit_bodylength()
{
length="72"
body=$(git log -n 1 --pretty=%b "$REF" | grep -Ev "http(s)*://" | grep -E -m 1 ".{$((length + 1))}")
Expand All @@ -30,9 +17,9 @@ function test_commit_bodylength()
}

# check for a tagged line
function check_tagged_line()
check_tagged_line()
{
regex='^\s*'"$1"':\s[[:print:]]+\s<[[:graph:]]+>$'
regex='^[[:space:]]*'"$1"':[[:space:]][[:print:]]+[[:space:]]<[[:graph:]]+>$'
foundline=$(git log -n 1 "$REF" | grep -E -m 1 "$regex")
if [ -z "$foundline" ]; then
echo "error: missing \"$1\""
Expand All @@ -42,30 +29,8 @@ function check_tagged_line()
return 0
}

# check for a tagged line and check that the link is valid
function check_tagged_line_with_url()
{
regex='^\s*'"$1"':\s\K([[:graph:]]+)$'
foundline=$(git log -n 1 "$REF" | grep -Po "$regex")
if [ -z "$foundline" ]; then
echo "error: missing \"$1\""
return 1
fi

OLDIFS=$IFS
IFS=$'\n'
for url in $(echo -e "$foundline"); do
if ! test_url "$url"; then
return 1
fi
done
IFS=$OLDIFS

return 0
}

# check commit message for a normal commit
function new_change_commit()
new_change_commit()
{
error=0

Expand All @@ -89,7 +54,7 @@ function new_change_commit()
return $error
}

function is_coverity_fix()
is_coverity_fix()
{
# subject starts with Fix coverity defects means it's a coverity fix
subject=$(git log -n 1 --pretty=%s "$REF" | grep -E -m 1 '^Fix coverity defects')
Expand All @@ -100,7 +65,7 @@ function is_coverity_fix()
return 1
}

function coverity_fix_commit()
coverity_fix_commit()
{
error=0

Expand All @@ -119,11 +84,12 @@ function coverity_fix_commit()

# test each summary line for the proper format
OLDIFS=$IFS
IFS=$'\n'
IFS='
'
for line in $(git log -n 1 --pretty=%b "$REF" | grep -E '^CID'); do
echo "$line" | grep -E '^CID [[:digit:]]+: ([[:graph:]]+|[[:space:]])+ \(([[:upper:]]|\_)+\)' > /dev/null
# shellcheck disable=SC2181
if [[ $? -ne 0 ]]; then
if [ $? -ne 0 ]; then
echo "error: commit message has an improperly formatted CID defect line"
error=1
fi
Expand Down