git-barepo

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

commit 94d6bfdb27b90a5f6d20c2e19146e8d96ad23102
parent c4cc2d8407478b6cf0d029fe1f867f26d3bf8a1f
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Tue, 26 May 2026 16:05:55 +0200

git-publish: fix issues when public path exists

This can happen if the repository is already published or if the public
path refers to an existing file.

The first case is valid, and 'git-publish' should update the
publication. This was not the case if the public path was not a symbolic
link, a situation that this commit fixes.

The second case is an error, which was reported as is. However, this
commit adds an error message that is intended to be more explicit for
the user.

Diffstat:
Mgit-publish | 36+++++++++++++++++++++++++++++++-----
1 file changed, 31 insertions(+), 5 deletions(-)

diff --git a/git-publish b/git-publish @@ -132,15 +132,41 @@ publication_ban() publish_repo() { repo_name=$(basename "${repo}" ".git") - - # Publish the git repository, i.e. create a symbolic link to it in the - # publicly exposed directory, or the inverse... repo_git="${dir_git}/${repo_name}.git" + + if [ -e "${repo_git}" ]; then + # If the path to the published repository already exists, + # verify that it matches the repository to publish... + dir0="$(cd "${repo_git}" && pwd -P)" + dir1="$(cd "${repo}" && pwd -P)" + if [ "${dir0}" != "${dir1}" ]; then + >&2 printf \ + '"%s" already exists and is not the public version of "%s"\n' \ + "${repo_git}" "${repo}" + die 1 + fi + + # ... and make sure that the source path points to a directory and + # not a symbolic link. The “mv_repo” option is discussed below + if [ -L "${repo}" ]; then + rm "${repo}" + mv "${repo_git}" "${repo}" + fi + + # Finally, delete the symbolic link in the public directory, + # if it exists. + rm -f "${repo_git}" + fi + + # Publish the git repository, i.e., create a symbolic link to it in + # the publicly accessible directory, or move it to the public + # directory and create a symbolic link from the original path to its + # public version. if [ "${mv_repo}" -eq 0 ]; then - ln -sf "${repo}" "${dir_git}" + ln -s "${repo}" "${dir_git}" else mv "${repo}" "${dir_git}" - ln -sf "${repo_git}" "$(dirname "${repo}")" + ln -s "${repo_git}" "$(dirname "${repo}")" fi # Create directory publicly served by the WWW daemon