#!/bin/sh
# =============================================================================
# Post-Commit Hook: Sync working tree with committed content
# =============================================================================
#
# WHY THIS EXISTS:
# pre-commit's trailing-whitespace and end-of-file-fixer hooks auto-modify
# files on disk. The stash/pop cycle restores the working tree to its
# pre-hook state, overwriting changes (e.g. from Claude Code's Edit tool).
# This causes "phantom reverts" — files appear reverted in working tree
# even though committed content is correct.
#
# This hook forces the working tree to match what was actually committed.
# =============================================================================

# Get files changed in the commit that just landed
changed_files=$(git diff-tree --no-commit-id --name-only -r HEAD 2>/dev/null)

if [ -n "$changed_files" ]; then
    echo "$changed_files" | xargs git checkout HEAD -- 2>/dev/null || true
fi
