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@xxxxxxxxxxxxx> Helped-by: Junio C Hamano <gitster@xxxxxxxxx> Helped-by: Justin Tobler <jltobler@xxxxxxxxx> Mentored-by: Karthik Nayak <karthik.188@xxxxxxxxx> Mentored-by: Patrick Steinhardt <ps@xxxxxx> Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@xxxxxxxxx> --- Documentation/git-repo.adoc | 1 + builtin/repo.c | 9 +++++++++ t/t1900-repo.sh | 21 +++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc index d52f4666be..3f920b619f 100644 --- a/Documentation/git-repo.adoc +++ b/Documentation/git-repo.adoc @@ -36,6 +36,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 2aba6a39c7..37fb1803f6 100644 --- a/builtin/repo.c +++ b/builtin/repo.c @@ -5,6 +5,7 @@ #include "parse-options.h" #include "refs.h" #include "strbuf.h" +#include "shallow.h" typedef int get_value_fn(struct repository *repo, struct strbuf *buf); @@ -20,6 +21,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, @@ -30,6 +38,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 7304629cb2..0bdbf6911e 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 'git-repo-info aborts if an invalid key is requested' ' test_when_finished "rm -rf expected err" && echo "error: key '\'foo\'' not found" >expected && @@ -60,4 +74,11 @@ test_expect_success "only one value is returned if the same key is requested twi test_cmp expected_value actual_value ' +test_expect_success 'output is returned correctly when two keys are requested' ' + test_when_finished "rm -f expect" && + printf "layout.bare=false\nlayout.shallow=false\n" >expect && + git repo info layout.shallow layout.bare >actual && + test_cmp expect actual +' + test_done -- 2.39.5 (Apple Git-154)