Skip to content

Commit 6467e9d

Browse files
committed
doc: Update setup webhooks documentation.
1 parent 25dc80c commit 6467e9d

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

README.md

+11-3
Original file line numberDiff line numberDiff line change
@@ -150,21 +150,29 @@ Update `.git/hooks/prepare-commit-msg` with the following code:
150150

151151
```sh
152152
#!/bin/bash
153-
exec < /dev/tty && node_modules/.bin/cz --hook || true
153+
test -z $2 && exec < /dev/tty && node_modules/.bin/cz --hook || true
154154
```
155155

156156
##### Husky
157157

158-
For `husky` users, add the following configuration to the project's `package.json` file:
158+
For `husky` <= v4 users, add the following configuration to the project's `package.json` file:
159159

160160
```json
161161
"husky": {
162162
"hooks": {
163-
"prepare-commit-msg": "exec < /dev/tty && npx cz --hook || true"
163+
"prepare-commit-msg": "test -z $2 && exec < /dev/tty && npx cz --hook || true"
164164
}
165165
}
166166
```
167167

168+
For `husky` > v4 users, run following:
169+
170+
```sh
171+
npx husky add .husky/prepare-commit-msg 'test -z $2 && exec < /dev/tty && npx cz --hook || true'
172+
```
173+
174+
> **Why `test -z $2`?** To prevent running commitizen, when commit source (passed as `$2` parameter) is not empty. E.g. when user provided it's own commit message manually e.g. using `git commit -m "doc: Improve README.md"`. More info in [git prepare_commit_msg hook documentation](https://git-scm.com/docs/githooks#_prepare_commit_msg).
175+
168176
> **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.
169177
170178
#### Congratulations! Your repo is Commitizen friendly. Time to flaunt it!

0 commit comments

Comments
 (0)