iOS client for Grain grain.social
ios photography atproto
7
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(hooks): preserve unstaged changes during pre-commit format

Stash unstaged changes before running swiftformat/swiftlint so the
re-stage step doesn't clobber partial staging from git add -p. Pop
the stash on exit.

authored by

Hima Aramona and committed by
Chad Miller
7e2e6fdd 67f36877

+16
+16
.githooks/pre-commit
··· 4 4 FILES=$(git diff --cached --name-only --diff-filter=ACM -- '*.swift') 5 5 [ -z "$FILES" ] && exit 0 6 6 7 + # Stash unstaged changes so formatters only touch the index snapshot. 8 + # Without this, re-staging formatted files below would clobber any 9 + # partial staging from `git add -p`. 10 + STASHED=0 11 + if ! git diff --quiet; then 12 + git stash push --keep-index --quiet -m "pre-commit-$$" 13 + STASHED=1 14 + fi 15 + 16 + restore_unstaged() { 17 + [ "$STASHED" = "1" ] || return 0 18 + git stash pop --quiet 2>/dev/null || \ 19 + echo "pre-commit: could not auto-restore unstaged changes; run 'git stash pop' manually" >&2 20 + } 21 + trap restore_unstaged EXIT 22 + 7 23 echo "$FILES" | xargs swiftformat 2>/dev/null 8 24 echo "$FILES" | xargs swiftlint lint --fix 2>/dev/null | grep -v "^Linting\|^Done linting" 9 25 echo "$FILES" | xargs git add