diff --git a/.github/hooks/commit-msg b/.github/hooks/commit-msg index 4e92a02a4..f33749894 100755 --- a/.github/hooks/commit-msg +++ b/.github/hooks/commit-msg @@ -66,7 +66,7 @@ do } done -head -1 "$1" | grep '^Release ' && { +head -1 "$1" | grep -q '^Release ' && { FILES=$(grep "Since: $TMP_VER" $(git ls-files)) if test x"$FILES" != x ; then echo >&2 "You need to replace $TMP_VER with the releasing version" diff --git a/.github/hooks/post-merge b/.github/hooks/post-merge new file mode 100755 index 000000000..72d30978b --- /dev/null +++ b/.github/hooks/post-merge @@ -0,0 +1,84 @@ +#!/bin/sh +# vim:set et sts=4 sw=4: +# -*- coding: utf-8 -*- +# +# ibus - The Input Bus +# +# Copyright (c) 2010-2023 Takao Fujiwara +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 +# USA + +# You can copy this file to .git/hooks/post-merge with the file permission +# '0755'. +# This script is useful not to commit invalid commit IDs every time and +# leave a temporary version(1.5.00) in source files when a release is +# bumped. +# Unfortunately .git/hooks/pre-merge-commit does not run for git merge +# fast-forwarding and I use post-merge instead as a workaround +# but post-merge succeed the last merge so need to run git reset --hard +# if this script outputs warnings. + +REPO="ibus/ibus" +TMP_VER="1.5.00" + +export GIT_PAGER=cat + +echo -e "\033[37;1mIBus post-merge\033[0m" + +check_commit_message() +{ + ID=$1 + # Check files in the current branch only but not cached commits + git log --pretty=oneline | grep -q "$ID" || { + echo >&2 "Invalid commit ID: $ID" + exit 1 + } +} + +THIS_FILE="$0" +diff $THIS_FILE .github/hooks/$(basename $THIS_FILE) || { + echo >&2 "$THIS_FILE is older than .github/hooks/$(basename $THIS_FILE)" + exit 1 +} + +test "" = "$(git log --pretty=email HEAD^...HEAD | + grep '^Signed-off-by: ' | + sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || { + echo >&2 Duplicate Signed-off-by lines. + exit 1 +} + +for ID in $(git log --pretty=email HEAD~100...HEAD | + grep '^Fixes: ' | awk '{print $2}') +do + echo "$ID" | grep -q "^http" && { + echo $ID | grep -q "$REPO/commit/" && { + ID=$(basename $ID) + check_commit_message $ID + } || : + } || { + check_commit_message $ID + } +done + +git log --pretty=email HEAD^...HEAD | grep -q "^Subject: \[PATCH\] Release" && { + FILES=$(grep "Since: $TMP_VER" $(git ls-files)) + if test x"$FILES" != x ; then + echo >&2 "You need to replace $TMP_VER with the releasing version" + echo >&2 "$FILES" + exit 1 + fi +} || :