Skip to content

Commit

Permalink
fix: don't discard commit message on lint fail (#13953)
Browse files Browse the repository at this point in the history
If we fail a commit message, we basically throw it away, which is
frustrating if the commit message was more than trivial, which good
commit messages often are.

Instead, offer the developer a command to recover and re-edit their
commit message.
  • Loading branch information
cincodenada committed Jan 15, 2022
1 parent 4bfb438 commit 1a6884a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
18 changes: 17 additions & 1 deletion .husky/commit-msg
@@ -1,4 +1,20 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn commitlint --edit $1
BOLD_RED="\033[1;31m"
BOLD_WHITE="\033[1;37m"
YELLOW="\033[33m"
WHITE="\033[37m"
RESET="\033[0m"

exitCode=0
yarn commitlint --edit $1 || exitCode="$?"

if [ $exitCode -ne 0 ]; then
echo "${BOLD_RED}!${BOLD_WHITE} Linting errors found in commit message!${RESET}"
echo "${YELLOW}${RESET} Commit stored in .git/COMMIT_EDITMESSAGE"
echo "${YELLOW}${RESET} You can run the following command to update your commit message:"
echo "npm run fix-commit"
fi

exit $exitCode
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -268,6 +268,7 @@
"test-mssql": "cross-env DIALECT=mssql npm test",
"test-db2": "cross-env DIALECT=db2 npm test",
"----------------------------------------- development ---------------------------------------------": "",
"fix-commit": "export TMPFILE=$(mktemp) && grep -v '^#' $(git rev-parse --git-dir)/COMMIT_EDITMSG > $TMPFILE && git commit -e -F $TMPFILE",
"sscce": "node sscce.js",
"sscce-mariadb": "cross-env DIALECT=mariadb node sscce.js",
"sscce-mysql": "cross-env DIALECT=mysql node sscce.js",
Expand Down

0 comments on commit 1a6884a

Please sign in to comment.