[GSoC RFC PATCH v3 5/5] repo-info: add field layout.shallow
From: Lucas Seiki Oshiro <hidden>
Date: 2025-07-06 23:20:21
Subsystem:
documentation, the rest · Maintainers:
Jonathan Corbet, Linus Torvalds
This commit is part of the series that introduces the new command 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 information, fitting in the purpose of git-repo-info. Then, add a new field `layout.shallow` to the git-repo-info command containing that information. Helped-by: Phillip Wood [off-list ref] Helped-by: Junio C Hamano [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-info.adoc | 1 + builtin/repo-info.c | 15 +++++++++++++++ t/t1900-repo-info.sh | 14 ++++++++++++++ 3 files changed, 30 insertions(+)
diff --git a/Documentation/git-repo-info.adoc b/Documentation/git-repo-info.adoc
index 67d19406ad..3261cd97b5 100644
--- a/Documentation/git-repo-info.adoc
+++ b/Documentation/git-repo-info.adoc@@ -73,6 +73,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-info.c b/builtin/repo-info.c
index 7e29ae8519..2fa6544d15 100644
--- a/builtin/repo-info.c
+++ b/builtin/repo-info.c@@ -6,6 +6,7 @@ #include "json-writer.h" #include "parse-options.h" #include "refs.h" +#include "shallow.h" enum output_format { FORMAT_JSON,
@@ -23,6 +24,7 @@ enum repo_info_references_field { enum repo_info_layout_field { FIELD_LAYOUT_BARE = 1 << 0, + FIELD_LAYOUT_SHALLOW = 1 << 1, }; struct repo_info_field {
@@ -66,6 +68,9 @@ static void repo_info_init(struct repo_info *repo_info, } else if (!strcmp(arg, "layout.bare")) { field->category = CATEGORY_LAYOUT; field->u.layout = FIELD_LAYOUT_BARE; + } else if (!strcmp(arg, "layout.shallow")) { + field->category = CATEGORY_LAYOUT; + field->u.layout = FIELD_LAYOUT_SHALLOW; } else { die("invalid field '%s'", arg); }
@@ -103,6 +108,11 @@ static void append_null_terminated_field(struct strbuf *buf, strbuf_addstr(buf, is_bare_repository() ? "true" : "false"); break; + case FIELD_LAYOUT_SHALLOW: + strbuf_addstr(buf, "shallow\n"); + strbuf_addstr(buf, is_repository_shallow(repo) ? "true" : + "false"); + break; } break; }
@@ -165,6 +175,11 @@ static void repo_info_print_json(struct repo_info *repo_info) jw_object_bool(&jw, "bare", is_bare_repository()); } + + if (layout_fields & FIELD_LAYOUT_SHALLOW) { + jw_object_bool(&jw, "shallow", + is_repository_shallow(repo)); + } jw_end(&jw); } jw_end(&jw);
diff --git a/t/t1900-repo-info.sh b/t/t1900-repo-info.sh
index 246c4bc40c..fdbbfb42a0 100755
--- a/t/t1900-repo-info.sh
+++ b/t/t1900-repo-info.sh@@ -67,4 +67,18 @@ 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_done
--
2.39.5 (Apple Git-154)