summaryrefslogtreecommitdiffstats
path: root/.husky/prepare-commit-msg
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-x.husky/prepare-commit-msg8
-rwxr-xr-x.husky/prepare-commit-msg.cz28
2 files changed, 36 insertions, 0 deletions
diff --git a/.husky/prepare-commit-msg b/.husky/prepare-commit-msg
new file mode 100755
index 0000000..617400a
--- /dev/null
+++ b/.husky/prepare-commit-msg
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+# shellcheck source=./_/husky.sh
+. "$(dirname "$0")/_/husky.sh"
+
+if ! git config --get tf-a.disableCommitizen > /dev/null; then
+ "$(dirname "$0")/prepare-commit-msg.cz" "$@"
+fi
diff --git a/.husky/prepare-commit-msg.cz b/.husky/prepare-commit-msg.cz
new file mode 100755
index 0000000..724527d
--- /dev/null
+++ b/.husky/prepare-commit-msg.cz
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+file="$1"
+type="$2"
+
+if [ -z "$type" ]; then # only run on new commits
+ #
+ # Save any commit message trailers generated by Git.
+ #
+
+ trailers=$(git interpret-trailers --parse "$file")
+
+ #
+ # Execute the Commitizen hook.
+ #
+
+ (exec < "/dev/tty" && npx --no-install git-cz --hook) || true
+
+ #
+ # Restore any trailers that Commitizen might have overwritten.
+ #
+
+ printf "\n" >> "$file"
+
+ while IFS= read -r trailer; do
+ git interpret-trailers --in-place --trailer "$trailer" "$file"
+ done <<< "$trailers"
+fi