Fix apply --force against a dirty tree; clarify patch-count guard

Two issues found by exercising the scripts end to end:

- `git checkout -B` refuses to run when the worktree is dirty, so
  `make apply FORCE=1` aborted in exactly the situation FORCE exists
  to handle. Use `checkout -f -B`; the non-forced path has already
  verified the tree is clean, so forcing changes nothing there.

- The commit-count guard claimed the user forgot `make rebuild`, but
  deleting a patch file on purpose trips it identically. Say both,
  and document the FORCE=1 form in the README's "drop the example
  patches" instructions, which would otherwise have failed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
iceBear67
2026-08-14 04:52:37 +00:00
co-authored by Claude Opus 5
parent 618c8e31ee
commit 27f078331d
2 changed files with 10 additions and 5 deletions
+3 -2
View File
@@ -175,11 +175,12 @@ git format-patch --no-stat -N --zero-commit --full-index --no-signature
(或 `)`)结尾——**改上游代码时顺手确认它的测试仍然成立**,这个补丁本身就是个例子。
2. **`0002`** 新增文件——根目录 `FORK.md`
不需要就直接删
不需要就直接删。注意要带 `FORCE=1`——`work/` 里还留着这两个补丁的提交,而删掉补丁文件后
`patches/``work/` 少,安全检查会拦下来(它无法区分「你故意删的」和「你忘了 rebuild」):
```sh
rm patches/0001-*.patch patches/0002-*.patch
make apply
make apply FORCE=1
```
## 许可
+7 -3
View File
@@ -38,8 +38,9 @@ else
want="$(count_patches)"
if [[ "$have" != "$want" ]]; then
die "work/ has $have commit(s) above $BASE_TAG but patches/ has $want patch file(s).
You probably forgot to run 'make rebuild' after committing.
To discard the work/ commits and replay patches/ as-is: make apply FORCE=1"
Either you committed in work/ without running 'make rebuild' (export it:
make rebuild), or you added/removed patch files on purpose -- in which case
discard the work/ commits and replay patches/ as-is: make apply FORCE=1"
fi
fi
fi
@@ -58,7 +59,10 @@ gitdir="$(git rev-parse --git-dir)"
[[ -d "$gitdir/rebase-apply" ]] && git am --abort >/dev/null 2>&1 || true
info "Resetting work/ to upstream $(git rev-parse --short "$REV")"
git checkout -q -B "$WORK_BRANCH" "$REV"
# -f is required: without it checkout refuses to run against a dirty tree, which
# is precisely the case FORCE=1 exists to handle. The tree is already known
# clean on the non-forced path, so forcing costs nothing there.
git checkout -q -f -B "$WORK_BRANCH" "$REV"
git reset -q --hard "$REV"
# -x removes ignored files too, which is what we want for a pristine tree --