fix(hooks): skip edit-log validation for in-progress merge commits#2100
Conversation
git commit refuses a partial-pathspec commit while MERGE_HEAD exists, so the edit-log check's own suggested workaround (commit specific files) is impossible during a merge. A merge commit also stages every auto-merged file from the incoming branch, not just files this session edited via tools, so the check's premise doesn't hold either. Skip validation when MERGE_HEAD is present.
| if [ -n "$MERGE_HEAD_PATH" ] && [ -f "$MERGE_HEAD_PATH" ]; then | ||
| exit 0 | ||
| fi |
There was a problem hiding this comment.
exit 0 skips any future commit checks added below this block
exit 0 terminates the entire script, so any commit-time validation added after the edit-log block in the future (lines 220–244) would also be silently bypassed during merge commits. Currently this is harmless because only the edit-log check remains, but it creates a latent footgun. Wrapping just the edit-log validation in its own if ! merge; then … fi guard, rather than exiting early, would make the bypass scope explicit and safe for future additions.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Good catch — reworked so the merge bypass only scopes the edit-log validation block instead of an early exit 0. The MERGE_IN_PROGRESS flag now gates an if [ "$MERGE_IN_PROGRESS" = false ]; then ... fi wrapper around just that check, so any commit-time validation added below it in the future will still run during merge commits. Pushed in a follow-up commit.
A bare file-existence check on MERGE_HEAD's path can be satisfied by any stray or hand-crafted file at that location, letting it be faked to bypass the edit-log validation added in the previous commit. Use git rev-parse --verify instead, which requires MERGE_HEAD to resolve to an actual object in this repo's object database.
Replace the early exit 0 for in-progress merges with an if [ "$MERGE_IN_PROGRESS" = false ] wrapper around just the edit-log validation, so any commit-time check added below it in the future still runs during merge commits instead of being silently skipped.
…to fix/guard-git-mergehead-skip Impact: 1 functions changed, 12 affected
Summary
guard-git.sh's commit-time edit-log validation blocks commits whose staged files don't match this session's tracked edits — protection against cross-session interference.MERGE_HEADpresent),git commitrefuses a partial-pathspec commit, so the check's own suggested workaround (commit specific files) is structurally impossible.MERGE_HEADexists, allowing legitimate merge commits through.Test plan
git commitwith no pathspec — confirm it's no longer blocked by the edit-log check