git-repo

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

commit 9bf2c8211258588a09a25c9cf322d408676ac878
parent 475178c2dd4d771f1556f5277627f1740e872648
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed,  3 Dec 2025 10:29:26 +0100

git-repo: fixed issues with paths such as "."

The caller could not update the repository if the provided path did not
explicitly contain its directory name.

To fix the problem, this validation changes the behavior of git-repo.
Until now, the repository name was assumed to be followed by the suffix
".git", in accordance with the convention for bare repositories. The
name provided as input was therefore potentially updated to ensure this
naming convention.

However, this is only possible if the path to the repository contains
the name of the repository directory. If this is not the case, the path
necessarily references an existing repository (for example, "."), so its
name cannot be updated.

Consequently, the ".git" suffix is only guaranteed when the repository
does not yet exist.  git-repo nevertheless continues to check that the
existing repository is a bare repository.

Diffstat:
Mgit-repo | 65+++++++++++++++++++++++++++++++++++++++--------------------------
1 file changed, 39 insertions(+), 26 deletions(-)

diff --git a/git-repo b/git-repo @@ -164,40 +164,53 @@ done # Skip parsed arguments shift $((OPTIND - 1)) -repo="$(echo "$1" | sed 's#/\+$##g')" - -# Make sure the repository name has a .git suffix (i.e. bare repo) -suffix="${repo##*.}" -if [ "${suffix}" != "git" ] \ -|| [ "${suffix}" = "${repo}" ]; then - repo="${repo}.git" -fi +repo="$1" +# The input repository does not exist if [ ! -e "${repo}" ]; then - mkdir -p "${repo}" || die "$?" + + # Remove trailing slashes + repo="$(echo "${repo}" | sed 's#/\+$##g')" + + # Ensure that the repository name includes the .git extension, in + # accordance with the convention applicable to bare repositories. + suffix="${repo##*.}" + if [ "${suffix}" != "git" ] \ + || [ "${suffix}" = "${repo}" ]; then + repo="${repo}.git" + fi + + mkdir -p "${repo}" git init --bare "${repo}" -fi -if [ ! -d "${repo}" ]; then - >&2 printf '%s: not a git repository\n' "${repo}" - die -fi + git_dir="${repo}" + +# Verify that the existing path is indeed a bare git repository +else + # Check that it is a directory + if [ ! -d "${repo}" ]; then + >&2 printf '%s: not a git repository\n' "${repo}" + die + fi -cd -- "${repo}" + cd -- "${repo}" -if ! git_dir=$(git rev-parse --git-dir 2>&1); then - >&2 printf '%s: %s\n' "${repo}" "${git_dir}" - die -fi + # Retrieve the "git" directory, i.e., the directory where git data is + # stored + if ! git_dir=$(git rev-parse --git-dir 2>&1); then + >&2 printf '%s: %s\n' "${repo}" "${git_dir}" + die + fi -# Check that the repository is a bare repository -if ! git_bare=$(git rev-parse --is-bare-repository) \ -|| [ "${git_bare}" = "false" ]; then - >&2 printf '%s: not a git bare repository\n' "${repo}" - die -fi + # Check that the repository is a bare repository + if ! git_bare=$(git rev-parse --is-bare-repository) \ + || [ "${git_bare}" = "false" ]; then + >&2 printf '%s: not a git bare repository\n' "${repo}" + die + fi -cd -- "${OLDPWD}" + cd -- "${OLDPWD}" +fi # Retrieve absolute path of the git directory cd -- "${git_dir}"