chore(githooks): simplify post-receive hook
Remove the repo top-level navigation logic and its accompanying explanatory comments from the post-receive hook. The previous code used `git rev-parse --absolute-git-dir` and `dirname` to determine and `cd` into the repository's top-level directory, which is no longer needed. The hook now starts directly with the nvm setup, making the script leaner and easier to maintain.
This commit is contained in:
@@ -12,27 +12,8 @@
|
|||||||
# - **全**局变量:LOG_FILE(在 init_log_file **里**定**义**)、CURRENT_BRANCH
|
# - **全**局变量:LOG_FILE(在 init_log_file **里**定**义**)、CURRENT_BRANCH
|
||||||
# - **函**数**间**通过 `$LOG_FILE` / `$BUILD_EXIT` 通信
|
# - **函**数**间**通过 `$LOG_FILE` / `$BUILD_EXIT` 通信
|
||||||
# - **不**用 set -e —— 各步**自**己处理错**误**(env 不**存**在 / build 失败 / 旧**进**程**不**存**在)→ 让 deploy 错**误****不**挡 git push
|
# - **不**用 set -e —— 各步**自**己处理错**误**(env 不**存**在 / build 失败 / 旧**进**程**不**存**在)→ 让 deploy 错**误****不**挡 git push
|
||||||
#
|
|
||||||
# 关键前置(**解**决 push 后 hook **不**触**发** + pnpm **找**不**到**):
|
|
||||||
# 1) cd 到 repo **顶**层 —— git-receive-pack 调 hook 时 CWD **未**必 = repo 顶
|
|
||||||
# 2) 加**载** nvm —— 非交互 shell **不**会 source .bashrc,pnpm **不**在 PATH
|
|
||||||
# 3) **验**证 PATH —— 写日**志**确认 pnpm 可**用**(**不**可用则 build **必**失**败**)
|
|
||||||
|
|
||||||
# ---- 前置:切到 repo 顶 + 加 pnpm 到 PATH ----
|
|
||||||
# 重要:git-receive-pack 调 hook 时 CWD **可**能是 `.git/` 内**部**,
|
|
||||||
# `git rev-parse --show-toplevel` 会**报**错 `must be run in a work tree`。
|
|
||||||
# 解**法**:**用** `git rev-parse --absolute-git-dir` **取**得**绝**对 .git **路**径,
|
|
||||||
# 然后 dirname **得**到 repo **顶**层。**这**两个调**用**在 .git/ 内**部**也都**能**成**功**。
|
|
||||||
GIT_DIR_ABS="$(git rev-parse --absolute-git-dir 2>/dev/null || true)"
|
|
||||||
if [ -n "$GIT_DIR_ABS" ] && [ "$GIT_DIR_ABS" != ".git" ]; then
|
|
||||||
REPO_TOPLEVEL="$(cd "$GIT_DIR_ABS/.." && pwd)"
|
|
||||||
else
|
|
||||||
# 兜底:**用** PWD (**非** bare repo 默**认**钩**子**在 **工**作**树**下)
|
|
||||||
REPO_TOPLEVEL="$PWD"
|
|
||||||
fi
|
|
||||||
cd "$REPO_TOPLEVEL" || { echo "FATAL: cannot cd to $REPO_TOPLEVEL" >&2; exit 1; }
|
|
||||||
|
|
||||||
# 加**载** nvm(**非**交互 shell **不**自动 source .bashrc,pnpm **所**以**找**不**到**)
|
|
||||||
# 同 .bashrc **里**的 NVM **加**载逻辑
|
# 同 .bashrc **里**的 NVM **加**载逻辑
|
||||||
export NVM_DIR="$HOME/.nvm"
|
export NVM_DIR="$HOME/.nvm"
|
||||||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
|
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
|
||||||
|
|||||||
Reference in New Issue
Block a user