Skip to content

Commit 16a64b5

Browse files
lucasoshirogitster
authored andcommitted
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 <[email protected]> Helped-by: Junio C Hamano <[email protected]> Helped-by: Justin Tobler <[email protected]> Helped-by: Eric Sunshine <[email protected]> Mentored-by: Karthik Nayak <[email protected]> Mentored-by: Patrick Steinhardt <[email protected]> Signed-off-by: Lucas Seiki Oshiro <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 02a1d80 commit 16a64b5

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

Documentation/git-repo.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ values that they return:
4040
`layout.bare`::
4141
`true` if this is a bare repository, otherwise `false`.
4242

43+
`layout.shallow`::
44+
`true` if this is a shallow repository, otherwise `false`.
45+
4346
`references.format`::
4447
The reference storage format. The valid values are:
4548
+

builtin/repo.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "quote.h"
77
#include "refs.h"
88
#include "strbuf.h"
9+
#include "shallow.h"
910

1011
static const char *const repo_usage[] = {
1112
"git repo info [<key>...]",
@@ -25,6 +26,13 @@ static int get_layout_bare(struct repository *repo UNUSED, struct strbuf *buf)
2526
return 0;
2627
}
2728

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+
2836
static int get_references_format(struct repository *repo, struct strbuf *buf)
2937
{
3038
strbuf_addstr(buf,
@@ -35,6 +43,7 @@ static int get_references_format(struct repository *repo, struct strbuf *buf)
3543
/* repo_info_fields keys should be in lexicographical order */
3644
static const struct field repo_info_fields[] = {
3745
{ "layout.bare", get_layout_bare },
46+
{ "layout.shallow", get_layout_shallow },
3847
{ "references.format", get_references_format },
3948
};
4049

t/t1900-repo.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ test_repo_info 'bare repository = false is retrieved correctly' \
4141
test_repo_info 'bare repository = true is retrieved correctly' \
4242
'git init --bare' 'bare' 'layout.bare' 'true'
4343

44+
test_repo_info 'shallow repository = false is retrieved correctly' \
45+
'git init' 'nonshallow' 'layout.shallow' 'false'
46+
47+
test_repo_info 'shallow repository = true is retrieved correctly' \
48+
'git init remote &&
49+
echo x >remote/x &&
50+
git -C remote add x &&
51+
git -C remote commit -m x &&
52+
git clone --depth 1 "file://$PWD/remote"' 'shallow' 'layout.shallow' 'true'
53+
4454
test_expect_success 'git-repo-info fails if an invalid key is requested' '
4555
echo "error: key '\'foo\'' not found" >expected_err &&
4656
test_must_fail git repo info foo 2>actual_err &&

0 commit comments

Comments
 (0)