feat: add git post-receive hook for auto build and start

Adds a `git_hooks/post-receive` script that runs `pnpm run build:start`
(equivalent to `next build && next start`) automatically after a push is
received, enabling deployment on `receive.denyCurrentBranch=updateInstead`
configured repos (e.g., production/test servers).

Updates the README with a new "Git Hooks" section explaining:

- How to enable the hooks locally via `git config core.hooksPath git_hooks`
- That `core.hooksPath` is a local config and must be set per clone
- That `post-receive` fires on the receiving (push target) machine, not
  the local dev machine
This commit is contained in:
2026-06-12 14:06:41 +08:00
parent d64ad0f130
commit c4fa692528
2 changed files with 33 additions and 0 deletions
+22
View File
@@ -20,6 +20,28 @@ You can start editing the page by modifying `app/page.tsx`. The page auto-update
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
## Git Hooks
项目使用 `git_hooks/` 目录存放**仓库内**的 git hooks**不**在 `.git/hooks/`)。**clone 后需手动启用**
```bash
git config core.hooksPath git_hooks
```
### 启用的 Hook
#### `post-receive`
**触发场景**`git push` 到本仓库时(在 **bare repo**`receive.denyCurrentBranch=updateInstead` 的非 bare repo 上)。
**行为**:自动执行 `pnpm run build:start`,即 `next build && next start`
**注意事项**
- 本仓库的 `git_hooks/post-receive` **不**会**自动**生效 —— 必须在每个工作副本上跑一次上面的 `git config` 命令
- `core.hooksPath` 是**本地** git config(写入 `.git/config`),**不**随仓库提交
- `post-receive` 在**接收端**触发 —— 即 push 目标机器(生产 / 测试服务器)的 hook,不是本地开发机的
## Learn More
To learn more about Next.js, take a look at the following resources:
+11
View File
@@ -0,0 +1,11 @@
#!/bin/sh
# Post-receive hook: push 后自动 build + start
#
# 触发场景:
# - 非 bare repo + receive.denyCurrentBranch=updateInstead:本地推送自动部署
#
# 用途:执行 package.json 中的 `build:start` 脚本
# - 内部 = `npm run build && npm run start`
# - 实际调用 `pnpm run build:start`(项目使用 pnpm
pnpm run build:start