0
0
Gitdevops~20 mins

Creating custom hook scripts in Git - Practice Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Git Hook Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2: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
ACommit successful with TODO comments.
BSyntax error in hook script.
CNo output, commit proceeds.
DCommit blocked: TODO comments found.
Attempts:
2 left
💡 Hint
The script blocks commits if TODO comments are detected in staged changes.
🧠 Conceptual
intermediate
1:30remaining
Purpose of Git hook scripts
What is the primary purpose of creating custom Git hook scripts?
ATo automate tasks during Git events like commit or push.
BTo change the Git repository URL.
CTo increase the size of the Git repository.
DTo create new branches automatically.
Attempts:
2 left
💡 Hint
Think about what happens automatically when you commit or push.
Configuration
advanced
1: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?
A.git/hooks/pre-push
B.git/pre-push
Chooks/pre-push
Dpre-push/.git/hooks
Attempts:
2 left
💡 Hint
Git looks for hooks inside a specific directory within the repository.
Troubleshoot
advanced
2: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?
AGit does not support post-commit hooks.
BThe script is placed in the wrong directory.
CThe script file is not executable.
DThe repository is not initialized.
Attempts:
2 left
💡 Hint
Git requires hook scripts to have execute permissions.
🔀 Workflow
expert
2:30remaining
Sequence of Git hook scripts during a commit
What is the correct order of Git hook scripts triggered during a commit?
A1,2,3,4
B2,1,3,4
C2,3,1,4
D1,3,2,4
Attempts:
2 left
💡 Hint
Some hooks run before the commit message is prepared.