Skip to content

Commit e52cd65

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 acf2669 commit e52cd65

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

Documentation/git-repo.adoc

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

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

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 must 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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ test_repo_info 'bare repository = false is retrieved correctly' \
4444
test_repo_info 'bare repository = true is retrieved correctly' \
4545
'git init --bare' 'bare' 'layout.bare' 'true'
4646

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+
4760
test_expect_success 'values returned in order requested' '
4861
cat >expect <<-\EOF &&
4962
layout.bare=false

0 commit comments

Comments
 (0)