repo: add the field layout.shallow

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 <phillip.wood@dunelm.org.uk> Helped-by: Junio C Hamano <gitster@pobox.com> Helped-by: Justin Tobler <jltobler@gmail.com> Helped-by: Eric Sunshine <sunshine@sunshineco.com> Mentored-by: Karthik Nayak <karthik.188@gmail.com> Mentored-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Lucas Seiki Oshiro committed Aug 16, 2025 at 19:46 UTC e52cd654c9b21a98817578b8fd668da99053ee2b
3 files changed +25
Documentation/git-repo.adoc
+3
@@ -41,6 +41,9 @@ values that they return:
41 `layout.bare`::
42 `true` if this is a bare repository, otherwise `false`.
43
44 +`layout.shallow`::
45 + `true` if this is a shallow repository, otherwise `false`.
46 +
47 `references.format`::
48 The reference storage format. The valid values are:
49 +
builtin/repo.c
+9
@@ -6,6 +6,7 @@
6 #include "quote.h"
7 #include "refs.h"
8 #include "strbuf.h"
9 +#include "shallow.h"
10
11 static const char *const repo_usage[] = {
12 "git repo info [<key>...]",
@@ -25,6 +26,13 @@ static int get_layout_bare(struct repository *repo UNUSED, struct strbuf *buf)
26 return 0;
27 }
28
29 +static int get_layout_shallow(struct repository *repo, struct strbuf *buf)
30 +{
31 + strbuf_addstr(buf,
32 + is_repository_shallow(repo) ? "true" : "false");
33 + return 0;
34 +}
35 +
36 static int get_references_format(struct repository *repo, struct strbuf *buf)
37 {
38 strbuf_addstr(buf,
@@ -35,6 +43,7 @@ static int get_references_format(struct repository *repo, struct strbuf *buf)
43 /* repo_info_fields keys must be in lexicographical order */
44 static const struct field repo_info_fields[] = {
45 { "layout.bare", get_layout_bare },
46 + { "layout.shallow", get_layout_shallow },
47 { "references.format", get_references_format },
48 };
49
t/t1900-repo.sh
+13
@@ -44,6 +44,19 @@ test_repo_info 'bare repository = false is retrieved correctly' \
44 test_repo_info 'bare repository = true is retrieved correctly' \
45 'git init --bare' 'bare' 'layout.bare' 'true'
46
47 +test_repo_info 'shallow repository = false is retrieved correctly' \
48 + 'git init' 'nonshallow' 'layout.shallow' 'false'
49 +
50 +test_expect_success 'setup remote' '
51 + git init remote &&
52 + echo x >remote/x &&
53 + git -C remote add x &&
54 + git -C remote commit -m x
55 +'
56 +
57 +test_repo_info 'shallow repository = true is retrieved correctly' \
58 + 'git clone --depth 1 "file://$PWD/remote"' 'shallow' 'layout.shallow' 'true'
59 +
60 test_expect_success 'values returned in order requested' '
61 cat >expect <<-\EOF &&
62 layout.bare=false