Skip to content

Commit

Permalink
Fix pre-commit hook to handle errors and restore files if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
EladCirtPhilips committed Apr 25, 2024
1 parent 0a0b6e0 commit a912054
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
#!/bin/sh

# This script runs the 'npm run all' command
exit_code=0

# Run the npm command
npm run all

# Check the exit status and handle errors if needed
if [ $? -ne 0 ]; then
echo "An error occurred while running 'npm run all'."
exit 1
exit_code=1
fi

# Check for any changes in the dist/ directory
if [ "$(git diff --ignore-space-at-eol --text dist/ | wc -l)" -gt "0" ]; then
echo "The 'npm run all' command has modified the dist/ directory. Please run 'npm run all' locally and commit the changes."

# Restore the files that changed after running 'npm run all'
git restore --staged --worktree dist/index.js dist/index.js.map badges/coverage.svg
exit 1
exit_code=1
fi

# Restore the files that changed after running 'npm run all'
git restore --staged --worktree dist/index.js dist/index.js.map badges/coverage.svg

exit $exit_code

0 comments on commit a912054

Please sign in to comment.