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

2. Conventions:

/srv/git/wonderland/
the path to alice's repository,
"git"
the name of the suc channel 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

6. Advertisement

Did you like what you read ?

You can help me write more by:

7. Changelog

  • <2024-04-02 Tue> Make the hook script fit in 80 chars per line