Complete the code to create a Git hook script that runs before a commit.
#!/bin/sh [1]
This script prints a message before a commit is made, showing the hook runs automatically.
Complete the code to make a pre-push hook that prevents pushing if tests fail.
#!/bin/sh if ! [1]; then echo "Tests failed, push aborted." exit 1 fi
The hook runs tests using 'make test'. If tests fail, it stops the push.
Fix the error in this commit-msg hook that rejects empty commit messages.
#!/bin/sh if [ -z "$(cat [1])" ]; then echo "Empty commit message not allowed." exit 1 fi
The commit message file path is passed as the first argument ($1) to the hook script.
Fill both blanks to create a post-commit hook that logs the commit hash.
#!/bin/sh commit_hash=$(git [1] -1 --format=%H) echo "Commit [2]: $commit_hash" >> commit_log.txt
'git log -1 --format=%H' gets the latest commit hash. The script logs it with a message.
Fill all three blanks to create a pre-receive hook that rejects pushes to the main branch.
#!/bin/sh while read oldrev newrev refname; do if [ "$refname" = [1] ]; then echo "Pushes to [2] are not allowed." exit [3] fi done
The hook checks if the refname equals 'refs/heads/main' and rejects the push with exit code 1.