]> git.ipfire.org Git - thirdparty/git.git/commitdiff
repo: add the field layout.shallow
authorLucas Seiki Oshiro <lucasseikioshiro@gmail.com>
Sat, 16 Aug 2025 22:46:02 +0000 (19:46 -0300)
committerJunio C Hamano <gitster@pobox.com>
Sun, 17 Aug 2025 16:13:40 +0000 (09:13 -0700)
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>
Documentation/git-repo.adoc
builtin/repo.c
t/t1900-repo.sh

index 932b08c26fad7ac8d6de7cde07dd717b67d7827d..01b7f9c95e3f44621c33bca6581dd5e044cc62d5 100644 (file)
@@ -41,6 +41,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:
 +
index aada476e1cbd9e3126010151295ff9fe1cce4456..3c9140593bc95671fedd422a62dd9eb1d3b49d0b 100644 (file)
@@ -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>...]",
@@ -25,6 +26,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,
@@ -35,6 +43,7 @@ static int get_references_format(struct repository *repo, struct strbuf *buf)
 /* repo_info_fields keys must 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 },
 };
 
index b0438d276eec99899f77b97afdac00af1eed8fdf..6a9cbf3d4714c2cdb71a875450d499db022c1fa0 100755 (executable)
@@ -44,6 +44,19 @@ test_repo_info 'bare repository = false is retrieved correctly' \
 test_repo_info 'bare repository = true is retrieved correctly' \
        'git init --bare' 'bare' 'layout.bare' 'true'
 
+test_repo_info 'shallow repository = false is retrieved correctly' \
+       'git init' 'nonshallow' 'layout.shallow' 'false'
+
+test_expect_success 'setup remote' '
+       git init remote &&
+       echo x >remote/x &&
+       git -C remote add x &&
+       git -C remote commit -m x
+'
+
+test_repo_info 'shallow repository = true is retrieved correctly' \
+       'git clone --depth 1 "file://$PWD/remote"' 'shallow' 'layout.shallow' 'true'
+
 test_expect_success 'values returned in order requested' '
        cat >expect <<-\EOF &&
        layout.bare=false