Skip to content

Commit

Permalink
github/hooks: Add post-merge
Browse files Browse the repository at this point in the history
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 succeeds the last merge so need to run git reset --hard
if this script outputs warnings.
  • Loading branch information
fujiwarat committed Aug 17, 2023
1 parent f05c12d commit 5ed9f13
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/hooks/commit-msg
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
84 changes: 84 additions & 0 deletions .github/hooks/post-merge
Original file line number Diff line number Diff line change
@@ -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 <takao.fujiwara1@gmail.com>
#
# 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
} || :

0 comments on commit 5ed9f13

Please sign in to comment.