commit 26c75c8e0790d1eeb4907df196185130e07d6522
parent 06484836f139aef9bede0dd7016df923beb4a1fa
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 29 May 2025 18:12:50 +0200
git-publish: update checks on the post-receive hook
Until now, the hook was installed if no post-receive hook existed on the
repository or if the hook was strictly the same as the one to be
deployed. Thus, adding a simple slash to the base URL, which does not
modify the URL itself, nonetheless returned an error and required the
user to handle the problem manually.
From now on, a header is added to the post-receive script to
differentiate it from another hook. The header not only notifies that
the file comes from the git-publish command but also contains a checksum
of the template used to generate it, so that different versions of the
hook are considered different. In all other cases, it is assumed that
only the meta-variables are resolved and therefore that the script does
the same thing. The repository hook can therefore be safely replaced by
the new hook.
Diffstat:
2 files changed, 21 insertions(+), 14 deletions(-)
diff --git a/git-publish b/git-publish
@@ -131,17 +131,24 @@ setup_post_receive_hook()
{
hook="${GIT_PUBLISH_RESOURCES_PATH}/post-receive.in"
- # Generate the post-receive script
- sed -e "s#@DIR_GIT@#${dir_git}#g" \
- -e "s#@DIR_WWW@#${dir_www}#g" \
- -e "s#@BASE_URL@#${base_url}#g" \
- "${hook}" > "${tmpdir}/post-receive"
-
- if [ -e "${repo}/hooks/post-receive" ] \
- && ! diff "${repo}/hooks/post-receive" \
- "${tmpdir}/post-receive" > /dev/null; then
- >&2 printf 'post-receive hook already exist\n'
- return 1;
+ # Setup the hook header: it identifies the hook
+ digest="$(cksum "${hook}" | cut -d' ' -f1)"
+ header='# git-publish '"${digest}"
+
+ sed "2i ${header}" "${hook}" \
+ | sed -e "s#@DIR_GIT@#${dir_git}#g" \
+ -e "s#@DIR_WWW@#${dir_www}#g" \
+ -e "s#@BASE_URL@#${base_url}#g" \
+ > "${tmpdir}/post-receive"
+
+ if [ -e "${repo}/hooks/post-receive" ]; then
+ # Don't overwrite the repository's already configured post-receive
+ # hook if it hasn't been configured by git-publish.
+ header2="$(sed -n '2p' "${repo}/hooks/post-receive")"
+ if [ ! "${header}" = "${header2}" ]; then
+ >&2 printf 'another post-receive hook already exist\n'
+ return 1
+ fi
fi
cp "${tmpdir}/post-receive" "${repo}/hooks/post-receive"
diff --git a/post-receive.in b/post-receive.in
@@ -85,8 +85,8 @@ stagit-index "${reposdir}/"*/ > "${destdir}/index.html"
# make pages.
stagit -c "${cachefile}" -u "@BASE_URL@/$d/" "${reposdir}/${r}"
-ln -sf log.html index.html
-ln -sf ../style.css style.css
-ln -sf ../logo.png logo.png
+ln -sf './log.html' ./index.html
+ln -sf '../style.css' ./style.css
+ln -sf '../logo.png' ./logo.png
echo "done"