Skip to content

Commit 84089be

Browse files
authored
Merge branch 'sahat:master' into master
2 parents cf11361 + d2dec54 commit 84089be

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

.husky/pre-commit

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,34 @@
1+
#!/bin/sh
2+
3+
# Save the list of currently staged files
4+
STAGED_FILES=$(git diff --cached --name-only)
5+
6+
# Check for staged files with unstaged modifications
7+
MODIFIED_FILES=$(git diff --name-only)
8+
9+
# Find files that overlap between staged and modified without using process substitution
10+
CONFLICTING_FILES=""
11+
for file in $STAGED_FILES; do
12+
if echo "$MODIFIED_FILES" | grep -qx "$file"; then
13+
CONFLICTING_FILES="$CONFLICTING_FILES$file\n"
14+
fi
15+
done
16+
17+
# Abort if there are conflicts
18+
if [ -n "$CONFLICTING_FILES" ]; then
19+
echo "Error: The following staged files have unstaged modifications, which can cause issues with the pre-commit eslint fix and prettier rewrite execution:"
20+
echo -e "$CONFLICTING_FILES" # Use -e for newline interpretation in echo
21+
echo "Please stage the changes or reset them before committing."
22+
echo "If this is a temporary local commit, you can also use the --no-verify flag to bypass the pre-commit test and linting. i.e. 'git commit --no-verify'"
23+
exit 1 # Abort commit
24+
fi
25+
26+
# Run tests and linting
127
npm test
228
npm run lint
29+
30+
# Re-stage files after lint fixes (only staged files)
31+
# Use a portable alternative for xargs
32+
echo "$STAGED_FILES" | while IFS= read -r file; do
33+
git add "$file"
34+
done

0 commit comments

Comments
 (0)