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]
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 | 1 +
builtin/repo.c | 7 +++++++
t/t1900-repo.sh | 22 ++++++++++++++++++++++
3 files changed, 30 insertions(+)
diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
index db185c5c91..864868993b 100644
--- a/Documentation/git-repo.adoc
+++ b/Documentation/git-repo.adoc
@@ -52,6 +52,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 5eefe06918..d75417a48b 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -5,6 +5,7 @@
#include "strbuf.h"
#include "refs.h"
#include "environment.h"
+#include "shallow.h"
typedef void add_field_fn(struct strbuf *buf, struct repository *repo);
@@ -39,9 +40,15 @@ static void add_layout_bare(struct strbuf *buf, struct repository *repo UNUSED)
add_bool(buf, "layout.bare", is_bare_repository());
}
+static void add_layout_shallow(struct strbuf *buf, struct repository *repo)
+{
+ add_bool(buf, "layout.shallow", is_repository_shallow(repo));
+}
+
// repo_info_fields keys should be in lexicographical order
static const struct field repo_info_fields[] = {
{"layout.bare", add_layout_bare},
+ {"layout.shallow", add_layout_shallow},
{"references.format", add_references_format},
};
diff --git a/t/t1900-repo.sh b/t/t1900-repo.sh
index 6155e275b5..e0e2393247 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" '
echo "references.format" > expected &&
git rev-parse --show-ref-format > ref-format &&
@@ -50,4 +64,12 @@ test_expect_success "only one value is returned if the same key is requested twi
test_cmp expected actual
'
+test_expect_success 'output is returned correctly when two keys are requested' '
+ test_when_finished "rm -f expect" &&
+ printf "layout.bare\nfalseQlayout.shallow\nfalseQ" >expect &&
+ git repo info layout.shallow layout.bare >output &&
+ nul_to_q <output >actual &&
+ test_cmp expect actual
+'
+
test_done
--
2.39.5 (Apple Git-154)