]> git.armaanb.net Git - stagit.git/commitdiff
improve example, add initial post-receive example
authorHiltjo Posthuma <hiltjo@codemadness.org>
Sat, 15 Jul 2017 11:50:24 +0000 (13:50 +0200)
committerHiltjo Posthuma <hiltjo@codemadness.org>
Sat, 15 Jul 2017 11:50:24 +0000 (13:50 +0200)
example.sh
example_post-receive.sh [new file with mode: 0755]

index 84ccffd67eb3b5eff092fe05fb691e1f24b22449..57290d3fefdf56683025561bba685e352d3c1c54 100644 (file)
@@ -2,11 +2,14 @@
 # - Makes index for repositories in a single directory.
 # - Makes static pages for each repository directory.
 #
-# NOTE, things to do manually (once):
+# NOTE, things to do manually (once) before running this script:
 # - copy style.css, logo.png and favicon.png manually, a style.css example
 #   is included.
+#
 # - write clone url, for example "git://git.codemadness.org/dir" to the "url"
 #   file for each repo.
+# - write owner of repo to the "owner" file.
+# - write description in "description" file.
 #
 # Usage:
 # - mkdir -p htmldir && cd htmldir
diff --git a/example_post-receive.sh b/example_post-receive.sh
new file mode 100755 (executable)
index 0000000..38bda49
--- /dev/null
@@ -0,0 +1,65 @@
+#!/bin/sh
+# generic git post-receive hook.
+# change the config options below and call this script in your post-receive
+# hook or symlink it.
+#
+# usage: $0 [name]
+#
+# if name is not set the basename of the current directory is used,
+# this is the directory of the repo when called from the post-receive script.
+
+name="$1"
+if test "$name" = ""; then
+       name="$(basename $(pwd))"
+fi
+
+# config
+# paths must be absolute.
+reposdir="/home/src/src"
+dir="${reposdir}/${name}"
+htmldir="/home/www/domains/git.codemadness.org/htdocs"
+stagitdir="/"
+destdir="${htmldir}${stagitdir}"
+cachefile=".htmlcache"
+# /config
+
+if ! test -d "$dir"; then
+       echo "$dir does not exist" >&2
+       exit 1
+fi
+cd "$dir" || exit 1
+
+# detect git push -f
+force=0
+while read -r old new ref; do
+       hasrevs=$(git rev-list "$old" "^$new" | sed 1q)
+       if test -n "$hasrevs"; then
+               force=1
+               break
+       fi
+done
+
+# strip .git suffix.
+r=$(basename "${name}")
+d=$(basename "${name}" ".git")
+printf "[%s] stagit HTML pages... " "${d}"
+
+mkdir -p "${destdir}/${d}"
+cd "${destdir}/${d}" || exit 1
+
+# remove commits and $cachefile on git push -f, this recreated later on.
+if test "$force" = "1"; then
+       rm -f "${cachefile}"
+       rm -rf "commit"
+fi
+
+# make index.
+stagit-index "${reposdir}/"*/ > "${destdir}/index.html"
+# make pages.
+stagit -c "${cachefile}" "${reposdir}/${r}"
+
+ln -sf log.html index.html
+ln -sf ../style.css style.css
+ln -sf ../logo.png logo.png
+
+printf "done\n"