]> git.armaanb.net Git - stagit.git/blobdiff - example_post-receive.sh
Redirect stdout to correct file.
[stagit.git] / example_post-receive.sh
index 38bda4932ee2da639075aac5e3b199644459b4ae..c9bcb5e61d048a455652c5d197486bfd82b2e1a2 100755 (executable)
@@ -8,9 +8,13 @@
 # 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.
 
+# NOTE: needs to be set for correct locale (expects UTF-8) otherwise the
+#       default is LC_CTYPE="POSIX".
+export LC_CTYPE="en_US.UTF-8"
+
 name="$1"
-if test "$name" = ""; then
-       name="$(basename $(pwd))"
+if test "${name}" = ""; then
+       name=$(basename "$(pwd)")
 fi
 
 # config
@@ -23,17 +27,20 @@ destdir="${htmldir}${stagitdir}"
 cachefile=".htmlcache"
 # /config
 
-if ! test -d "$dir"; then
-       echo "$dir does not exist" >&2
+if ! test -d "${dir}"; then
+       echo "${dir} does not exist" >&2
        exit 1
 fi
-cd "$dir" || exit 1
+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
+       test "${old}" = "0000000000000000000000000000000000000000" && continue
+       test "${new}" = "0000000000000000000000000000000000000000" && continue
+
+       hasrevs=$(git rev-list "${old}" "^${new}" | sed 1q)
+       if test -n "${hasrevs}"; then
                force=1
                break
        fi
@@ -47,14 +54,15 @@ 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
+# 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}"
 
@@ -62,4 +70,4 @@ ln -sf log.html index.html
 ln -sf ../style.css style.css
 ln -sf ../logo.png logo.png
 
-printf "done\n"
+echo "done"