From 2f646ee154a28b24c528e7244478d982e21f0e3c Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 11 May 2026 11:37:23 -0700 Subject: [PATCH] fix(husky): guard pre-commit against merge/rebase state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit lint-staged uses git stash internally to isolate staged files for linting. During a merge/rebase/cherry-pick/revert, that stash machinery interacts catastrophically with MERGE_HEAD and friends — on any lint failure it resets, silently wiping MERGE_HEAD and your conflict resolutions. The user ends up in a loop where every merge attempt leaves a clean tree with no merge commit. This adds an early-exit guard for the four mid-operation states, and also anchors the script to the repo root + scopes each lint-staged run in a subshell so a subdir commit or per-package failure can't poison the cwd for the next step. Co-Authored-By: Claude Opus 4.7 (1M context) --- .husky/pre-commit | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) mode change 100644 => 100755 .husky/pre-commit diff --git a/.husky/pre-commit b/.husky/pre-commit old mode 100644 new mode 100755 index dac57bbf1..efabe6826 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,23 @@ #!/bin/sh + +# Skip during merge/rebase/cherry-pick/revert. lint-staged's internal +# git-stash mechanism is incompatible with these states and will silently +# wipe MERGE_HEAD and your conflict resolutions on commit failure. +git_dir=$(git rev-parse --git-dir) +if [ -e "$git_dir/MERGE_HEAD" ] \ + || [ -e "$git_dir/CHERRY_PICK_HEAD" ] \ + || [ -e "$git_dir/REVERT_HEAD" ] \ + || [ -d "$git_dir/rebase-merge" ] \ + || [ -d "$git_dir/rebase-apply" ]; then + echo "Skipping lint-staged (mid merge/rebase/cherry-pick/revert)" + exit 0 +fi + +# Anchor to repo root so commits made from a subdirectory still work, and +# run each package's lint-staged in a subshell so cwd is scoped (a failure +# inside one package can't poison the cwd for the next). +cd "$(git rev-parse --show-toplevel)" || exit 1 + echo "Running lint-staged..." -cd client && npx lint-staged && cd .. -cd server && npx lint-staged && cd .. \ No newline at end of file +(cd client && npx lint-staged) || exit 1 +(cd server && npx lint-staged) || exit 1