From d414cb74f04a9ae31f346a43ed19ea8533cff2bf Mon Sep 17 00:00:00 2001 From: FreePhoenix888 Date: Mon, 4 Sep 2023 23:11:26 +0600 Subject: [PATCH 1/3] docs(readme): update husky instruction to run commitizen on git commit --- README.md | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e0c0a41e..b9cd58f9 100644 --- a/README.md +++ b/README.md @@ -156,14 +156,18 @@ exec < /dev/tty && node_modules/.bin/cz --hook || true ##### Husky -For `husky` users, add the following configuration to the project's `package.json` file: +For `husky` users, add the following configuration to the `.husky/prepare-commit-msg` file: -```json -"husky": { - "hooks": { - "prepare-commit-msg": "exec < /dev/tty && npx cz --hook || true" - } -} +```sh +#!/usr/bin/env sh +. "$(dirname -- "$0")/_/husky.sh" + +exec < /dev/tty && npx cz --hook +``` + +And make this file executable +```sh +.husky/prepare-commit-msg ``` > **Why `exec < /dev/tty`?** By default, git hooks are not interactive. This command allows the user to use their terminal to interact with Commitizen during the hook. From 47bbff7e6e6089282d588ad415ea8795f51c4daf Mon Sep 17 00:00:00 2001 From: FreePhoenix888 Date: Thu, 7 Sep 2023 18:01:56 +0600 Subject: [PATCH 2/3] Update README.md --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b9cd58f9..e855016c 100644 --- a/README.md +++ b/README.md @@ -162,7 +162,16 @@ For `husky` users, add the following configuration to the `.husky/prepare-commit #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" -exec < /dev/tty && npx cz --hook +# Check if COMMIT_EDITMSG is just a default message +if grep -q "# Please enter the commit message" ".git/COMMIT_EDITMSG"; then + # Remove the default message + echo "" > .git/COMMIT_EDITMSG + # Run commitizen + exec < /dev/tty && npx cz --hook || true +else + # Use the provided commit message + exit 0 +fi ``` And make this file executable From 2abb06b20e4b36c71c842150f4edf9cb74a621dc Mon Sep 17 00:00:00 2001 From: FreePhoenix888 Date: Tue, 12 Sep 2023 22:16:39 +0600 Subject: [PATCH 3/3] Update README.md --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index e855016c..a462155f 100644 --- a/README.md +++ b/README.md @@ -162,6 +162,15 @@ For `husky` users, add the following configuration to the `.husky/prepare-commit #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" +# Ignore if amend commit +parent=$(/bin/ps -o ppid -p $PPID | tail -1) +if [ -n "$parent" ]; then + amended=$(/bin/ps -o command -p $parent | grep -e '--amend') + if [ -n "$amended" ]; then + exit 0 + fi +fi + # Check if COMMIT_EDITMSG is just a default message if grep -q "# Please enter the commit message" ".git/COMMIT_EDITMSG"; then # Remove the default message