chore(script/prepare-commit-msg): add simple commit message generator
This commit is contained in:
parent
f0cee8181d
commit
9d36bd057c
2 changed files with 26 additions and 0 deletions
|
|
@ -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".
|
||||
|
|
|
|||
13
script/prepare-commit-msg
Executable file
13
script/prepare-commit-msg
Executable file
|
|
@ -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
|
||||
Loading…
Add table
Reference in a new issue