@@ -207,8 +207,48 @@ To add a `prepare-commit-msg` hook to your project, run the following command:
207
207
npx husky add .husky/prepare-commit-msg ' exec < /dev/tty && npx cz --hook || true'
208
208
```
209
209
210
- > Why ` exec < /dev/tty? ` By default, git hooks are not interactive.
210
+ > Note: This is only a simple example. To support most cases on Linux, Mac and Windows you can use the other example below.
211
+
212
+ ``` bash
213
+ # if we hve a cmd that is running npx cz that means finalize and commit
214
+ FILE=commit.cmd
215
+ if test -f " $FILE " ; then
216
+ echo " $FILE exists."
217
+ rm commit.cmd
218
+ exit 0;
219
+ fi
220
+ # if on Windows, spawn a cmd that will run npx cz
221
+ case ` uname` in
222
+ * CYGWIN* |* MINGW* |* MSYS* )
223
+ # Only run commitizen if no commit message was already provided.
224
+ if [ -z " ${2-} " ]; then
225
+ export CZ_TYPE=" ${CZ_TYPE:- fix} "
226
+ export CZ_MAX_HEADER_WIDTH=$COMMITLINT_MAX_WIDTH
227
+ export CZ_MAX_LINE_WIDTH=$CZ_MAX_HEADER_WIDTH
228
+ echo " npx cz && exit" > commit.cmd
229
+ start commit.cmd
230
+ exit 1;
231
+ fi
232
+
233
+ exit 0;;
234
+ esac
235
+ # Only run commitizen if no commit message was already provided.
236
+ if [ -z " ${2-} " ]; then
237
+ export CZ_TYPE=" ${CZ_TYPE:- fix} "
238
+ export CZ_MAX_HEADER_WIDTH=$COMMITLINT_MAX_WIDTH
239
+ export CZ_MAX_LINE_WIDTH=$CZ_MAX_HEADER_WIDTH
240
+ # By default git hooks are not interactive. exec < /dev/tty allows a users terminal to interact with commitizen.
241
+ exec < /dev/tty && npx cz --hook || true
242
+ fi
243
+ ```
244
+
211
245
> This command allows the user to use their terminal to interact with Commitizen during the hook.
246
+ >
247
+ > Why ` exec < /dev/tty? ` By default, git hooks are not interactive.
248
+
249
+ > Note: If you are using ` zsh ` you may need to use ` exec < /dev/tty? ` instead of ` exec < /dev/tty ` .
250
+
251
+ > Note: For pnpm users, replace ` npx ` with ` pnpx ` in the above command.
212
252
213
253
Congratulations! Your repo is Commitizen friendly. Time to flaunt it!
214
254
0 commit comments