Skip to content

Commit 867706a

Browse files
committed
chore: update readme, how to use cz in some cases
Signed-off-by: prisis <[email protected]>
1 parent f5333d3 commit 867706a

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

Diff for: packages/commitlint-config/README.md

+41-1
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,48 @@ To add a `prepare-commit-msg` hook to your project, run the following command:
207207
npx husky add .husky/prepare-commit-msg 'exec < /dev/tty && npx cz --hook || true'
208208
```
209209

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+
211245
> 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.
212252
213253
Congratulations! Your repo is Commitizen friendly. Time to flaunt it!
214254

0 commit comments

Comments
 (0)