0
0
Gitdevops~10 mins

Creating custom hook scripts in Git - Interactive Practice

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

Complete the code to make a Git hook script executable.

Git
chmod [1] .git/hooks/pre-commit
Drag options to blanks, or click blank then click option'
A+x
B-x
C-r
D+r
Attempts:
3 left
💡 Hint
Common Mistakes
Using -x instead of +x disables execute permission.
Using read permission flags like +r instead of execute.
2fill in blank
medium

Complete the first line of a Git hook script to specify the shell interpreter.

Git
#![1]/sh
Drag options to blanks, or click blank then click option'
A/bin
B/usr
C/sbin
D/etc
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect interpreter paths like /usr/bin or /etc.
Omitting the shebang line.
3fill in blank
hard

Fix the error in the Git hook script line that prevents commit if a file named TODO exists.

Git
if [ -f [1] ]; then
  echo "Please resolve TODOs before commit."
  exit 1
fi
Drag options to blanks, or click blank then click option'
A'TODO'
B"TODO"
CTODO
Dtodo
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around the file name inside the test brackets.
Using wrong file name case.
4fill in blank
hard

Fill both blanks to create a pre-commit hook that checks for 'TODO' in staged files and blocks commit.

Git
if git diff --cached | grep -q [1]; then
  echo [2]
  exit 1
fi
Drag options to blanks, or click blank then click option'
ATODO
B"Commit blocked: TODO found in files."
C"All clear."
DFIXME
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong search string in grep.
Printing a message that does not explain the block.
5fill in blank
hard

Fill all three blanks to create a post-commit hook that logs the last commit message to a file.

Git
git log -1 --pretty=[1] > [2]
echo "Logged commit message to [3]"
Drag options to blanks, or click blank then click option'
A"%B"
Bcommit_message.log
D"%s"
Attempts:
3 left
💡 Hint
Common Mistakes
Using %s which only shows the commit subject.
Mismatching file names in redirection and echo message.