commit c4cc2d8407478b6cf0d029fe1f867f26d3bf8a1f
parent e07e6c9a977de0247be0764edb513c7984b20c2a
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Mon, 25 May 2026 17:25:13 +0200
git-barepo: add Tests
Verifies the command's behavior, particularly when the repository path
is a symbolic link. This is no longer a special case, as publishing a
repository now allows to move it to another directory and replace
its original path with a symbolic link (commit 83fb88b).
Diffstat:
| M | Makefile | | | 2 | ++ |
| A | test_barepo.sh | | | 146 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 148 insertions(+), 0 deletions(-)
diff --git a/Makefile b/Makefile
@@ -57,10 +57,12 @@ uninstall:
lint:
shellcheck -o all git-publish
shellcheck -o all git-barepo
+ shellcheck -o all test_barepo.sh
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_barepo.sh 1> /dev/null 2>&1
$(SHELL) test_publish.sh 1> /dev/null 2>&1
diff --git a/test_barepo.sh b/test_barepo.sh
@@ -0,0 +1,146 @@
+#!/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
+name="repo"
+tmpdir="$(mktemp -d "${TMPDIR:-/tmp}"/git_barepo_test_XXXXXX)"
+git="${tmpdir}/${name}.git"
+
+# Use the local git-publish
+export PATH="${PWD}:${PATH}"
+
+########################################################################
+# Helper functions
+########################################################################
+get_group() # file
+{
+ # shellcheck disable=SC2012
+ ls -dl "$1" | cut -d' ' -f4
+}
+
+get_group_perms() # file
+{
+ # shellcheck disable=SC2012
+ ls -dl "$1" | cut -d' ' -f1 | cut -c5-7
+}
+
+check_shared_repo() # repo, group
+{
+ # Check git configuration
+ cd "$1"
+ _v="$(git config --local --get core.sharedRepository)"
+ [ "${_v}" = "group" ]
+ cd "${OLDPWD}"
+
+ # Check file permissions
+ find -L "$1" | while read -r i; do
+ _group="$(get_group "${i}")"
+ _perm="$(get_group_perms "${i}")"
+
+ if [ -L "${i}" ]; then # Do not check symbolic links
+ continue
+ fi
+
+ [ "${_group}" = "$2" ]
+
+ # Check group's permissions
+ if [ -d "${i}" ]; then
+ [ "${_perm}" = "rws" ] # Directory
+ else
+ _p="$(printf '%s\n' "${_perm}" | cut -c1,2)"
+ [ "${_p}" = "rw" ] # File
+ fi
+ done
+}
+
+check_private_repo()
+{
+ # Check git configuration
+ cd "$1"
+ _v="$(git config --local --get core.sharedRepository)"
+ [ -z "${_v}" ] || [ "${_v}" = "false" ]
+ cd "${OLDPWD}"
+
+ # There is no simple way to check the access permissions of a private
+ # file, as we cannot make any assumptions about its default
+ # permissions. It is still possible, but that would amount to
+ # reimplementing what is already done in git-barepo. However, it seems
+ # inappropriate to reimplement something that should be verify.
+}
+
+########################################################################
+# The test
+########################################################################
+git barepo "${git}" # Create bare repository
+
+# Check that a directory exists...
+[ -d "${git}" ]
+
+# ... and that it is a bare repository.
+cd "${git}"
+is_bare="$(git rev-parse --is-bare-repository)"
+[ "${is_bare}" = "true" ]
+cd "${OLDPWD}"
+
+# Check that it is not a dumb repository
+[ ! -e "${git}/hooks/post-update" ]
+
+# Create a link to the repository
+link="${tmpdir}/${name}_link.git"
+ln -s "${git}" "${link}"
+[ -L "${link}" ]
+
+git barepo -d "${link}"
+[ -e "${git}/hooks/post-update" ] # It should be now a dumb repository
+git barepo -D "${git}"
+[ ! -e "${link}/hooks/post-update" ] # It is no more a dumb repository
+
+# Find another group that is not the user's group, but to which the user
+# belongs. Fails if such group is not found, even though this situation
+# is perfectly valid from the system's perspective, because the test
+# cannot actually be performed.
+group="$(id -gn)"
+group="$(id -Gn | tr ' ' '\n' | grep -v "${group}" | head -n1)"
+[ -n "${group}" ]
+
+# Share the repository
+git barepo -s "${group}" "${git}"
+check_shared_repo "${git}" "${group}"
+
+# Privatise the repository
+git barepo -p "${git}"
+check_private_repo "${git}"
+
+# Update repository sharing via a symoblic link
+git barepo -s "${group}" "${link}"
+check_shared_repo "${git}" "${group}"
+check_shared_repo "${link}" "${group}"
+git barepo -p "${link}"
+check_private_repo "${git}"
+check_private_repo "${link}"