diff --git a/doc/commit_convention.md b/doc/commit_convention.md index d82ea39eb0..5eee95e7bb 100644 --- a/doc/commit_convention.md +++ b/doc/commit_convention.md @@ -76,3 +76,16 @@ but contains The compiler does not generate an error message. It silently uses the operator bool() to coerce the expression into a Boolean. This produces counter-intuitive behavior, and may confuse developers. + +"Prepare commit message" git hook +================================= + +Execute the following to activate a little script that tries to synthesize +the first part of the commit message: + +```bash +ln -s script/prepare-commit-msg .git/hooks +``` + +Currently, if just a single file has changed, the hook will use it for the scope +and default the change type to "feat". diff --git a/script/prepare-commit-msg b/script/prepare-commit-msg new file mode 100755 index 0000000000..01cd839080 --- /dev/null +++ b/script/prepare-commit-msg @@ -0,0 +1,13 @@ +#!/bin/bash +set -euo pipefail + +# exit on existing commit message +[[ -z "$2" ]] || exit 0 + +diff=$(git diff --staged --stat | head -n -1) +[[ $(echo "$diff" | wc -l) == 1 ]] || exit 0 + +file=$(echo "$diff" | cut -f 2 -d' ') +orig=$(cat "$1") +echo "feat($file):" > $1 +echo "$orig" >> $1