Skip to content

Commit

Permalink
docs(cli): add resolve hook mode open editor FAQ
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhengqbbb committed Mar 7, 2024
1 parent dff52e1 commit b7ba5b4
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 8 deletions.
13 changes: 9 additions & 4 deletions docs/cli/install.md
Expand Up @@ -103,11 +103,13 @@ bunx czg
## As git hooks use

:::warning
This is not recommended
- Because it will **change the original behavior of git commit**, so that will lose fast commit methods such as `git commit -m "xxx"`
- And it will eventually open `vi` so that will lose the convenience of using the CLI
Not recommended usage

This will **alter the original behavior of the git commit command**, losing the ability for quick commits \
like `git commit -m "chore: ..."` \
However, czg still supports it because **it can enforce and restrict your team's commit behavior**
:::
Be that as it may czg still support, because it will constrain your team


e.g: husky(.husky/prepare-commit-msg)
```sh
Expand All @@ -116,3 +118,6 @@ e.g: husky(.husky/prepare-commit-msg)

exec < /dev/tty && npx czg --hook || true
```

==Opening a like vim editor after submitting the message ?== [==> See FAQ for solution](/faq/#opening-a-like-vim-editor-in-git-hooks-mode)

19 changes: 19 additions & 0 deletions docs/faq/index.md
Expand Up @@ -32,6 +32,25 @@ CZ_DEBUG=1 cz
CZ_DEBUG=1 czg
```

## Opening a like `vim` editor in git hooks mode

> The `prepare-commit-msg` githook opens an editor after the commit message has been prepared [=> githooks man](https://git-scm.com/docs/githooks#_prepare_commit_msg)
1. Changing the default editor from `vi` to `cat`
```sh
git config --local core.editor cat
```
2. Adding package scripts initialization script `prepare` or pnpm's `postinstall` to assist other contributors with initialization
```diff
{
"scripts": {
- "prepare": "husky install"
+ "prepare": "husky install && git config --local core.editor cat"
}
}
```


## Cannot find the command after global install

- Enter the command `npm prefix -g` to check whether the bin folder path of npm's global download is added to the system environment variable `$PATH`.
Expand Down
12 changes: 8 additions & 4 deletions docs/zh/cli/install.md
Expand Up @@ -106,17 +106,21 @@ bunx czg

:::warning
不推荐这样使用
- 因为这样会**改变 git commit 命令原有的行为**,失去快速提交的方式
`git commit -m "chore: ..."`
- 并且在最后会开启 `vi` 编辑器进行确定,失去使用命令行工具的便利性
:::

因为这样会**改变 git commit 命令原有的行为**,失去快速提交的方式 \
`git commit -m "chore: ..."` \
但话虽如此,czg 依然支持,因为它可以约束限制你团队的提交行为

:::

示例: husky(.husky/prepare-commit-msg)

```sh
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

exec < /dev/tty && npx czg --hook || true
```

==在提交完消息后出现像 vim 的编辑器 ?== [=> 查看 FAQ 解决方案](/zh/faq/#githooks-%E6%A8%A1%E5%BC%8F%E4%B8%8B%E6%89%93%E5%BC%80%E4%BA%86%E5%83%8F-vim-%E7%9A%84%E7%BC%96%E8%BE%91%E5%99%A8)

18 changes: 18 additions & 0 deletions docs/zh/faq/index.md
Expand Up @@ -31,6 +31,24 @@ CZ_DEBUG=1 cz
CZ_DEBUG=1 czg
```

## githooks 模式下打开了像 `vim` 的编辑器

> 在使用 `prepare-commit-msg` hook 中会在消息合并后使用 editor [=> githooks 命令手册](https://git-scm.com/docs/githooks#_prepare_commit_msg)
1. 将 editor 从默认 `vi` 改为 `cat`
```sh
git config --local core.editor cat
```
2. 添加 packages scripts 初始化脚本 `prepare` or pnpm's `postinstall`, 帮助其他贡献者进行初始化
```diff
{
"scripts": {
- "prepare": "husky install"
+ "prepare": "husky install && git config --local core.editor cat"
}
}
```

## 全局安装后无法找到命令

- 输入命令 `npm prefix -g` 查看当中 npm 全局下载的 bin 文件夹路径是否添加到系统环境变量 `$PATH`
Expand Down

0 comments on commit b7ba5b4

Please sign in to comment.