Challenge - 5 Problems
Commit Message Validator Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate1:30remaining
Output of a commit-msg hook script
Given this commit-msg hook script, what will be the output if the commit message is "Fix bug in login"?
Git
#!/bin/sh MESSAGE_FILE=$1 MESSAGE=$(cat "$MESSAGE_FILE") if echo "$MESSAGE" | grep -qE '^\[JIRA-[0-9]+\]'; then exit 0 else echo "Error: Commit message must start with a JIRA ticket ID like [JIRA-123]" exit 1 fi
Attempts:
2 left
💡 Hint
Check if the commit message starts with the required pattern.
✗ Incorrect
The script checks if the commit message starts with a pattern like [JIRA-123]. Since "Fix bug in login" does not start with that, it prints the error and exits with failure.
🧠 Conceptual
intermediate1:00remaining
Purpose of commit-msg hook
What is the main purpose of a commit-msg hook in Git?
Attempts:
2 left
💡 Hint
Think about what happens right after you write a commit message.
✗ Incorrect
The commit-msg hook runs after you write a commit message and before the commit is finalized. It is used to validate or modify the commit message.
❓ Troubleshoot
advanced1:30remaining
Why does the commit-msg hook not run?
You created a commit-msg hook script in .git/hooks/ but it does not run when committing. What is the most likely reason?
Attempts:
2 left
💡 Hint
Check file permissions for scripts in .git/hooks/
✗ Incorrect
Git only runs hook scripts that have executable permissions. If the script is not executable, Git ignores it.
🔀 Workflow
advanced2:00remaining
Implementing commit-msg hook for multiple rules
You want a commit-msg hook that enforces these rules:
1. Commit message must start with [PROJ-123]
2. Commit message must be at least 15 characters long
Which script correctly implements both checks?
1. Commit message must start with [PROJ-123]
2. Commit message must be at least 15 characters long
Which script correctly implements both checks?
Attempts:
2 left
💡 Hint
Both conditions must be true to pass validation.
✗ Incorrect
Option A checks each condition separately and exits with error if either fails. Other options have logic errors or inverted exit codes.
✅ Best Practice
expert2:00remaining
Best practice for sharing commit-msg hooks in a team
What is the best way to ensure all team members use the same commit-msg hook for message validation?
Attempts:
2 left
💡 Hint
Think about version controlling the hook and automating installation.
✗ Incorrect
Git does not version control .git/hooks/, so storing hooks in the repo and copying them during setup ensures consistency. Global hooks are possible but less flexible for project-specific rules.