Subject: [GSoC RFC PATCH v3 4/5] repo-info: add field layout.bare

From: Lucas Seiki Oshiro <[email-masked]>
Date: Sun, 6 Jul 2025 20:19:37 -0300

This commit is part of the series that introduces the new command
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 information, fitting in the purpose of
git-repo-info.

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

Helped-by: Phillip Wood <[email-masked]>
Helped-by: Junio C Hamano <[email-masked]>
Mentored-by: Karthik Nayak <[email-masked]>
Mentored-by: Patrick Steinhardt <[email-masked]>
Signed-off-by: Lucas Seiki Oshiro <[email-masked]>
---
 Documentation/git-repo-info.adoc |  4 ++++
 builtin/repo-info.c              | 37 ++++++++++++++++++++++++++++++++
 t/t1900-repo-info.sh             |  6 ++++++
 3 files changed, 47 insertions(+)

diff --git a/Documentation/git-repo-info.adoc b/Documentation/git-repo-info.adoc
index dd221b236e..67d19406ad 100644
--- a/Documentation/git-repo-info.adoc
+++ b/Documentation/git-repo-info.adoc
@@ -70,6 +70,10 @@ categories. Each category is composed by one or more fields.
 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-info.c b/builtin/repo-info.c
index 98a0d83d51..7e29ae8519 100644
--- a/builtin/repo-info.c
+++ b/builtin/repo-info.c
@@ -1,4 +1,8 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "builtin.h"
+#include "environment.h"
+#include "hash.h"
 #include "json-writer.h"
 #include "parse-options.h"
 #include "refs.h"
@@ -10,16 +14,22 @@ enum output_format {
 
 enum repo_info_category {
 	CATEGORY_REFERENCES = 1 << 0,
+	CATEGORY_LAYOUT = 1 << 1,
 };
 
 enum repo_info_references_field {
 	FIELD_REFERENCES_FORMAT = 1 << 0,
 };
 
+enum repo_info_layout_field {
+	FIELD_LAYOUT_BARE = 1 << 0,
+};
+
 struct repo_info_field {
 	enum repo_info_category category;
 	union {
 		enum repo_info_references_field references;
+		enum repo_info_layout_field layout;
 	} u;
 };
 
@@ -53,6 +63,9 @@ static void repo_info_init(struct repo_info *repo_info,
 		if (!strcmp(arg, "references.format")) {
 			field->category = CATEGORY_REFERENCES;
 			field->u.references = FIELD_REFERENCES_FORMAT;
+		} else if (!strcmp(arg, "layout.bare")) {
+			field->category = CATEGORY_LAYOUT;
+			field->u.layout = FIELD_LAYOUT_BARE;
 		} else {
 			die("invalid field '%s'", arg);
 		}
@@ -81,6 +94,17 @@ static void append_null_terminated_field(struct strbuf *buf,
 			break;
 		}
 		break;
+
+	case CATEGORY_LAYOUT:
+		strbuf_addstr(buf, "layout.");
+		switch (field->u.layout) {
+		case FIELD_LAYOUT_BARE:
+			strbuf_addstr(buf, "bare\n");
+			strbuf_addstr(buf, is_bare_repository() ? "true" :
+								  "false");
+			break;
+		}
+		break;
 	}
 
 	strbuf_addch(buf, '\0');
@@ -106,6 +130,7 @@ static void repo_info_print_json(struct repo_info *repo_info)
 	struct json_writer jw;
 	unsigned int categories = 0;
 	unsigned int references_fields = 0;
+	unsigned int layout_fields = 0;
 	struct repository *repo = repo_info->repo;
 
 	for (size_t i = 0; i < repo_info->fields_nr; i++) {
@@ -115,6 +140,9 @@ static void repo_info_print_json(struct repo_info *repo_info)
 		case CATEGORY_REFERENCES:
 			references_fields |= field->u.references;
 			break;
+		case CATEGORY_LAYOUT:
+			layout_fields |= field->u.layout;
+			break;
 		}
 	}
 
@@ -130,6 +158,15 @@ static void repo_info_print_json(struct repo_info *repo_info)
 		}
 		jw_end(&jw);
 	}
+
+	if (categories & CATEGORY_LAYOUT) {
+		jw_object_inline_begin_object(&jw, "layout");
+		if (layout_fields & FIELD_LAYOUT_BARE) {
+			jw_object_bool(&jw, "bare",
+				       is_bare_repository());
+		}
+		jw_end(&jw);
+	}
 	jw_end(&jw);
 
 	puts(jw.json.buf);
diff --git a/t/t1900-repo-info.sh b/t/t1900-repo-info.sh
index 2af9d1d9c3..246c4bc40c 100755
--- a/t/t1900-repo-info.sh
+++ b/t/t1900-repo-info.sh
@@ -61,4 +61,10 @@ 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_done
-- 
2.39.5 (Apple Git-154)