git.m455.casa

repo2html

clone url: git://git.m455.casa/repo2html


assets/post-receive

1 #!/bin/sh
2
3 # - place this file in the 'hooks' directory of a bare git repository
4 # - this assumes that repo2html is in your path
5
6 # The toplevel path containing directories of static pages
7 [ "$REPO2HTML_PREFIX" ] || export REPO2HTML_PREFIX=/var/www/git
8 # The toplevel clone url for repos.
9 export REPO2HTML_DESCRIPTION="sherry's git repositories"
10
11 # hueristic attempt to detect a reasonable default for the name of this repo
12 # you may want to adjust this if you have e.g. sub-directories containing repos
13 # whose structure you want to preserve on the webserver.
14 if repo_name="$(git config repo2html.dirname)"; then
15 : # repo name from git config; do nothing else
16 elif [ "$(git rev-parse --is-bare-repository)" = "true" ]; then
17 # bare /foo/bar/baz/myrepo.git -> myrepo
18 repo_name="$(basename "$(pwd)" .git)"
19 git config repo2html.dirname "$repo_name"
20 else
21 # /foo/bar/baz/myrepo/.git -> myrepo
22 repo_name="$(basename "$(dirname "$(pwd)")")"
23 git config repo2html.dirname "$repo_name"
24 fi
25
26 # only generate if default branch is modified
27 headref="$(git symbolic-ref -q HEAD)"
28 while read -r _ _ ref
29 do [ "$ref" = "$headref" ] && go=1
30 done
31 if [ "$go" ]; then
32 echo "$headref was updated; regenerating HTML at: $REPO2HTML_PREFIX/$repo_name"
33 else
34 echo "($headref was not updated so HTML will not be regenerated.)"
35 exit 0
36 fi
37
38 # check to see if we can even write to the specified directory
39 if mkdir -p "$REPO2HTML_PREFIX/$repo_name" && \
40 [ -x "$REPO2HTML_PREFIX/$repo_name" ] && \
41 [ -w "$REPO2HTML_PREFIX/$repo_name" ]
42 then
43 : # we can write to the directory; seems good
44 else
45 echo "Error: can't generate HTML due to insufficient permissions on path:"
46 echo " $REPO2HTML_PREFIX/$repo_name"
47 echo "Set REPO2HTML_PREFIX in the environment or this script:"
48 echo " $0"
49 exit 1
50 fi
51
52 # the second argument here should be a directory containing "default.html"
53 repo2html "$REPO2HTML_PREFIX/$repo_name" "path/to/directory/containing/template"