]> git.ipfire.org Git - thirdparty/git.git/commitdiff
repo: add the field layout.bare
authorLucas Seiki Oshiro <lucasseikioshiro@gmail.com>
Sat, 16 Aug 2025 22:46:01 +0000 (19:46 -0300)
committerJunio C Hamano <gitster@pobox.com>
Sun, 17 Aug 2025 16:13:40 +0000 (09:13 -0700)
This commit is part of the series that introduces the new subcommand
git-repo-info.

The flag --is-bare-repository from git-rev-parse is used for retrieving
whether the current repository is bare. This way, it is used for
querying repository metadata, fitting in the purpose of git-repo-info.

Then, add a new field layout.bare to the git-repo-info subcommand
containing that information.

Helped-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Justin Tobler <jltobler@gmail.com>
Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Mentored-by: Karthik Nayak <karthik.188@gmail.com>
Mentored-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-repo.adoc
builtin/repo.c
t/t1900-repo.sh

index 2779a6d995ca2308d5cb172bb5fa40183164f020..932b08c26fad7ac8d6de7cde07dd717b67d7827d 100644 (file)
@@ -38,6 +38,9 @@ In order to obtain a set of values from `git repo info`, you should provide
 the keys that identify them. Here's a list of the available keys and the
 values that they return:
 
+`layout.bare`::
+       `true` if this is a bare repository, otherwise `false`.
+
 `references.format`::
        The reference storage format. The valid values are:
 +
index 73d4e27a1686b3c4161de14516bf8973c4814551..aada476e1cbd9e3126010151295ff9fe1cce4456 100644 (file)
@@ -1,4 +1,7 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "builtin.h"
+#include "environment.h"
 #include "parse-options.h"
 #include "quote.h"
 #include "refs.h"
@@ -16,6 +19,12 @@ struct field {
        get_value_fn *get_value;
 };
 
+static int get_layout_bare(struct repository *repo UNUSED, struct strbuf *buf)
+{
+       strbuf_addstr(buf, is_bare_repository() ? "true" : "false");
+       return 0;
+}
+
 static int get_references_format(struct repository *repo, struct strbuf *buf)
 {
        strbuf_addstr(buf,
@@ -25,6 +34,7 @@ static int get_references_format(struct repository *repo, struct strbuf *buf)
 
 /* repo_info_fields keys must be in lexicographical order */
 static const struct field repo_info_fields[] = {
+       { "layout.bare", get_layout_bare },
        { "references.format", get_references_format },
 };
 
index be8a4b2499b231f92298f59bfe575a1d4635b9dd..b0438d276eec99899f77b97afdac00af1eed8fdf 100755 (executable)
@@ -38,6 +38,23 @@ test_repo_info 'ref format files is retrieved correctly' \
 test_repo_info 'ref format reftable is retrieved correctly' \
        'git init --ref-format=reftable' 'format-reftable' 'references.format' 'reftable'
 
+test_repo_info 'bare repository = false is retrieved correctly' \
+       'git init' 'nonbare' 'layout.bare' 'false'
+
+test_repo_info 'bare repository = true is retrieved correctly' \
+       'git init --bare' 'bare' 'layout.bare' 'true'
+
+test_expect_success 'values returned in order requested' '
+       cat >expect <<-\EOF &&
+       layout.bare=false
+       references.format=files
+       layout.bare=false
+       EOF
+       git init --ref-format=files ordered &&
+       git -C ordered repo info layout.bare references.format layout.bare >actual &&
+       test_cmp expect actual
+'
+
 test_expect_success 'git-repo-info fails if an invalid key is requested' '
        echo "error: key ${SQ}foo${SQ} not found" >expect &&
        test_must_fail git repo info foo 2>actual &&