From 7506dcae3a77737f1118475fdfefa74670bf1f43 Mon Sep 17 00:00:00 2001 From: chenhang Date: Tue, 16 Jun 2026 13:24:37 +0800 Subject: [PATCH] chore(githooks): sync worktree to new HEAD in post-receive hook The post-receive hook now performs a `git reset --hard HEAD` after each push to ensure the working tree reflects the newly received commits. This is needed when the server's `receive.denyCurrentBranch` is set to `false`, in which case Git no longer auto-updates the working tree and downstream build steps would otherwise run against stale code. --- .githooks/post-receive | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.githooks/post-receive b/.githooks/post-receive index 06bc22a4..c02ba4e2 100755 --- a/.githooks/post-receive +++ b/.githooks/post-receive @@ -10,6 +10,18 @@ export NVM_DIR="$HOME/.nvm" REPO_TOPLEVEL="$(git rev-parse --show-toplevel 2>/dev/null || echo "$PWD")" cd "$REPO_TOPLEVEL" || { echo "FATAL: cannot cd to $REPO_TOPLEVEL" >&2; exit 1; } +# ============================================================ +# 0. sync_worktree —— 将**工**作**树**同步到**新** push 的 HEAD +# 背景:服务器 .git/config 设了 receive.denyCurrentBranch=updateInstead 时 +# git 自**动**更**新**工作**树**但**会**跳过**此**钩子;**改**为 false 后 +# git **不**会**更**新**工作**树**,**手**动 reset --hard 同步**才**能**让**下**面** +# 的 build **用**上**新**代**码**。 +# ============================================================ +sync_worktree() { + echo "=== sync_worktree: git reset --hard HEAD @ $(date -u +%Y-%m-%dT%H:%M:%SZ) ===" + git reset --hard HEAD +} + # ============================================================ # 1. init_log_file —— 定**义** LOG_FILE + 创**建** logs/ 目**录** # ============================================================ @@ -115,6 +127,7 @@ log_abort() { # ============================================================ main() { init_log_file + sync_worktree # **先**同步工作**树**到**新** HEAD(**与** git config denyCurrentBranch 配**合**) write_metadata_header # **先**覆盖写元信息(**这**样 env copy 日**志****能**保留在**后**面) copy_env_by_branch # **追**加 env copy 日志