git-barepo

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

commit 57fe1703a13bf8c2ed88ede55167c440166a1a75
parent da044df911eb163a543341887c5f18ce6cd1736e
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Sun, 24 May 2026 16:30:18 +0200

git-publish: add tests

They verify that the publication of a repository proceeds as expected,
whether it was published using the default behavior - that is, with the
published repository linked to the original - or by moving it to the
public directory and converting the original path into a link to it.

Particular attention has been paid to this latter behavior, as
repository data is moved to (publishing) or from (unpublishing) the
public directory. A bug that overlooks the fact that the public
repository is not necessarily a symbolic link could result in
catastrophic data loss.

Further testing should be conducted to improve coverage of edge cases
and ensure, as much as possible, that no data is at risk of being
deleted.

Diffstat:
MMakefile | 4++++
Atest_publish.sh | 155+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 159 insertions(+), 0 deletions(-)

diff --git a/Makefile b/Makefile @@ -57,6 +57,10 @@ uninstall: lint: shellcheck -o all git-publish shellcheck -o all git-barepo + shellcheck -o all test_publish.sh shellcheck -o all post-receive.in mandoc -Tlint -Wwarning git-publish.1 mandoc -Tlint -Wwarning git-barepo.1 + +test: + $(SHELL) test_publish.sh 1> /dev/null 2>&1 diff --git a/test_publish.sh b/test_publish.sh @@ -0,0 +1,155 @@ +#!/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 + +cookie='D3CAFBAD' +name="repo" + +# Working directory +tmpdir="$(mktemp -d "${TMPDIR:-/tmp}"/git_publish_test_XXXXXX)" +repo="${tmpdir}/${name}" +git="${tmpdir}/git/${name}.git" +srv="${tmpdir}/srv" + +# Use the local git-publish +export PATH="${PWD}:${PATH}" + +######################################################################## +# Helper functions +######################################################################## +check_git_content() # repo-url +{ + git clone "$1" "${tmpdir}/${name}" + + [ -f "${tmpdir}/${name}/README" ] + [ -f "${tmpdir}/${name}/cookie.txt" ] + + str="$(cat "${tmpdir}/${name}/cookie.txt")" + [ "${str}" = "${cookie}" ] + + rm -rf "${tmpdir:?}/${name}" +} + +check_www_content() +{ + [ -f "${srv}/www/index.html" ] + [ -d "${srv}/www/${name}" ] + [ -f "${srv}/www/${name}/index.html" ] +} + +######################################################################## +# Setup repository +######################################################################## +# Create bare repository +mkdir -p "${git}" +git init --bare "${git}" + +# Create the repository content +mkdir -p "${repo}" +printf 'Repository to be published\n' > "${repo}/README" +printf '%s' "${cookie}" > "${repo}/cookie.txt" + +# Configure the directory as a git working directory, commit its +# content and push it to the remote repository +cd "${repo}" +git init +git config --local user.name "Mr Untel" +git config --local user.email "mr@untel.fr" +git add README cookie.txt +git commit -m "Test content for publishing a repository" +git remote add origin "file://${git}" +git push origin master + +cd "${OLDPWD}" +rm -rf "${repo}" # Remove temporary directory + +######################################################################## +# Basic tests +######################################################################## +# Publish the repository +mkdir -p "${srv}/git" "${srv}/www" +git publish \ + -g "${srv}/git" \ + -w "${srv}/www" \ + -u "http://mr.untel.fr/" \ + "${git}" + +[ -L "${srv}/git/${name}.git" ] # The published repository is a symlink + +check_git_content "file://${srv}/git/${name}.git" +check_git_content "file://${git}" +check_www_content + +# Unpublish the repository +GIT_PUBLISH_DIR_GIT="${srv}/git" \ +GIT_PUBLISH_DIR_WWW="${srv}/www" \ +git publish -d "${git}" + +# The published content should be removed +[ ! -e "${srv}/git/${name}.git" ] +[ ! -e "${srv}/www/${name}" ] +[ ! -e "${srv}/www/index.html" ] # No more index since no more repo + +check_git_content "file://${git}" # Original repository should be OK + +######################################################################## +# Test the publication by moving the source repository +######################################################################## +export GIT_PUBLISH_DIR_GIT="${srv}/git" +export GIT_PUBLISH_DIR_WWW="${srv}/www" +export GIT_PUBLISH_BASE_URL="http://mr.untel.fr" + +# Publish the repository by moving it to the publicly accessible +# directory and converting the original repository into a symbolic link +# to the public repository +git publish -m "${git}" + +# The public repository is a directory, not a symbolic link +[ -d "${srv}/git/${name}.git" ] && [ ! -L "${srv}/git/${name}.git" ] + +# The original repository is a symbolic link to the public repository +[ -L "${git}" ] + +check_git_content "file://${srv}/git/${name}.git" +check_git_content "file://${git}" +check_www_content + +# Unpublish the repository +git publish -d "${git}" + +# The published content should be removed +[ ! -e "${srv}/git/${name}.git" ] +[ ! -e "${srv}/www/${name}" ] +[ ! -e "${srv}/www/index.html" ] # No more index since no more repo + +# And the original repository should be a directory, not a symbolic +[ -d "${git}" ] && [ ! -L "${git}" ] + +check_git_content "file://${git}" + +die 0