]> code.delx.au - dotfiles/blob - .git-hooks-global/prepare-commit-msg
bash: fix __vte_osc7 in terminal title
[dotfiles] / .git-hooks-global / prepare-commit-msg
1 #!/bin/bash
2
3 set -eu
4
5 FILENAME="$1"
6
7 function is_new_commit {
8 test -z "$(head -n1 "$FILENAME")"
9 }
10
11 function insert_issue_key {
12 local issue_key
13 issue_key="$(git symbolic-ref -q HEAD | grep -o "[A-Z]\+-[0-9]\+" | head -n1 || true)"
14 if [ -n "$issue_key" ]; then
15 sed -i "1i${issue_key}: " "$FILENAME"
16 fi
17 }
18
19 if is_new_commit; then
20 insert_issue_key
21 fi