git-barepo

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

commit 83fb88b465c9714a2720fa41b6d6d999913050e6
parent 7b0ff250da1b5f3d67992c0c8582a0db75462178
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Sun, 24 May 2026 16:15:54 +0200

git-publish: allow published repos to be directories

Add the -m option, which moves the repositories to the publicly
accessible directory instead of creating a symbolic link to the
repositories to be published. In this case, to ensure access to the
repository via its original path, this path is replaced with a symbolic
link to the public directory.

This is a reversal of the default behavior of git-publish. The purpose
is to comply with the constraints of certain servers, such as those
where public repositories are exposed via a chroot environment from
which external links would otherwise be inaccessible.

Diffstat:
Mgit-publish | 33++++++++++++++++++++++++++++-----
Mgit-publish.1 | 36++++++++++++++++++++++++++++++++++--
2 files changed, 62 insertions(+), 7 deletions(-)

diff --git a/git-publish b/git-publish @@ -41,7 +41,7 @@ die() synopsis() { >&2 printf \ -'usage: %s [-df] [-g dir_git] [-u base_url] [-w dir_www] repository ...\n' \ +'usage: %s [-dfm] [-g dir_git] [-u base_url] [-w dir_www] repository ...\n' \ "${0##*/}" } @@ -128,14 +128,20 @@ publication_ban() # - dir_www: directory where to publish the git repository's HTML pages # - repo: git bare repository # - force: force generation of HTML pages from scratch +# - mv_repo: reverse the symbolic link publish_repo() { repo_name=$(basename "${repo}" ".git") # Publish the git repository, i.e. create a symbolic link to it in the - # publicly exposed directory - ln -sf "${repo}" "${dir_git}" + # publicly exposed directory, or the inverse... repo_git="${dir_git}/${repo_name}.git" + if [ "${mv_repo}" -eq 0 ]; then + ln -sf "${repo}" "${dir_git}" + else + mv "${repo}" "${dir_git}" + ln -sf "${repo_git}" "$(dirname "${repo}")" + fi # Create directory publicly served by the WWW daemon repo_www="${dir_www}/${repo_name}" @@ -293,8 +299,19 @@ unpublish() repo_www="${dir_www}/${repo_name}" repo_git="${dir_git}/${repo_name}.git" + # Remove publicly exposed directory + if [ -L "${repo_git}" ]; then + rm "${repo_git}" + elif [ -L "${repo}" ]; then # rev_symlink + rm "${repo}"; + mv "${repo_git}" "$(dirname "${repo}")" + else + >&2 printf 'neither %s nor %s is a symlink\n' \ + "${repo}" "${repo_git}" + continue + fi + rm -rf "${repo_www}" # Remove HTML pages - rm -f "${repo_git}" # Remove link in the publicly exposed directory # shellcheck disable=SC2310 if check_post_receive_hook "${repo}"; then @@ -314,14 +331,20 @@ dir_www="${GIT_PUBLISH_DIR_WWW:-/srv/www/git}" force=0 # Force HTML generation delete=0 # Delete publication +# Move the repository to the publication directory instead of creating a +# link to it there. The original repository then becomes a symbolic link +# to the published repository. +mv_repo=0 + # Parse input arguments OPTIND=1 -while getopts ":dfg:u:w:" opt; do +while getopts ":dfg:mu:w:" opt; do case "${opt}" in d) delete=1 ;; f) force=1 ;; u) base_url="${OPTARG}" ;; g) dir_git="${OPTARG}" ;; # git directory + m) mv_repo=1;; # Reverse symlink w) dir_www="${OPTARG}" ;; # WWW directory *) synopsis; die ;; esac diff --git a/git-publish.1 b/git-publish.1 @@ -12,7 +12,7 @@ .\" .\" You should have received a copy of the GNU General Public License .\" along with this program. If not, see <http://www.gnu.org/licenses/>. -.Dd December 3, 2025 +.Dd May 24, 2026 .Dt GIT-PUBLISH 1 .Os .\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" @@ -22,7 +22,7 @@ .\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" .Sh SYNOPSIS .Nm -.Op Fl df +.Op Fl dfm .Op Fl g Ar dir_git .Op Fl u Ar base_url .Op Fl w Ar dir_www @@ -46,6 +46,7 @@ published repositories to update HTML pages on new commits .Pp The options are as follows: .Bl -tag -width Ds +.\"""""""""""""""""""""""""""""""""" .It Fl d Unpublish .Ar repositories : @@ -54,21 +55,42 @@ HTML pages and the post-receive hook that updates them. The HTML index of publicly exposed repositories is updated to no longer reference repositories to be unpublished. If no more repositories are made public, this HTML index is deleted, +.\"""""""""""""""""""""""""""""""""" .It Fl f Force HTML generation from scratch. Enabling this option ensures that HTML pages take into account any changes in the repositories, such as their metadata .Pq see Sx FILES No section . +.\"""""""""""""""""""""""""""""""""" .It Fl g Ar dir_git Directory in which git repositories are publicly exposed. By default, the .Ev GIT_PUBLISH_DIR_GIT environment variable is used. +.\"""""""""""""""""""""""""""""""""" +.It Fl m +Move the repositories to publish to the +.Ar dir_git +directory, +which is the directory where git repositories are publicly accessible. +The paths to the original repositories become symbolic links to their +published repositories. +This is actually the opposite of the default behavior, in which +published repositories are symbolic links to the original git +repositories. +.Pp +Ensuring that the published repository is a directory rather than a +symbolic link may be a server constraint. +For example, for security reasons, the server might serve public +repositories via a chroot jail, thereby prohibiting the use of links +that would take users outside it. +.\"""""""""""""""""""""""""""""""""" .It Fl u Ar base_url Base URL to make links in the Atom feeds absolute. By default, the .Ev GIT_PUBLISH_BASE_URL environment variable is used. +.\"""""""""""""""""""""""""""""""""" .It Fl w Ar dir_www Directory in which HTML pages are generated. By default, the @@ -95,16 +117,19 @@ section .\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" .Sh ENVIRONMENT .Bl -tag -width Ds +.\"""""""""""""""""""""""""""""""""" .It Ev GIT_PUBLISH_DIR_GIT Directory in which bare repositories are made public. The default is .Pa /srv/git . +.\"""""""""""""""""""""""""""""""""" .It Ev GIT_PUBLISH_BASE_URL Base URL to make links in the ATOM feed absolute. It has no default value and must be explicitly defined if the .Fl u option is not used, unless publications are to be deleted .Pq option Fl d . +.\"""""""""""""""""""""""""""""""""" .It Ev GIT_PUBLISH_DIR_WWW Directory where public repository HTML pages are stored. The default is @@ -115,14 +140,18 @@ The default is In each bare repository, the content of follow files specifies its metadata: .Bl -tag -width Ds +.\"""""""""""""""""""""""""""""""""" .It Pa description Brief description of the repository. +.\"""""""""""""""""""""""""""""""""" .It Pa owner Owner of repository. +.\"""""""""""""""""""""""""""""""""" .It Pa publication_ban If the file exists, the repository is not authorized to be published. Its purpose is therefore to prevent the accidental publication of a repository that should remain private. +.\"""""""""""""""""""""""""""""""""" .It Pa url Public URL from which the repository can be cloned. .El @@ -133,10 +162,13 @@ defined in the directory. Otherwise, the default files provided by git-publish will be used: .Bl -tag -width Ds +.\"""""""""""""""""""""""""""""""""" .It Pa style.css HTML stylesheet. +.\"""""""""""""""""""""""""""""""""" .It Pa favicon.png favicon image (used by graphical browser). +.\"""""""""""""""""""""""""""""""""" .It Pa logo.png 32x32 logo. .El