From b744daa642b2a286de8d0129f525ff5e17fb594f Mon Sep 17 00:00:00 2001 From: Rachel Lee Nabors Date: Wed, 21 Jan 2026 00:13:03 +0000 Subject: [PATCH 1/2] Fix pre-commit hook to not stage unrelated working directory changes The update-links section was using `git diff --name-only` which captures ALL modified files in the working directory, not just files modified by the update-links script. This could accidentally stage files the user had modified but intentionally not staged for the current commit. Fix: Capture the list of already-modified files BEFORE running update-links, then only stage files that weren't already modified (i.e., files that became modified as a result of update-links). Co-Authored-By: Claude Opus 4.5 --- .husky/pre-commit | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index de35e84a2..4a877c0b4 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -63,13 +63,29 @@ fi if git diff --cached --name-only | grep -q "next.config.ts"; then echo "🔗 Updating internal links for new redirects..." + # Capture files already modified in working directory BEFORE running update-links + # This prevents accidentally staging unrelated changes the user has in progress + ALREADY_MODIFIED=$(git diff --name-only -- 'app/**/*.mdx' 'app/**/*.tsx' 'app/**/*.md' 2>/dev/null || true) + # Run the TypeScript update script if pnpm update-links 2>/dev/null; then - # Stage any files that were modified - UPDATED_FILES=$(git diff --name-only -- 'app/**/*.mdx' 'app/**/*.tsx' 'app/**/*.md' 2>/dev/null || true) - if [ -n "$UPDATED_FILES" ]; then - echo "$UPDATED_FILES" | xargs git add - echo "✅ Internal links updated and staged" + # Find files modified AFTER running update-links + NOW_MODIFIED=$(git diff --name-only -- 'app/**/*.mdx' 'app/**/*.tsx' 'app/**/*.md' 2>/dev/null || true) + + # Only stage files that were NOT already modified (i.e., newly modified by update-links) + STAGED_COUNT=0 + if [ -n "$NOW_MODIFIED" ]; then + for file in $NOW_MODIFIED; do + # Check if this file was already modified before update-links ran + if [ -z "$ALREADY_MODIFIED" ] || ! echo "$ALREADY_MODIFIED" | grep -qxF "$file"; then + git add "$file" + STAGED_COUNT=$((STAGED_COUNT + 1)) + fi + done + fi + + if [ "$STAGED_COUNT" -gt 0 ]; then + echo "✅ Internal links updated and staged ($STAGED_COUNT file(s))" fi fi fi From 4c5bf2088df71edc0ce14e17e69a15e30d93e5cf Mon Sep 17 00:00:00 2001 From: Rachel Lee Nabors Date: Wed, 21 Jan 2026 02:32:26 +0000 Subject: [PATCH 2/2] fixed overlooking modified files --- .husky/pre-commit | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.husky/pre-commit b/.husky/pre-commit index 4a877c0b4..bc0e5c1dc 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -74,12 +74,17 @@ if git diff --cached --name-only | grep -q "next.config.ts"; then # Only stage files that were NOT already modified (i.e., newly modified by update-links) STAGED_COUNT=0 + SKIPPED_FILES="" if [ -n "$NOW_MODIFIED" ]; then for file in $NOW_MODIFIED; do # Check if this file was already modified before update-links ran if [ -z "$ALREADY_MODIFIED" ] || ! echo "$ALREADY_MODIFIED" | grep -qxF "$file"; then git add "$file" STAGED_COUNT=$((STAGED_COUNT + 1)) + else + # File had both user's unstaged changes AND needed link updates + # We can't stage it without also staging user's unrelated changes + SKIPPED_FILES="$SKIPPED_FILES $file" fi done fi @@ -87,6 +92,19 @@ if git diff --cached --name-only | grep -q "next.config.ts"; then if [ "$STAGED_COUNT" -gt 0 ]; then echo "✅ Internal links updated and staged ($STAGED_COUNT file(s))" fi + + # Warn about files that needed link updates but couldn't be staged + if [ -n "$SKIPPED_FILES" ]; then + echo "" + echo "⚠️ Warning: The following files need link updates but have unstaged changes:" + for file in $SKIPPED_FILES; do + echo " - $file" + done + echo "" + echo " The link updates were applied but NOT staged to avoid mixing with your changes." + echo " After this commit, review these files and stage the link updates separately," + echo " or run 'git checkout -- ' to discard all changes including link updates." + fi fi fi