Skip to content

Commit 21550c4

Browse files
authored
docs: document rs setup --force (#404)
1 parent 4829cbb commit 21550c4

4 files changed

Lines changed: 70 additions & 14 deletions

File tree

website/docs/en/guide/cli/setup.mdx

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,26 @@ rs staged
4141

4242
:::warning Existing Git hook managers
4343

44-
`rs setup` updates the repository's [`core.hooksPath`](https://git-scm.com/docs/git-config#Documentation/git-config.txt-corehooksPath). It skips installation when another hooks path or existing Git hook is detected. Migrate the required hooks and remove the existing hooks configuration before running the command.
44+
`rs setup` updates the repository's [`core.hooksPath`](https://git-scm.com/docs/git-config#Documentation/git-config.txt-corehooksPath). It skips installation when another hooks path or existing Git hook is detected. Run `rs setup --force` to install Rstack hooks anyway.
4545

4646
:::
4747

4848
## Options
4949

50+
### `--force`
51+
52+
`--force` (or `-f`) installs Rstack hooks even when an existing Git hooks setup is detected:
53+
54+
```bash
55+
rs setup --force
56+
```
57+
58+
Rstack preserves the existing hook files and sets `core.hooksPath` to its generated hooks directory. While this setting is active, Git no longer runs hooks from the previous location.
59+
60+
:::tip
61+
Run `rs setup --force` only once. Use `rs setup` without `--force` in the `prepare` script.
62+
:::
63+
5064
### `--hooks-dir`
5165

5266
Sets the directory for hook scripts, relative to the Git repository root.
@@ -171,23 +185,37 @@ To change the owner, remove `rs setup` from the previous project's `prepare` scr
171185
To remove hooks managed by Rstack CLI:
172186

173187
1. Remove `rs setup` from the `prepare` script.
174-
2. Unset the repository's hooks path:
188+
2. Check which Git configuration scope defines the active hooks path:
189+
190+
```bash
191+
git config --show-scope --get core.hooksPath
192+
```
193+
194+
3. Unset the hooks path in the reported scope. For `local`, run:
175195

176196
```bash
177197
git config --local --unset core.hooksPath
178198
```
179199

180-
3. Delete `.rstack/hooks/`, or the directory passed to `--hooks-dir`.
200+
For `worktree`, run:
201+
202+
```bash
203+
git config --worktree --unset core.hooksPath
204+
```
205+
206+
If `--force` previously preserved hooks under `.git/hooks`, unsetting the path reactivates those files. Delete any obsolete files first if you do not want them to run.
207+
208+
4. Delete `.rstack/hooks/`, or the directory passed to `--hooks-dir`.
181209

182210
## Troubleshooting
183211

184212
### Hook does not run
185213

186214
- Check that the hook script has a [supported name](#supported-hooks) and is next to the `_` directory.
187-
- Run `git config --local --get core.hooksPath` and verify the configured path.
215+
- Run `git config --show-scope --get core.hooksPath` and verify the effective scope and path.
188216
- Rerun `rs setup` to restore generated files and executable permissions.
189217
- Check that `RSTACK_HOOKS` is not set to `0` in the environment or initialization file.
190-
- If another hooks setup is reported, migrate or remove the conflicting setup before rerunning the command.
218+
- If another hooks setup is reported, run `rs setup --force`.
191219
- If another project is reported as the hooks owner, follow the ownership transfer steps in [Monorepo](#monorepo).
192220

193221
Hook scripts do not need to be executable because Rstack CLI runs them with `sh`.

website/docs/en/guide/git-hooks.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ Run the script once to install the hooks:
3636
`rs setup` sets the repository's `core.hooksPath` to `.rstack/hooks/_`. Verify the installation with:
3737

3838
```bash
39-
git config --local --get core.hooksPath
39+
git config --get core.hooksPath
4040
# .rstack/hooks/_
4141
```
4242

4343
:::tip
4444

4545
- The `_` directory is generated dynamically and ignored by Git by default.
46-
- If `rs setup` detects another hooks path or existing Git hooks, it skips installation. Migrate any hooks you want to keep, remove the existing configuration, and then try again. See the [`rs setup` guide](./cli/setup#hook-files) for details.
46+
- If `rs setup` detects another hooks path or existing Git hooks, it skips installation. Run `rs setup --force` to install Rstack hooks anyway. See the [`rs setup` guide](./cli/setup) for details.
4747

4848
:::
4949

website/docs/zh/guide/cli/setup.mdx

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,26 @@ rs staged
4141

4242
:::warning 已有 Git hook 管理工具
4343

44-
`rs setup` 会更新仓库的 [`core.hooksPath`](https://git-scm.com/docs/git-config#Documentation/git-config.txt-corehooksPath)。检测到其他 hooks 路径或已有 Git hook 时,命令会跳过安装。请先迁移所需的 hooks 并移除已有 hooks 配置,再运行该命令
44+
`rs setup` 会更新仓库的 [`core.hooksPath`](https://git-scm.com/docs/git-config#Documentation/git-config.txt-corehooksPath)。检测到其他 hooks 路径或已有 Git hook 时,命令会跳过安装。可运行 `rs setup --force` 强制安装 Rstack hooks
4545

4646
:::
4747

4848
## 选项 \{#options}
4949

50+
### `--force`
51+
52+
检测到已有 Git hooks 配置时,可使用 `--force`(或 `-f`)强制安装 Rstack hooks:
53+
54+
```bash
55+
rs setup --force
56+
```
57+
58+
Rstack 会保留原有 hook 文件,并将 `core.hooksPath` 指向 Rstack 生成的 hooks 目录。该配置生效期间,Git 不再执行原路径下的 hooks。
59+
60+
:::tip
61+
`rs setup --force` 只需运行一次。`prepare` 脚本中应使用不带 `--force``rs setup`
62+
:::
63+
5064
### `--hooks-dir`
5165

5266
设置 hook 脚本的存放目录,路径相对于 Git 仓库根目录。
@@ -171,23 +185,37 @@ rs staged
171185
如需移除由 Rstack CLI 管理的 hooks:
172186

173187
1.`prepare` 脚本中移除 `rs setup`
174-
2. 删除仓库的 hooks 路径配置:
188+
2. 检查当前生效的 hooks 路径来自哪个 Git 配置作用域:
189+
190+
```bash
191+
git config --show-scope --get core.hooksPath
192+
```
193+
194+
3. 根据输出,在对应作用域中取消 hooks 路径配置。作用域为 `local` 时运行:
175195

176196
```bash
177197
git config --local --unset core.hooksPath
178198
```
179199

180-
3. 删除 `.rstack/hooks/` 或通过 `--hooks-dir` 指定的目录。
200+
作用域为 `worktree` 时运行:
201+
202+
```bash
203+
git config --worktree --unset core.hooksPath
204+
```
205+
206+
如果之前通过 `--force` 保留了 `.git/hooks` 下的 hooks,取消路径配置会重新启用这些文件。如果不希望它们运行,请先删除不再需要的文件。
207+
208+
4. 删除 `.rstack/hooks/` 或通过 `--hooks-dir` 指定的目录。
181209

182210
## 故障排查 \{#troubleshooting}
183211

184212
### Hook 未运行 \{#hook-does-not-run}
185213

186214
- 确认 hook 脚本使用[支持的名称](#supported-hooks),并与 `_` 目录同级。
187-
- 运行 `git config --local --get core.hooksPath`检查配置的路径
215+
- 运行 `git config --show-scope --get core.hooksPath`检查当前生效的配置作用域和路径
188216
- 重新运行 `rs setup`,恢复生成文件及其可执行权限。
189217
- 检查环境变量或初始化文件中是否设置了 `RSTACK_HOOKS=0`
190-
- 如果命令提示存在其他 hooks 配置,请先迁移或移除冲突配置,再重新运行该命令
218+
- 如果命令提示存在其他 hooks 配置,请运行 `rs setup --force`
191219
- 如果命令提示其他项目是 hooks owner,请按照 [Monorepo](#monorepo) 中的步骤转移 owner。
192220

193221
hook 脚本不需要可执行权限,因为 Rstack CLI 会使用 `sh` 运行它。

website/docs/zh/guide/git-hooks.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ import { PackageManagerTabs } from '@rspress/core/theme';
3636
`rs setup` 会将仓库的 `core.hooksPath` 设为 `.rstack/hooks/_`,可以通过以下命令确认是否安装成功:
3737

3838
```bash
39-
git config --local --get core.hooksPath
39+
git config --get core.hooksPath
4040
# .rstack/hooks/_
4141
```
4242

4343
:::tip
4444

4545
- `_` 目录由命令动态生成,且默认被 Git 忽略。
46-
- 如果检测到其他 hooks 路径或已有 Git hooks,`rs setup` 会跳过安装。请先迁移需要保留的 hooks,移除原有配置,然后重试。详细说明请参考 [`rs setup` 指南](./cli/setup#hook-files)
46+
- 如果检测到其他 hooks 路径或已有 Git hooks,`rs setup` 会跳过安装。可运行 `rs setup --force` 强制安装 Rstack hooks。详细说明请参考 [`rs setup` 指南](./cli/setup)
4747

4848
:::
4949

0 commit comments

Comments
 (0)