chore: Add post-merge hook for automatic pnpm install (#13089)

### What this PR does

Adds automatic `pnpm install` execution after `git pull` or `git merge`
by configuring a post-merge hook via pre-commit.

### Why we need it and why it was done in this way

Developers often forget to run `pnpm install` after pulling changes,
leading to inconsistent dependency states. This hook automatically
detects changes to `package.json` or `pnpm-lock.yaml` and runs the
install command.

The following tradeoffs were made:

- Following the existing post-checkout pattern (not using
--frozen-lockfile)

The following alternatives were considered: None

### Breaking changes

None.

### Special notes for your reviewer

Run `pnpm prepare` after merging to activate the hook.

### Checklist

- [x] PR: The PR description is expressive enough and will help future
contributors
- [x] Code: Write code that humans can understand and keep it simple
- [x] Refactor: You have left the code cleaner than you found it
- [x] Upgrade: Impact of this change on upgrade flows was considered
- [ ] Documentation: Not required (dev tooling change)
- [x] Self-review: I have reviewed my own code

### Release note

```release-note
NONE
```
This commit is contained in:
Phantom
2026-02-27 11:25:09 +08:00
committed by GitHub
parent a43114d0c8
commit 92ef2c0edf

View File

@@ -1,4 +1,4 @@
default_install_hook_types: [pre-commit, post-checkout] default_install_hook_types: [pre-commit, post-checkout, post-merge]
repos: repos:
- repo: local - repo: local
@@ -30,4 +30,12 @@ repos:
entry: bash -c 'if [ "$PRE_COMMIT_FROM_REF" != "$PRE_COMMIT_TO_REF" ] && git diff --name-only "$PRE_COMMIT_FROM_REF" "$PRE_COMMIT_TO_REF" -- "**/package.json" pnpm-lock.yaml | grep -q .; then echo "Dependencies changed, running pnpm install..."; pnpm install; else echo "No dependency changes, skipping pnpm install."; fi' entry: bash -c 'if [ "$PRE_COMMIT_FROM_REF" != "$PRE_COMMIT_TO_REF" ] && git diff --name-only "$PRE_COMMIT_FROM_REF" "$PRE_COMMIT_TO_REF" -- "**/package.json" pnpm-lock.yaml | grep -q .; then echo "Dependencies changed, running pnpm install..."; pnpm install; else echo "No dependency changes, skipping pnpm install."; fi'
stages: [post-checkout] stages: [post-checkout]
always_run: true always_run: true
pass_filenames: false
- id: post-merge-install
name: pnpm install after merge/pull
language: system
entry: bash -c 'PREV_HEAD=$(git rev-parse --short HEAD@{1} 2>/dev/null); if [ -n "$PREV_HEAD" ] && git diff --name-only "$PREV_HEAD" HEAD -- "**/package.json" pnpm-lock.yaml | grep -q .; then echo "Dependencies changed, running pnpm install..."; pnpm install; else echo "No dependency changes, skipping pnpm install."; fi'
stages: [post-merge]
always_run: true
pass_filenames: false pass_filenames: false