Skip to content

Instantly share code, notes, and snippets.

@zing-rsa
Created January 23, 2024 09:05
Show Gist options
  • Save zing-rsa/f12e83a9c9ecd56b2365d5579c8e622e to your computer and use it in GitHub Desktop.
Save zing-rsa/f12e83a9c9ecd56b2365d5579c8e622e to your computer and use it in GitHub Desktop.

Revisions

  1. zing-rsa created this gist Jan 23, 2024.
    21 changes: 21 additions & 0 deletions pre-commit
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    #!/bin/sh

    . git-sh-setup # for die

    if git-diff-index -p -M --cached HEAD -- \
    | grep '^+' \
    | grep -i TODO; then
    # assign stdin to allow read
    exec < /dev/tty

    # read flag
    read -p "[pre-commit hook] TODO detected in patch, abort commit? (Y/n) " yn

    # close stdin
    exec <&-

    case $yn in
    [Nn] ) exit 0;;
    * ) die "[pre-commit hook] Commit blocked";;
    esac
    fi