summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2024-08-17 22:12:05 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2024-08-17 22:12:05 +0300
commitf171dfbb3103de7802013471aac7ba3082ee2618 (patch)
treeffcec4575d6acd750da3d3076170b080db6e0bfe
parentdf1adc97856a08b56199b8ebc2ea4060c709d06e (diff)
git-request-pull: Split commit checks to a separate function
Create a new check_commit() function to make the code more readable. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
-rwxr-xr-xgit-request-pull.sh87
1 files changed, 46 insertions, 41 deletions
diff --git a/git-request-pull.sh b/git-request-pull.sh
index 6a5afea..1058d2e 100755
--- a/git-request-pull.sh
+++ b/git-request-pull.sh
@@ -50,56 +50,61 @@ parse_options() {
headrev=$(git rev-parse --verify --quiet "$head"^0)
}
+check_commit()
+{
+ local baserev=$1
+ local commit=$2
+
+ local msg=$(git cat-file commit "$commit")
+ local summary=$(git show --pretty='format:%h ("%s")' -s $commit)
+
+ # 1. The commit message shall not contain a local changelog.
+ if echo -E "$msg" | grep -q '^--- *$'
+ then
+ echo "Found local changelog in commit $commit"
+ errors=$((errors+1))
+ fi
+
+ # 2. The commit message shall have Signed-off-by lines
+ # corresponding the committer and the author.
+ local committer=$(echo "$msg" | grep '^committer ' | head -1 | \
+ cut -d ' ' -f 2- | rev | cut -d ' ' -f 3- | rev)
+ if ! echo -E "$msg" | grep -Fqx "Signed-off-by: ${committer}"
+ then
+ echo "Commit $summary is not signed off by committer"
+ errors=$((errors+1))
+ fi
+
+ local author=$(echo "$msg" | grep '^author ' | head -1 | \
+ cut -d ' ' -f 2- | rev | cut -d ' ' -f 3- | rev)
+ if ! echo -E "$msg" | grep -Fqx "Signed-off-by: ${author}"
+ then
+ echo "Commit $summary is not signed off by author"
+ errors=$((errors+1))
+ fi
+
+ # 3. Fixes: tags shall reference an ancestor commit.
+ local fixes=$(echo "$msg" | grep '^Fixes: ')
+ if [ -n "$fixes" ] ; then
+ fixes=$(echo "$fixes" | sed 's/^Fixes: \([0-9a-f]\+\) (.*)$/\1/')
+ git merge-base --is-ancestor $fixes $baserev >/dev/null 2>&1 || {
+ echo "Commit $summary contains a Fixes: tag referencing $fixes not present in history"
+ errors=$((errors+1))
+ }
+ fi
+}
+
check_commits() {
if [[ -z "$baserev" || -z "$headrev" ]] ; then
# git request-pull will catch this issue
return
fi
- local author
local commit
- local committer
- local errors=0
- local sob
+ errors=0
for commit in $(git rev-list ^$baserev $headrev) ; do
- local msg=$(git cat-file commit "$commit")
- local summary=$(git show --pretty='format:%h ("%s")' -s $commit)
-
- # 1. The commit message shall not contain a local changelog.
- if echo -E "$msg" | grep -q '^--- *$'
- then
- echo "Found local changelog in commit $commit"
- errors=$((errors+1))
- fi
-
- # 2. The commit message shall have Signed-off-by lines
- # corresponding the committer and the author.
- local committer=$(echo "$msg" | grep '^committer ' | head -1 | \
- cut -d ' ' -f 2- | rev | cut -d ' ' -f 3- | rev)
- if ! echo -E "$msg" | grep -Fqx "Signed-off-by: ${committer}"
- then
- echo "Commit $summary is not signed off by committer"
- errors=$((errors+1))
- fi
-
- local author=$(echo "$msg" | grep '^author ' | head -1 | \
- cut -d ' ' -f 2- | rev | cut -d ' ' -f 3- | rev)
- if ! echo -E "$msg" | grep -Fqx "Signed-off-by: ${author}"
- then
- echo "Commit $summary is not signed off by author"
- errors=$((errors+1))
- fi
-
- # 3. Fixes: tags shall reference an ancestor commit.
- local fixes=$(echo "$msg" | grep '^Fixes: ')
- if [ -n "$fixes" ] ; then
- fixes=$(echo "$fixes" | sed 's/^Fixes: \([0-9a-f]\+\) (.*)$/\1/')
- git merge-base --is-ancestor $fixes $baserev >/dev/null 2>&1 || {
- echo "Commit $summary contains a Fixes: tag referencing $fixes not present in history"
- errors=$((errors+1))
- }
- fi
+ check_commit $baserev $commit
done
if [[ $errors != 0 ]] ; then