0
0
Gitdevops~10 mins

commit-msg hook for message validation in Git - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to make the commit-msg hook executable.

Git
chmod +[1] .git/hooks/commit-msg
Drag options to blanks, or click blank then click option'
Ax
Br
Cw
Da
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'r' or 'w' instead of 'x' for execute permission.
Forgetting to set execute permission causes the hook not to run.
2fill in blank
medium

Complete the script line to read the commit message file path passed to the commit-msg hook.

Git
commit_msg_file=[1]
Drag options to blanks, or click blank then click option'
A$2
B$0
C$1
D$#
Attempts:
3 left
💡 Hint
Common Mistakes
Using $0 which is the script name, not the argument.
Using $2 or $# which are not the first argument.
3fill in blank
hard

Fix the error in the regex check line to validate commit message starts with a capital letter.

Git
if ! head -1 "$commit_msg_file" | grep -qE '^[1]'; then
Drag options to blanks, or click blank then click option'
A[A-Z]
B[a-z]
C[0-9]
D[A-Z]+"
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase letters in regex when uppercase is required.
Using quantifiers like '+' unnecessarily here.
4fill in blank
hard

Fill both blanks to reject commit messages shorter than 10 characters.

Git
msg_length=$(wc -c < "$commit_msg_file")
if [ "$msg_length" [1] [2] ]; then
Drag options to blanks, or click blank then click option'
A-lt
B>
C10
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using > instead of -lt causing wrong logic.
Using 5 instead of 10 as length threshold.
5fill in blank
hard

Fill all three blanks to print an error and exit with status 1 if validation fails.

Git
echo "[1]"
exit [2]
# End of hook [3]
Drag options to blanks, or click blank then click option'
AError: Commit message invalid.
B1
Cscript
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Exiting with 0 which means success.
Not printing any error message.