1#!/bin/bash
2
3file="$1"
4type="$2"
5
6if [ -z "$type" ]; then # only run on new commits
7    #
8    # Save any commit message trailers generated by Git.
9    #
10
11    trailers=$(git interpret-trailers --parse "$file")
12
13    #
14    # Execute the Commitizen hook.
15    #
16
17    (exec < "/dev/tty" && npx --no-install git-cz --hook) || true
18
19    #
20    # Restore any trailers that Commitizen might have overwritten.
21    #
22
23    printf "\n" >> "$file"
24
25    while IFS= read -r trailer; do
26        git interpret-trailers --in-place --trailer "$trailer" "$file"
27    done <<< "$trailers"
28fi
29