repo2html/assets/post-receive
m455 907516d1d6 Updated documentation and cleaned up directory tree
- Updated documentation, so it's very nice for pho4cexa <3
- Moved helper/example files to an assets directory (feel free to
  rearrange all of these again if you have any better ideas :D
- Renamed and moved tutorial file to make it more descriptive
- Removed old environment variables from post-receive hook example file
2022-12-20 00:56:30 -05:00

53 lines
1.9 KiB
Bash
Executable file

#!/bin/sh
# - place this file in the 'hooks' directory of a bare git repository
# - this assumes that repo2html is in your path
# The toplevel path containing directories of static pages
[ "$REPO2HTML_PREFIX" ] || export REPO2HTML_PREFIX=/var/www/git
# The toplevel clone url for repos.
export REPO2HTML_DESCRIPTION="sherry's git repositories"
# hueristic attempt to detect a reasonable default for the name of this repo
# you may want to adjust this if you have e.g. sub-directories containing repos
# whose structure you want to preserve on the webserver.
if repo_name="$(git config repo2html.dirname)"; then
: # repo name from git config; do nothing else
elif [ "$(git rev-parse --is-bare-repository)" = "true" ]; then
# bare /foo/bar/baz/myrepo.git -> myrepo
repo_name="$(basename "$(pwd)" .git)"
git config repo2html.dirname "$repo_name"
else
# /foo/bar/baz/myrepo/.git -> myrepo
repo_name="$(basename "$(dirname "$(pwd)")")"
git config repo2html.dirname "$repo_name"
fi
# only generate if default branch is modified
headref="$(git symbolic-ref -q HEAD)"
while read -r _ _ ref
do [ "$ref" = "$headref" ] && go=1
done
if [ "$go" ]; then
echo "$headref was updated; regenerating HTML at: $REPO2HTML_PREFIX/$repo_name"
else
echo "($headref was not updated so HTML will not be regenerated.)"
exit 0
fi
# check to see if we can even write to the specified directory
if mkdir -p "$REPO2HTML_PREFIX/$repo_name" && \
[ -x "$REPO2HTML_PREFIX/$repo_name" ] && \
[ -w "$REPO2HTML_PREFIX/$repo_name" ]
then
: # we can write to the directory; seems good
else
echo "Error: can't generate HTML due to insufficient permissions on path:"
echo " $REPO2HTML_PREFIX/$repo_name"
echo "Set REPO2HTML_PREFIX in the environment or this script:"
echo " $0"
exit 1
fi
# the second argument here should be a directory containing "default.html"
repo2html "$REPO2HTML_PREFIX/$repo_name" "path/to/directory/containing/template"