git » git-arr » commit 6f5f3c4

Add a post-receive hook

author Alberto Bertogli
2013-03-10 00:11:41 UTC
committer Alberto Bertogli
2013-03-12 22:09:25 UTC
parent c72278c97c15f30fb9cbcdcdd4c4fb84889a6b60

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>

hooks/README +14 -0
hooks/post-receive +58 -0

diff --git a/hooks/README b/hooks/README
new file mode 100644
index 0000000..c906f51
--- /dev/null
+++ b/hooks/README
@@ -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.
+
diff --git a/hooks/post-receive b/hooks/post-receive
new file mode 100755
index 0000000..f258338
--- /dev/null
+++ b/hooks/post-receive
@@ -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
+