Thread (178 messages) 178 messages, 10 authors, 2025-08-16
STALE333d
Revisions (6)
  1. v4 current
  2. v5 [diff vs current]
  3. v5 [diff vs current]
  4. v7 [diff vs current]
  5. v8 [diff vs current]
  6. v9 [diff vs current]

[GSoC RFC PATCH v4 3/4] repo: add field layout.bare

From: Lucas Seiki Oshiro <hidden>
Date: 2025-07-14 23:52:49
Subsystem: documentation, the rest · Maintainers: Jonathan Corbet, Linus Torvalds

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 [off-list ref]
Helped-by: Junio C Hamano [off-list ref]
Helped-by: Justin Tobler [off-list ref]
Mentored-by: Karthik Nayak [off-list ref]
Mentored-by: Patrick Steinhardt [off-list ref]
Signed-off-by: Lucas Seiki Oshiro <redacted>
---
 Documentation/git-repo.adoc |  4 ++++
 builtin/repo.c              | 17 +++++++++++++++++
 t/t1900-repo.sh             |  6 ++++++
 3 files changed, 27 insertions(+)
diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
index b7af6f45a4..db185c5c91 100644
--- a/Documentation/git-repo.adoc
+++ b/Documentation/git-repo.adoc
@@ -49,6 +49,10 @@ categories:
 Reference-related data:
 * `format`: the reference storage format, either `files` or `reftable`.
 
+`layout`::
+Information about the how the current repository is represented:
+* `bare`: `true` if this is a bare repository, otherwise `false`.
+
 SEE ALSO
 --------
 linkgit:git-rev-parse[1]
diff --git a/builtin/repo.c b/builtin/repo.c
index dcda0d6d61..5eefe06918 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -1,7 +1,10 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "builtin.h"
 #include "parse-options.h"
 #include "strbuf.h"
 #include "refs.h"
+#include "environment.h"
 
 typedef void add_field_fn(struct strbuf *buf, struct repository *repo);
 
@@ -16,6 +19,13 @@ static void add_string(struct strbuf *buf,
 	strbuf_addf(buf, "%s\n%s%c", key, value, '\0');
 }
 
+static void add_bool(struct strbuf *buf,
+		     const char *key, const int value)
+{
+	const char *output_value = value ? "true" : "false";
+	strbuf_addf(buf, "%s\n%s%c", key, output_value, '\0');
+}
+
 static void add_references_format(struct strbuf *buf,
 				  struct repository *repo)
 {
@@ -23,8 +33,15 @@ static void add_references_format(struct strbuf *buf,
 		   ref_storage_format_to_name(repo->ref_storage_format));
 }
 
+
+static void add_layout_bare(struct strbuf *buf, struct repository *repo UNUSED)
+{
+	add_bool(buf, "layout.bare", is_bare_repository());
+}
+
 // repo_info_fields keys should be in lexicographical order
 static const struct field repo_info_fields[] = {
+	{"layout.bare", add_layout_bare},
 	{"references.format", add_references_format},
 };
 
diff --git a/t/t1900-repo.sh b/t/t1900-repo.sh
index b80fc6b78b..6155e275b5 100755
--- a/t/t1900-repo.sh
+++ b/t/t1900-repo.sh
@@ -36,6 +36,12 @@ test_repo_info 'ref format files is retrieved correctly' '
 test_repo_info 'ref format reftable is retrieved correctly' '
 	git init --ref-format=reftable repo' 'references.format' 'reftable'
 
+test_repo_info 'bare repository = false is retrieved correctly' '
+	git init repo' 'layout.bare' 'false'
+
+test_repo_info 'bare repository = true is retrieved correctly' '
+	git init --bare repo' 'layout.bare' 'true'
+
 test_expect_success "only one value is returned if the same key is requested twice" '
 	echo "references.format" > expected &&
 	git rev-parse --show-ref-format > ref-format &&
-- 
2.39.5 (Apple Git-154)
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help