From 1a6884a32f9a59ab690deec016e5c250ce1582c5 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Sat, 15 Jan 2022 00:05:44 -0800 Subject: [PATCH] fix: don't discard commit message on lint fail (#13953) 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. --- .husky/commit-msg | 18 +++++++++++++++++- package.json | 1 + 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/.husky/commit-msg b/.husky/commit-msg index d71a03b9f3e0..ecd176fd6a3b 100755 --- a/.husky/commit-msg +++ b/.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 diff --git a/package.json b/package.json index 7c65d9402a9c..615041b8fe42 100644 --- a/package.json +++ b/package.json @@ -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",