Subject: [GSoC PATCH v5 4/5] repo: add field layout.shallow

From: Lucas Seiki Oshiro <[email-masked]>
Date: Mon, 21 Jul 2025 21:28:34 -0300

This commit is part of the series that introduces the new subcommand
git-repo-info.

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

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

Helped-by: Phillip Wood <[email-masked]>
Helped-by: Junio C Hamano <[email-masked]>
Helped-by: Justin Tobler <[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.adoc |  1 +
 builtin/repo.c              |  7 +++++++
 t/t1900-repo.sh             | 21 +++++++++++++++++++++
 3 files changed, 29 insertions(+)

diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
index 7124487323..375b956d3f 100644
--- a/Documentation/git-repo.adoc
+++ b/Documentation/git-repo.adoc
@@ -36,6 +36,7 @@ Reference-related data:
 `layout`::
 Information about the how the current repository is represented:
 * `bare`: `true` if this is a bare repository, otherwise `false`.
+* `shallow`: `true` if this is a shallow repository, otherwise `false`.
 
 SEE ALSO
 --------
diff --git a/builtin/repo.c b/builtin/repo.c
index b85bd10889..490fa9dd49 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -4,6 +4,7 @@
 #include "parse-options.h"
 #include "refs.h"
 #include "environment.h"
+#include "shallow.h"
 
 typedef const char *get_value_fn(struct repository *repo);
 
@@ -17,6 +18,11 @@ static const char *get_layout_bare(struct repository *repo UNUSED)
 	return is_bare_repository() ? "true" : "false";
 }
 
+static const char *get_layout_shallow(struct repository *repo)
+{
+	return is_repository_shallow(repo) ? "true" : "false";
+}
+
 static const char *get_references_format(struct repository *repo)
 {
 	return ref_storage_format_to_name(repo->ref_storage_format);
@@ -25,6 +31,7 @@ static const char *get_references_format(struct repository *repo)
 /* repo_info_fields keys should be in lexicographical order */
 static const struct field repo_info_fields[] = {
 	{ "layout.bare", get_layout_bare },
+	{ "layout.shallow", get_layout_shallow },
 	{ "references.format", get_references_format },
 };
 
diff --git a/t/t1900-repo.sh b/t/t1900-repo.sh
index 03609ffff9..c46ace1fd3 100755
--- a/t/t1900-repo.sh
+++ b/t/t1900-repo.sh
@@ -42,6 +42,20 @@ test_repo_info 'bare repository = false is retrieved correctly' '
 test_repo_info 'bare repository = true is retrieved correctly' '
 	git init --bare repo' 'layout.bare' 'true'
 
+test_repo_info 'shallow repository = false is retrieved correctly' '
+	git init repo' 'layout.shallow' 'false'
+
+test_repo_info 'shallow repository = true is retrieved correctly' '
+	git init remote &&
+	cd remote &&
+	echo x >x &&
+	git add x &&
+	git commit -m x &&
+	cd .. &&
+	git clone --depth 1 "file://$PWD/remote" repo &&
+	rm -rf remote
+	' 'layout.shallow' 'true'
+
 test_expect_success "only one value is returned if the same key is requested twice" '
 	test_when_finished "rm -f expected_key expected_value actual_key actual_value output" &&
 	echo "references.format" >expected_key &&
@@ -53,4 +67,11 @@ test_expect_success "only one value is returned if the same key is requested twi
         test_cmp expected_value actual_value
 '
 
+test_expect_success 'output is returned correctly when two keys are requested' '
+	test_when_finished "rm -f expect" &&
+	printf "layout.bare=false\nlayout.shallow=false\n" >expect &&
+	git repo info layout.shallow layout.bare >actual &&
+	test_cmp expect actual
+'
+
 test_done
-- 
2.39.5 (Apple Git-154)