Skip to content

Commit cb92c41

Browse files
committed
chore: update prepare-commit-msg hook from kull
1 parent a3145a9 commit cb92c41

File tree

3 files changed

+38
-19
lines changed

3 files changed

+38
-19
lines changed

.dev/githooks/prepare-commit-msg

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
#
3-
# This hook adds a comment for guidance about the commit message
4-
# format on top of the default commit message.
3+
# This hook adds guidance about the commit message format
4+
# on top of the default commit message.
55
#
6-
# Called by "git commit" with the name of the file that has the
7-
# commit message, followed by the description of the commit
8-
# message's source. The hook's purpose is to edit the commit
9-
# message file. If the hook fails with a non-zero status,
10-
# the commit is aborted.
6+
# Called by "git commit" with the name of the file that has the commit message,
7+
# followed by the description of the commit message's source.
118
#
129
# To enable this hook, set the hooksPath in git:
1310
# git config core.hooksPath .dev/githooks
@@ -16,15 +13,37 @@ COMMIT_MSG_FILE=$1
1613
COMMIT_SOURCE=$2
1714
SHA1=$3
1815

16+
scopes_file=".dev/scopes.txt"
17+
test -r $scopes_file &&
18+
scopes="$(cat "$scopes_file" | sed '/^\(#.*\|\)$/d' | sed ':a;N;s/\n/, /g;ta')"
19+
1920
beginswith() { case $2 in "$1"*) true;; *) false;; esac; }
2021

22+
# https://mincong.io/2019/07/23/prepare-commit-message-using-git-hook
23+
# Only add custom message when there is no commit source ($COMMIT_SOURCE is empty).
24+
# Otherwise, keep the default message proposed by Git.
25+
# Possible commit sources: message, template, merge, squash or commit.
26+
# See https://git-scm.com/docs/githooks
2127
original=$(cat "$COMMIT_MSG_FILE")
22-
if beginswith $'\n#' "$original"; then
23-
{
24-
printf "\n\n# Please enter the message in the format\n"
25-
echo "# <type>(<scope>): <description>"
26-
echo "# Possible types: fix, feat, docs, style, refactor, test, chore, rework, release"
27-
printf "# For details see https://www.notion.so/softwarechallenge/Git-217333329ea64db5b2cc8bbbaf79db87"
28-
echo "$original"
29-
} > "$COMMIT_MSG_FILE"
28+
if test -z "$COMMIT_SOURCE"
29+
then
30+
# Find common path prefix of changed files
31+
path=$(while read file
32+
do test -z "$count" && common="$file" && count=$(expr length "$file") ||
33+
while expr substr "$file" $count 1 != substr "$common" $count 1 >/dev/null; do let count--; done
34+
done <<<"$(git -P diff --cached --name-only -r)" &&
35+
expr substr "$common" 1 "$count")
36+
{
37+
# Infer type & scope from changed files
38+
expr "$path" : "gradle" >/dev/null &&
39+
printf "chore(gradle): " ||
40+
printf "fix(%s): " $path
41+
42+
printf "\n\n# Please enter the message in the format\n"
43+
echo "# <type>(<scope>): <description>"
44+
echo "# Possible types: fix, feat, docs, style, refactor, test, chore, rework, release"
45+
test -n "$scopes" && echo "# Allowed scopes: $scopes"
46+
printf "# For details see https://www.notion.so/softwarechallenge/Git-217333329ea64db5b2cc8bbbaf79db87"
47+
echo "$original"
48+
} > "$COMMIT_MSG_FILE"
3049
fi

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The version should always be in sync with the [GUI](https://github.com/software-
1010
A `y` version of 0 marks the beta of the current year
1111
and likely contains breaking changes between patches.
1212

13-
### [23.0.1](https://github.com/software-challenge/backend/commits/23.0.0) Proper Penguins - 2022-07-28
13+
### [23.0.1](https://github.com/software-challenge/backend/commits/23.0.1) Proper Penguins - 2022-08-06
1414
- Proper rule implementation for Penguins with some helpers
1515

1616
### [23.0.0](https://github.com/software-challenge/backend/commits/23.0.0) Rough Penguins - 2022-07-28

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ansonsten (gerade bei experimentier-Branches) ein squash merge,
3030
wobei der Titel des Pull Requests der Commit-Message entsprechen sollte.
3131

3232
Detaillierte Informationen zu unserem Kollaborations-Stil
33-
findet ihr in der [Kull Konvention](https://xerus2000.github.io/kull).
33+
findet ihr in der [Kull Konvention](https://kull.jfischer.org).
3434

3535
## Build
3636

@@ -75,4 +75,4 @@ In IntelliJ kann man das Projekt bequem via Gradle importieren,
7575
wodurch alle Module und Bibliotheken automatisch geladen werden.
7676

7777
Dann können Gradle-Tasks auch direkt in IntelliJ vom Gradle-Werkzeugfenster ausgeführt werden;
78-
dieses befindet sich normalerweise in der rechten Andockleiste.
78+
dieses befindet sich normalerweise in der rechten Andockleiste.

0 commit comments

Comments
 (0)