diff --git a/README.md b/README.md index e215bc4c..11428835 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/git_hooks/post-receive b/git_hooks/post-receive new file mode 100755 index 00000000..36c8fdca --- /dev/null +++ b/git_hooks/post-receive @@ -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