Files
dotfiles/.config/zsh/autoload/git/git-commit-last-msg
Julian Prein 5747b6e04c git:commit-last-msg: Make more robust
Use core.commentchar to identify commented lines and use the cut line
instead of just deleting from the first comment on, as this would break
for example in git generated messages (e.g. squashes).
2024-01-05 16:10:55 +01:00

23 lines
805 B
Bash
Executable File

#!/usr/bin/env zsh
# Commit, but put the last written commit message into the editor buffer. For
# this it uses .git/COMMIT_EDITMSG but deletes all commented lines and
# everything from the cut line on (i.e. `-- >8 --`). All arguments are passed to
# git-commit.
#
# Useful for example when the commit-msg hook fails but only slight
# modifications are needed. For example, just run:
#
# git-commit-last-msg --no-verify --no-edit
local gitdir cut_line cchar
cut_line='------------------------ >8 ------------------------'
gitdir="$(git rev-parse --git-dir)" || return
cchar="$(git config --get --default='#' core.commentchar)"
# only ^ needs escaping because of the character class used
cchar="${cchar//^/\\^}"
git commit -eF <(sed -n "/$cut_line/q; /^[$cchar]/!p" "$gitdir/COMMIT_EDITMSG") "$@"