Challenge - 5 Problems
Git Hook Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
Output of a pre-commit hook script
You have a pre-commit hook script that checks for TODO comments in staged files. What will be the output if a staged file contains a TODO comment?
Git
#!/bin/sh if git diff --cached | grep -q 'TODO'; then echo "Commit blocked: TODO comments found." exit 1 fi exit 0
Attempts:
2 left
💡 Hint
The script blocks commits if TODO comments are detected in staged changes.
✗ Incorrect
The script searches staged changes for 'TODO'. If found, it prints a message and exits with status 1, blocking the commit.
🧠 Conceptual
intermediate1:30remaining
Purpose of Git hook scripts
What is the primary purpose of creating custom Git hook scripts?
Attempts:
2 left
💡 Hint
Think about what happens automatically when you commit or push.
✗ Incorrect
Git hooks run scripts automatically on certain Git events to automate checks or tasks.
❓ Configuration
advanced1:30remaining
Correct placement of a custom Git hook script
Where should you place a custom hook script named 'pre-push' to ensure Git runs it before pushing?
Attempts:
2 left
💡 Hint
Git looks for hooks inside a specific directory within the repository.
✗ Incorrect
Git hook scripts must be placed inside the .git/hooks directory with the exact hook name.
❓ Troubleshoot
advanced2:00remaining
Why a Git hook script is not running
You created a 'post-commit' hook script but it does not run after commits. What is the most likely reason?
Attempts:
2 left
💡 Hint
Git requires hook scripts to have execute permissions.
✗ Incorrect
If the hook script is not executable, Git will ignore it and not run it.
🔀 Workflow
expert2:30remaining
Sequence of Git hook scripts during a commit
What is the correct order of Git hook scripts triggered during a commit?
Attempts:
2 left
💡 Hint
Some hooks run before the commit message is prepared.
✗ Incorrect
The order is: prepare-commit-msg, pre-commit, commit-msg, then post-commit.