git-repo

Tools for sharing git bare repositories
git clone git://git.meso-star.fr/git-repo.git
Log | Files | Refs | README | LICENSE

commit c30191e15cb3e3de4bb4a67a78d560e3be9c71ef
parent 342c3d07d2a4b86159c96cbf3ac04a5d29e675f1
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri, 30 May 2025 15:20:56 +0200

git-publish: temp directory no longer used

It was used to store the post-receive hook generated before checking
that it could replace a hook already installed. Since commit 26c75c8,
hook conflicts are detected from a header, and no longer from file
contents. The temporary file is therefore no longer needed, and can be
generated directly in the repository or not, depending on header
conflicts.

Diffstat:
Mgit-publish | 35++++++++++++++++-------------------
1 file changed, 16 insertions(+), 19 deletions(-)

diff --git a/git-publish b/git-publish @@ -35,15 +35,9 @@ fi ######################################################################## die() { - rm -rf "${tmpdir}" # cleanup temporary files exit "${1:-1}" # return status code (default is 1) } -# Configure signal processing -trap 'die $?' EXIT - -tmpdir="$(mktemp -d "${TMPDIR:-/tmp}/git_publish_XXXXXX")" - synopsis() { >&2 printf \ @@ -135,12 +129,6 @@ setup_post_receive_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. @@ -151,7 +139,12 @@ setup_post_receive_hook() fi fi - cp "${tmpdir}/post-receive" "${repo}/hooks/post-receive" + 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" \ + > "${repo}/hooks/post-receive" + chmod 755 "${repo}/hooks/post-receive" } @@ -161,23 +154,25 @@ setup_post_receive_hook() base_url="${GIT_PUBLISH_BASE_URL:-}" dir_git="${GIT_PUBLISH_DIR_GIT:-/srv/git}" dir_www="${GIT_PUBLISH_DIR_WWW:-/srv/www/git}" +force=0 # Force HTML generation # Parse input arguments OPTIND=1 -while getopts ":g:u:w:" opt; do +while getopts ":fg:u:w:" opt; do case "${opt}" in + f) force=1 ;; u) base_url="${OPTARG}" ;; g) dir_git="${OPTARG}" ;; # git directory w) dir_www="${OPTARG}" ;; # WWW directory - *) synopsis; exit 1 ;; + *) synopsis; die ;; esac done # Check mandatory options -[ "${OPTIND}" -le $# ] || { synopsis; exit 1; } -[ -n "${base_url}" ] || { >&2 printf 'Base url is missing\n'; exit 1; } -[ -n "${dir_git}" ] || { >&2 printf 'git directory is missing\n'; exit 1; } -[ -n "${dir_www}" ] || { >&2 printf 'WWW directory is missing\n'; exit 1; } +[ "${OPTIND}" -le $# ] || { synopsis; die; } +[ -n "${base_url}" ] || { >&2 printf 'Base url is missing\n'; die; } +[ -n "${dir_git}" ] || { >&2 printf 'git directory is missing\n'; die; } +[ -n "${dir_www}" ] || { >&2 printf 'WWW directory is missing\n'; die; } check_directory "${dir_git}" check_directory "${dir_www}" @@ -196,3 +191,5 @@ done # [Re]generate index of publicly exposed repositories stagit-index "${dir_git}/"*/ > "${dir_www}/index.html" + +die 0