0
0
Gitdevops~10 mins

Client-side vs server-side hooks 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 list the directory where client-side hooks are stored in a Git repository.

Git
ls .git/[1]
Drag options to blanks, or click blank then click option'
Alogs
Brefs
Cobjects
Dhooks
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'refs' or 'objects' instead of 'hooks' directory.
Trying to find hooks outside the .git folder.
2fill in blank
medium

Complete the command to create a server-side pre-receive hook file in the bare Git repository.

Git
touch /srv/git/project.git/hooks/[1]
Drag options to blanks, or click blank then click option'
Apre-receive
Bpost-commit
Cpre-commit
Dcommit-msg
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing client-side hooks like pre-commit with server-side hooks.
Using post-commit which runs after commit, not on server push.
3fill in blank
hard

Fix the error in the client-side hook script filename to make it executable by Git.

Git
mv pre-commit.sample [1]
Drag options to blanks, or click blank then click option'
Aprecommit
Bpre-commit
Cpre_commit
Dpre-commit.sh
Attempts:
3 left
💡 Hint
Common Mistakes
Adding '.sh' extension which Git ignores.
Using underscores instead of hyphens.
4fill in blank
hard

Fill both blanks to create a client-side hook that prevents commits with empty messages.

Git
#!/bin/sh
if [ ! -s "$1" ]; then
  echo "Commit message is empty" >&2
  exit [1]
fi
exit [2]
Drag options to blanks, or click blank then click option'
A1
B0
C2
D255
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 to stop the commit, which actually allows it.
Using exit codes greater than 1 unnecessarily.
5fill in blank
hard

Fill all three blanks to define a server-side hook that rejects pushes to the main branch.

Git
#!/bin/sh
while read oldrev newrev refname; do
  if [ "$refname" = [1] ]; then
    echo "Pushes to [2] are not allowed." >&2
    exit [3]
  fi
 done
 exit 0
Drag options to blanks, or click blank then click option'
Arefs/heads/main
Bmain
C1
Drefs/tags/v1
Attempts:
3 left
💡 Hint
Common Mistakes
Using just 'main' instead of 'refs/heads/main' for refname comparison.
Exiting with 0 which allows the push.
Confusing tags with branches.