Complete the code to create a pre-commit hook script that runs before a commit.
#!/bin/sh [1]
The pre-commit hook script should start by printing a message to indicate it is running checks before the commit.
Complete the code to prevent a commit if a Python file contains syntax errors.
for file in $(git diff --cached --name-only --diff-filter=ACM | grep '\.py$'); do python -m py_compile $[1] || exit 1 done
The variable file holds the filename in the loop and is used to check syntax.
Fix the error in the pre-commit hook that tries to run tests but fails due to wrong command.
echo "Running tests..." [1] if [ $? -ne 0 ]; then echo "Tests failed, aborting commit." exit 1 fi
npm test which may work but is less explicit.npm tests.The correct command to run tests with npm is npm run test.
Fill both blanks to create a pre-commit hook that checks for trailing whitespace and aborts commit if found.
if git diff --cached --check | grep [1]; then echo "Trailing whitespace found in [2]. Commit aborted." exit 1 fi
The --quiet option makes grep silent but returns status. The message refers to staged files where the whitespace was found.
Fill all three blanks to create a pre-commit hook that formats Python files with black and adds them back to staging.
for file in $(git diff --cached --name-only --diff-filter=ACM | grep '\.py$'); do black [1] git add [2] done exit [3]
The variable $file is used to format and add each Python file. The script exits with 0 to allow the commit.