#1032521 myrepos: "unknown repository type" error registering git bare with packed refs

#1032521#5
Date:
2023-03-08 14:15:37 UTC
From:
To:
Dear Maintainer,

An error is returned when running "mr register" on a bare git
repository that has no refs/tags or refs/heads directory.

$ git clone --bare --quiet https://github.com/beancount/beancount-mode.git
$ cd beancount-mode.git
$ rmdir refs/tags
$ mr register
mr register: unknown repository type

In my case my repositories are stored that way on disk, perhaps
because I'm using GitLab which seems to aggressively prefer
packed-refs [1] instead for example.

I checked the git reference documentation (gitrepository-layout [2],
etc.)  and was unable to find anything defining the directories under
refs/ as required instead of optional, but git seems to work fine with
an empty refs directory, lazily creating things under refs/ if they
are missing. However having a missing refs/ directory entirely is not
OK:

$ rm -rf refs
$ git log --oneline -1
fatal: not a git repository (or any of the parent directories): .git

A patch is attached that loosens the git_bare test (and vcsh) to not
require heads nor tags under refs, but instead simply require a refs
folder in addition to the other heuristics used for detecting a git
repository.

This appears to have been added in
c20b454a225407e5c6b918cbb6e739b888b252ab when handling of git bare
repositories was separated out.

[1] https://git-scm.com/docs/git-pack-refs
[2] https://git-scm.com/docs/gitrepository-layout


*** 0001-Fix-detection-of-git-bare-repositories-with-no-tags-.patch
From: Jacob Greenleaf <jacob@jacobgreenleaf.com>
Origin: other
Date: Tue, 7 Mar 2023 19:35:41 -0800
Subject: [PATCH] Fix detection of git bare repositories with no tags or heads
 refs dirs
---
 mr | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mr b/mr
index 056e749..26d9300 100755
--- a/mr
+++ b/mr
@@ -2501,11 +2501,11 @@ hg_test  = perl: -d "$ENV{MR_REPO}/.hg"
 darcs_test = perl: -d "$ENV{MR_REPO}/_darcs"
 fossil_test = perl: -f "$ENV{MR_REPO}/_FOSSIL_" || -f "$ENV{MR_REPO}/.fslckout"
 git_bare_test = perl:
-       -d "$ENV{MR_REPO}/refs/heads" && -d "$ENV{MR_REPO}/refs/tags" &&
+       -d "$ENV{MR_REPO}/refs" &&
        -d "$ENV{MR_REPO}/objects" && -f "$ENV{MR_REPO}/config" &&
        `GIT_CONFIG="$ENV{MR_REPO}"/config git config --get core.bare` =~ /true/
 vcsh_test = perl:
-       -d "$ENV{MR_REPO}/refs/heads" && -d "$ENV{MR_REPO}/refs/tags" &&
+       -d "$ENV{MR_REPO}/refs" &&
        -d "$ENV{MR_REPO}/objects" && -f "$ENV{MR_REPO}/config" &&
        `GIT_CONFIG="$ENV{MR_REPO}"/config git config --get vcsh.vcsh` =~ /true/
 veracity_test  = perl: -d "$ENV{MR_REPO}/.sgdrawer"
-- 
2.30.2