aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2023-01-17 15:13:35 +0900
committerMartin Schanzenbach <schanzen@gnunet.org>2023-01-17 15:13:35 +0900
commitc225268743b7571b1b6a326e34e002b3a4f40d2f (patch)
tree81d62cfd9b604f87ef911d9f02a624fa56972352
parent31dcac7e27e676a3bd00b8359806cb598d10696a (diff)
downloadgnunet-c225268743b7571b1b6a326e34e002b3a4f40d2f.tar.gz
gnunet-c225268743b7571b1b6a326e34e002b3a4f40d2f.zip
build: update git hooks logic
-rw-r--r--contrib/conf/commit-msg34
-rw-r--r--contrib/conf/prepare-commit-msg37
2 files changed, 71 insertions, 0 deletions
diff --git a/contrib/conf/commit-msg b/contrib/conf/commit-msg
new file mode 100644
index 000000000..daa526270
--- /dev/null
+++ b/contrib/conf/commit-msg
@@ -0,0 +1,34 @@
1#!/bin/bash
2
3# use as .git/hooks/commit-msg
4
5COMMIT_MSG_FILE=$1
6
7exec 1>&2
8
9RET=0
10changed=$(git diff --cached --name-only)
11
12for f in $changed;
13do
14 # Only headers in include
15 if echo $f | grep \src\/include\/.\*\.h\$ > /dev/null
16 then
17 RET=1
18 # Check if it has a ChangeLog line
19 if cat $COMMIT_MSG_FILE | grep \^ChangeLog: > /dev/null
20 then
21 RET=0
22 break
23 fi
24 fi
25done
26
27# If no ChangeLog line found, abort
28if [ $RET = 1 ];
29then
30 echo "Your commit includes staged changes that indicate an API change which requires a ChangeLog line."
31else
32 echo "Your commit does not include API changes"
33fi
34exit $RET
diff --git a/contrib/conf/prepare-commit-msg b/contrib/conf/prepare-commit-msg
new file mode 100644
index 000000000..60aaa2894
--- /dev/null
+++ b/contrib/conf/prepare-commit-msg
@@ -0,0 +1,37 @@
1#!/bin/bash
2
3# use as .git/hooks/pre-commit
4
5COMMIT_MSG_FILE=$1
6COMMIT_SOURCE=$2
7SHA1=$3
8
9exec 1>&2
10
11RET=0
12changed=$(git diff --cached --name-only)
13
14for f in $changed;
15do
16 # Only headers in include
17 if echo $f | grep \src\/include\/.\*\.h\$ > /dev/null
18 then
19 RET=1
20 fi
21done
22
23# Only add custom message when there is no commit source
24# ($COMMIT_SOURCE is empty). Otherwise, keep the default message
25# proposed by Git. Possible commit source: message, template,
26# merge, squash or commit.
27if [ $RET = 1 ];
28then
29 if [ -z "$COMMIT_SOURCE" ] || [ "message" == "$COMMIT_SOURCE" ];
30 then
31 hint=$(cat "$COMMIT_MSG_FILE")
32 echo -e "\n# Your commit includes staged changes that indicate an API change which requires a ChangeLog line. This info line will be ignored." > "$COMMIT_MSG_FILE"
33 echo "ChangeLog: " >> "$COMMIT_MSG_FILE"
34 echo "$hint" >> "$COMMIT_MSG_FILE"
35 fi
36fi
37exit 0