git-barepo

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

commit 344d45f0c1fa1bcaf12b5fee0ccfe6e1c7ee80d2
parent 5ecab2777d7705e4e9e6d6e0bc09bd25443d01db
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Tue, 26 May 2026 16:25:17 +0200

git-publish: test the publication of multiple repos

Diffstat:
MMakefile | 4+++-
Atest_publish_multi.sh | 195+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 198 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile @@ -59,10 +59,12 @@ lint: shellcheck -o all git-barepo shellcheck -o all test_barepo.sh shellcheck -o all test_publish.sh + shellcheck -o all test_publish_multi.sh shellcheck -o all post-receive.in - mandoc -Tlint -Wwarning git-publish.1 mandoc -Tlint -Wwarning git-barepo.1 + mandoc -Tlint -Wwarning git-publish.1 test: $(SHELL) test_barepo.sh 1> /dev/null 2>&1 $(SHELL) test_publish.sh 1> /dev/null 2>&1 + $(SHELL) test_publish_multi.sh 1> /dev/null 2>&1 diff --git a/test_publish_multi.sh b/test_publish_multi.sh @@ -0,0 +1,195 @@ +#!/bin/sh + +# Copyright (C) 2024-2026 |Méso|Star> (contact@meso-star.com) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +set -ex + +die() +{ + rm -rf "${tmpdir}" # cleanup temporary files + return "${1:-1}" # return status code (default is 1) +} + +# Configure signal processing +trap 'die $?' EXIT +trap 'die 1' TERM INT + +# Working directory +tmpdir="$(mktemp -d "${TMPDIR:-/tmp}"/git_publish_test_XXXXXX)" +gitdir="${tmpdir}/git" +srvdir="${tmpdir}/srv" + +mkdir -p "${gitdir}" "${srvdir}/www" "${srvdir}/git" + +# Use the local git-publish +export PATH="${PWD}:${PATH}" + +######################################################################## +# Helper functions +######################################################################## +create_git_bare_repo() # name +{ + _repo="${tmpdir}/$1" + _git="${gitdir}/$1.git" + + mkdir -p "${_git}" + git init --bare --initial-branch=master "${_git}" 1>&2 + + # Create the repository content + mkdir -p "${_repo}" + printf 'Repository %s\n' "$1" > "${_repo}/README.txt" + cksum "${_repo}/README.txt" | cut -d' ' -f1 > "${_repo}/cookie.txt" + + # Push the content to the git bare repository + cd "${_repo}" + { + git init --initial-branch=master + git config --local user.name "Mme Lambda" + git config --local user.email "mme@lambda.fr" + git add README.txt cookie.txt + git commit -m "Test content for publishing multiple repositories" + git remote add origin "file://${_git}" + git push origin master + } 1>&2 + cd "${OLDPWD}" + + # Output the value of the repository's cookie + cat "${_repo}/cookie.txt" + + rm -rf "${_repo}" # Clean up +} + +check_git_content() # repo-url, cookie +{ + _name=$(basename "$1" ".git") + git clone "$1" "${tmpdir}/${_name}" + + [ -f "${tmpdir}/${_name}/README.txt" ] + [ -f "${tmpdir}/${_name}/cookie.txt" ] + + _cookie="$(cat "${tmpdir}/${_name}/cookie.txt")" + [ "${_cookie}" = "$2" ] + + rm -rf "${tmpdir:?}/${_name}" +} + +check_www_content() # repo +{ + [ -f "${srvdir}/www/index.html" ] + [ -d "${srvdir}/www/$1" ] + [ -f "${srvdir}/www/$1/index.html" ] +} + +######################################################################## +# Setup repository +######################################################################## +cookie1="$(create_git_bare_repo "repo01")" +cookie2="$(create_git_bare_repo "repo02")" +cookie3="$(create_git_bare_repo "repo03")" + +######################################################################## +# The tests +######################################################################## +git publish \ + -g "${srvdir}/git" \ + -w "${srvdir}/www" \ + -u "http://mme.lambda.fr" \ + "${gitdir}"/*.git + +# The published repositories are symlinks +[ -L "${srvdir}/git/repo01.git" ] +[ -L "${srvdir}/git/repo02.git" ] +[ -L "${srvdir}/git/repo03.git" ] + +check_git_content "file://${srvdir}/git/repo01.git" "${cookie1}" +check_git_content "file://${srvdir}/git/repo02.git" "${cookie2}" +check_git_content "file://${srvdir}/git/repo03.git" "${cookie3}" +check_www_content "repo01" +check_www_content "repo02" +check_www_content "repo03" + +# From now on, use environment variables +export GIT_PUBLISH_DIR_GIT="${srvdir}/git" +export GIT_PUBLISH_DIR_WWW="${srvdir}/www" +export GIT_PUBLISH_BASE_URL="http://mme.lambda.fr" + +# Unpublish one repository +git publish -d "${gitdir}"/repo01.git +[ ! -e "${srvdir}/git/repo01.git" ] +[ ! -e "${srvdir}/www/repo01" ] +[ -d "${gitdir}/repo01.git" ] && [ ! -L "${gitdir}/repo01.git" ] +[ -d "${gitdir}/repo01.git" ] && [ ! -L "${gitdir}/repo01.git" ] +[ -f "${srvdir}/www/index.html" ] # There is still published repositories + +# Unpublished the remaining repositories +git publish -d "${gitdir}"/repo0[2,3].git +[ ! -e "${srvdir}/git/repo02.git" ] +[ ! -e "${srvdir}/git/repo03.git" ] +[ -d "${gitdir}/repo02.git" ] && [ ! -L "${gitdir}/repo02.git" ] +[ -d "${gitdir}/repo03.git" ] && [ ! -L "${gitdir}/repo03.git" ] +[ ! -e "${srvdir}/www/index.html" ] # No more index since no more repo + +# Publish the repositories by moving the source repositories +git publish -m "${gitdir}/"*.git + +# The published repositories are symlinks +[ -d "${srvdir}/git/repo01.git" ] && [ ! -L "${srvdir}/git/repo01.git" ] +[ -d "${srvdir}/git/repo02.git" ] && [ ! -L "${srvdir}/git/repo02.git" ] +[ -d "${srvdir}/git/repo03.git" ] && [ ! -L "${srvdir}/git/repo03.git" ] + +# The original repositories are symlinks +[ -L "${gitdir}/repo01.git" ] +[ -L "${gitdir}/repo02.git" ] +[ -L "${gitdir}/repo03.git" ] + +check_git_content "file://${srvdir}/git/repo01.git" "${cookie1}" +check_git_content "file://${srvdir}/git/repo02.git" "${cookie2}" +check_git_content "file://${srvdir}/git/repo03.git" "${cookie3}" +check_git_content "file://${gitdir}/repo01.git" "${cookie1}" +check_git_content "file://${gitdir}/repo02.git" "${cookie2}" +check_git_content "file://${gitdir}/repo03.git" "${cookie3}" +check_www_content "repo01" +check_www_content "repo02" +check_www_content "repo03" + +# Unpublish all repositories +git publish -d "${gitdir}"/*.git +[ ! -e "${srvdir}/git/repo01.git" ] +[ ! -e "${srvdir}/git/repo02.git" ] +[ ! -e "${srvdir}/git/repo03.git" ] +[ ! -e "${srvdir}/www/index.html" ] # No more index since no more repo + +# Check the original repositories are directories and remain valid after +# their unpublication +[ -d "${gitdir}/repo01.git" ] && [ ! -L "${gitdir}/repo01.git" ] +[ -d "${gitdir}/repo02.git" ] && [ ! -L "${gitdir}/repo02.git" ] +[ -d "${gitdir}/repo03.git" ] && [ ! -L "${gitdir}/repo03.git" ] +check_git_content "file://${gitdir}/repo01.git" "${cookie1}" +check_git_content "file://${gitdir}/repo02.git" "${cookie2}" +check_git_content "file://${gitdir}/repo03.git" "${cookie3}" + +# Prevent the publication of repo02 +touch "${gitdir}/repo02.git/publication_ban" +git publish "${gitdir}"/*.git +[ -d "${srvdir}/git/repo01.git" ] +[ ! -e "${srvdir}/git/repo02.git" ] +[ -d "${srvdir}/git/repo03.git" ] + +# Unpublish repo01 and repo03 +git publish -d "${gitdir}"/repo0[1,3].git +[ ! -e "${srvdir}/git/repo01.git" ] +[ ! -e "${srvdir}/git/repo02.git" ] +[ ! -e "${srvdir}/git/repo03.git" ]