git-barepo

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

commit 3c1eb493bed93c20a218ece8081fcf4d9b4802cc
parent 344d45f0c1fa1bcaf12b5fee0ccfe6e1c7ee80d2
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Tue, 26 May 2026 17:06:28 +0200

git-publish: improve error handling

If the public path already exists and points to a file, git-publish
failed. Although this is the expected behavior, the failure was due to
the assumption that the path was a directory. This commit now handles
this case to display a better error message to the user; in fact, the
same message as the one displayed if the path is a directory that does
not correspond to a previous publication of the repository.

Diffstat:
Mgit-publish | 4+++-
Mtest_publish.sh | 13++++++++++++-
2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/git-publish b/git-publish @@ -137,7 +137,9 @@ publish_repo() 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)" + if [ ! -f "${repo_git}" ]; then + dir0="$(cd "${repo_git}" && pwd -P)" + fi dir1="$(cd "${repo}" && pwd -P)" if [ "${dir0}" != "${dir1}" ]; then >&2 printf \ diff --git a/test_publish.sh b/test_publish.sh @@ -179,8 +179,9 @@ git publish -d "${git}" check_git_content "file://${git}" ######################################################################## -# Prevent the publication of the repository +# The repository cannot be published ######################################################################## +# Prevent the publication of the repository touch "${git}/publication_ban" git publish "${git}" @@ -191,8 +192,18 @@ git publish -m "${git}" [ ! -e "${srv}/git/${name}.git" ] [ ! -e "${srv}/www/${name}" ] +# Make the repository publishable rm "${git}/publication_ban" +# The repository cannot be published if the public path exists and it is +# not the result of an earlier publication of the reposite +touch "${srv}/git/${name}.git" +git publish "${git}" && false || true +rm "${srv}/git/${name}.git" +mkdir "${srv}/git/${name}.git" +git publish "${git}" && false || true +rmdir "${srv}/git/${name}.git" + ######################################################################## # Switch from the original repository to the published repository ########################################################################