Add a post-receive hook

This patch adds a post-receive hook that can be used to trigger a git-arr
update when there is a push to a repository.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
This commit is contained in:
Alberto Bertogli 2013-03-10 00:11:41 +00:00
parent c72278c97c
commit 6f5f3c4aa5
2 changed files with 72 additions and 0 deletions

14
hooks/README Normal file

@ -0,0 +1,14 @@
You can use the post-receive hook to automatically generate the repository
view after a push.
To do so, configure in your target repository the following options:
$ git config hooks.git-arr-config /path/to/site.conf
$ git config hooks.git-arr-output /var/www/git/
# Only if the git-arr executable is not on your $PATH.
$ git config hooks.git-arr-path /path/to/git-arr
Then copy the post-receive file to the "hooks" directory in your repository.

58
hooks/post-receive Executable file

@ -0,0 +1,58 @@
#!/bin/sh
#
# git-arr post-receive hook
#
# This is a script intended to be used as a post-receive hook, which updates
# its git-arr view.
#
# You should place it /path/to/your/repository.git/hooks/.
# Config
# --------
#
# hooks.git-arr-config
# The git-arr configuration file to use. Mandatory.
# Example: /srv/git-arr/site.conf
#
# hooks.git-arr-output
# Directory for the generated output. Mandatory.
# Example: /srv/www/git/
#
# hooks.git-arr-path
# The path to the git-arr executable. Optional, defaults to "git-arr".
#
# hooks.git-arr-repo-name
# The git-arr repository name. Optional, defaults to the path name.
git_arr_config="$(git config --path hooks.git-arr-config)"
git_arr_output="$(git config --path hooks.git-arr-output)"
git_arr_path="$(git config --path hooks.git-arr-path 2> /dev/null)"
git_arr_repo_name="$(git config hooks.git-arr-repo-name 2> /dev/null)"
if [ -z "$git_arr_config" -o -z "$git_arr_output" ]; then
echo "Error: missing config options."
echo "Both hooks.git-arr-config and hooks.git-arr-output must be set."
exit 1
fi
if [ -z "$git_arr_path" ]; then
git_arr_path=git-arr
fi
if [ -z "$git_arr_repo_name" ]; then
PARENT_DIR=$(cd $(dirname "$0")/..; echo "$PWD")
git_arr_repo_name=$(basename "$PARENT_DIR")
fi
echo "Running git-arr"
$git_arr_path --config "$git_arr_config" generate \
--output "$git_arr_output" \
--only "$git_arr_repo_name" > /dev/null
RESULT=$?
if [ $RESULT -ne 0 ]; then
echo "Error running git-arr"
exit $RESULT
fi