Skip to content

Commit 7b6f18a

Browse files
lucasoshirogitster
authored andcommitted
repo-info: add field layout.shallow
Add the field layout.shallow to the repo-info command. The data retrieved in this field is the same that currently is obtained by running `git rev-parse --is-shallow-repository`. 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 32acbd9 commit 7b6f18a

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

builtin/repo-info.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "parse-options.h"
88
#include "quote.h"
99
#include "refs.h"
10+
#include "shallow.h"
1011

1112
enum output_format {
1213
FORMAT_JSON,
@@ -23,7 +24,8 @@ enum repo_info_references_field {
2324
};
2425

2526
enum repo_info_layout_field {
26-
FIELD_LAYOUT_BARE = 1 << 0
27+
FIELD_LAYOUT_BARE = 1 << 0,
28+
FIELD_LAYOUT_SHALLOW = 1 << 1
2729
};
2830

2931
struct repo_info_field {
@@ -49,6 +51,10 @@ static struct repo_info_field default_fields[] = {
4951
{
5052
.category = CATEGORY_LAYOUT,
5153
.field.layout = FIELD_LAYOUT_BARE
54+
},
55+
{
56+
.category = CATEGORY_LAYOUT,
57+
.field.layout = FIELD_LAYOUT_SHALLOW
5258
}
5359
};
5460

@@ -91,6 +97,9 @@ static void repo_info_init(struct repo_info *repo_info,
9197
} else if (!strcmp(arg, "layout.bare")) {
9298
field->category = CATEGORY_LAYOUT;
9399
field->field.layout = FIELD_LAYOUT_BARE;
100+
} else if (!strcmp(arg, "layout.shallow")) {
101+
field->category = CATEGORY_LAYOUT;
102+
field->field.layout = FIELD_LAYOUT_SHALLOW;
94103
} else {
95104
die("invalid field '%s'", arg);
96105
}
@@ -125,6 +134,11 @@ static void repo_info_print_plaintext(struct repo_info *repo_info) {
125134
is_bare_repository() ?
126135
"true" : "false");
127136
break;
137+
case FIELD_LAYOUT_SHALLOW:
138+
print_key_value("layout.shallow",
139+
is_repository_shallow(repo) ?
140+
"true" : "false");
141+
break;
128142
}
129143
break;
130144
}
@@ -173,6 +187,11 @@ static void repo_info_print_json(struct repo_info *repo_info)
173187
jw_object_bool(&jw, "bare",
174188
is_bare_repository());
175189
}
190+
191+
if (layout_fields & FIELD_LAYOUT_SHALLOW) {
192+
jw_object_bool(&jw, "shallow",
193+
is_repository_shallow(repo));
194+
}
176195
jw_end(&jw);
177196
}
178197
jw_end(&jw);

t/t1900-repo-info.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
66

77
. ./test-lib.sh
88

9-
DEFAULT_NUMBER_OF_FIELDS=2
9+
DEFAULT_NUMBER_OF_FIELDS=3
1010

1111
parse_json () {
1212
tr '\n' ' ' | "$PERL_PATH" "$TEST_DIRECTORY/t0019/parse_json.perl"
@@ -77,6 +77,20 @@ test_repo_info 'bare repository = false is retrieved correctly' '
7777
test_repo_info 'bare repository = true is retrieved correctly' '
7878
git init --bare repo' 'layout.bare' 'true'
7979

80+
test_repo_info 'shallow repository = false is retrieved correctly' '
81+
git init repo' 'layout.shallow' 'false'
82+
83+
test_repo_info 'shallow repository = true is retrieved correctly' '
84+
git init remote &&
85+
cd remote &&
86+
echo x >x &&
87+
git add x &&
88+
git commit -m x &&
89+
cd .. &&
90+
git clone --depth 1 "file://$PWD/remote" repo &&
91+
rm -rf remote
92+
' 'layout.shallow' 'true'
93+
8094
test_expect_success 'plaintext: output all default fields' "
8195
git repo-info --format=plaintext >actual &&
8296
test_line_count = $DEFAULT_NUMBER_OF_FIELDS actual

0 commit comments

Comments
 (0)