Tutorial: git - suc integration
In this tutorial, we see how alice gets notified on a suc channel when
someone pushes on one of her git repository.
1. Prerequisites
- This tutorial assumes that
alicehas agitrepository, see Tutorial: create a git repository. - Refer to A slack clone in 5 lines of bash for an explanation of how
sucworks
2. Conventions:
/srv/git/wonderland/- the path to
alice's repository, "git"- the name of the
succhannel in which to post the notifications.
3. Creating the hook
alice creates the /srv/git/wonderland/hooks/post-receive file with the following contents:
#!/usr/bin/env bash set -euo pipefail CHANNEL="git" # https://stackoverflow.com/questions/4774054/\ # reliable-way-for-a-bash-script-to-get-the-full-path-to-itself REPO_PATH="$( cd -- "$(dirname "$0")"/.. >/dev/null 2>&1 ; pwd -P )" while read -r oldrev newrev ref do echo ----------------------------------------------------------- | suc "$CHANNEL" echo In repo "$REPO_PATH", | suc "$CHANNEL" echo "$ref" went from "$oldrev" to "$newrev" | suc "$CHANNEL" git log --graph --color "$oldrev..$newrev" | suc "$CHANNEL" done
She then makes it executable:
chmod +x /srv/git/wonderland/hooks/post-receive
4. Checking that it works
alice monitors the git channel with e.g. a call to:
tail -f /var/lib/suc/git
and then she pushes some new commits to the wonderland repo.
She should see the commit messages appear in the suc channel.
She can then discuss the changes with her buddies bob and charlie.
5. Further reading
- The Pro Git book's section on hooks is worth reading, as it provides information on where and when the hooks are executed, and what one can expect to do with each one: https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks
- Atlassian's git hooks tutorial provide a gentler introduction to what hooks are: https://www.atlassian.com/git/tutorials/git-hooks
6. Advertisement
Did you like what you read ?
You can help me write more by:
- renting a guix VPS from me,
- hiring me for a consulting gig: software development, cybersecurity audit and training, cryptocurrency forensics, etc. see my personal page,
- letting me teach you Python, or spreading the word about this course,
- or buying a very, very secure laptop from me.
7. Changelog
- Make the hook script fit in 80 chars per line