[GSoC PATCH v7 4/5] repo: add the field layout.shallow
From: Lucas Seiki Oshiro <hidden>
Date: 2025-08-01 13:11:37
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-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 [off-list ref] Helped-by: Junio C Hamano [off-list ref] Helped-by: Justin Tobler [off-list ref] Helped-by: Eric Sunshine [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 | 3 +++ builtin/repo.c | 9 +++++++++ t/t1900-repo.sh | 11 +++++++++++ 3 files changed, 23 insertions(+)
diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
index 98358c5539..140ee3a0aa 100644
--- a/Documentation/git-repo.adoc
+++ b/Documentation/git-repo.adoc@@ -35,6 +35,9 @@ values that they return: `layout.bare`:: `true` if this is a bare repository, otherwise `false`. +`layout.shallow`:: +`true` if this is a shallow repository, otherwise `false`. + `references.format`:: The reference storage format. The valid values are: +
diff --git a/builtin/repo.c b/builtin/repo.c
index 2d51bfa195..56c3a4027f 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c@@ -6,6 +6,7 @@ #include "quote.h" #include "refs.h" #include "strbuf.h" +#include "shallow.h" static const char *const repo_usage[] = { "git repo info [<key>...]",
@@ -26,6 +27,13 @@ static int get_layout_bare(struct repository *repo UNUSED, struct strbuf *buf) return 0; } +static int get_layout_shallow(struct repository *repo, struct strbuf *buf) +{ + strbuf_addstr(buf, + is_repository_shallow(repo) ? "true" : "false"); + return 0; +} + static int get_references_format(struct repository *repo, struct strbuf *buf) { strbuf_addstr(buf,
@@ -36,6 +44,7 @@ static int get_references_format(struct repository *repo, struct strbuf *buf) /* 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 6c555e90c3..6706cb4c44 100755
--- a/t/t1900-repo.sh
+++ b/t/t1900-repo.sh@@ -41,6 +41,16 @@ test_repo_info 'bare repository = false is retrieved correctly' ' test_repo_info 'bare repository = true is retrieved correctly' ' git init --bare' 'nonbare' 'layout.bare' 'true' +test_repo_info 'shallow repository = false is retrieved correctly' ' + git init' 'nonshallow' 'layout.shallow' 'false' + +test_repo_info 'shallow repository = true is retrieved correctly' ' + git init remote && + echo x >remote/x && + git -C remote add x && + git -C remote commit -m x && + git clone --depth 1 "file://$PWD/remote"' 'shallow' 'layout.shallow' 'true' + test_expect_success 'git-repo-info fails if an invalid key is requested' ' echo "error: key '\'foo\'' not found" >expected_err && test_must_fail git repo info foo 2>actual_err &&
@@ -68,4 +78,5 @@ test_expect_success 'output is returned correctly when two keys are requested' ' git init --ref-format=files two-keys && git -C two-keys repo info layout.bare references.format ' + test_done
--
2.39.5 (Apple Git-154)