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 <karthik.188@xxxxxxxxx> Mentored-by Patrick Steinhardt <ps@xxxxxx> Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@xxxxxxxxx> --- builtin/repo-info.c | 21 ++++++++++++++++++++- t/t1900-repo-info.sh | 16 +++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/builtin/repo-info.c b/builtin/repo-info.c index 1650d3595c..4c265c05fa 100644 --- a/builtin/repo-info.c +++ b/builtin/repo-info.c @@ -7,6 +7,7 @@ #include "parse-options.h" #include "quote.h" #include "refs.h" +#include "shallow.h" enum output_format { FORMAT_JSON, @@ -23,7 +24,8 @@ enum repo_info_references_field { }; enum repo_info_layout_field { - FIELD_LAYOUT_BARE = 1 << 0 + FIELD_LAYOUT_BARE = 1 << 0, + FIELD_LAYOUT_SHALLOW = 1 << 1 }; struct repo_info_field { @@ -49,6 +51,10 @@ static struct repo_info_field default_fields[] = { { .category = CATEGORY_LAYOUT, .field.layout = FIELD_LAYOUT_BARE + }, + { + .category = CATEGORY_LAYOUT, + .field.layout = FIELD_LAYOUT_SHALLOW } }; @@ -91,6 +97,9 @@ static void repo_info_init(struct repo_info *repo_info, } else if (!strcmp(arg, "layout.bare")) { field->category = CATEGORY_LAYOUT; field->field.layout = FIELD_LAYOUT_BARE; + } else if (!strcmp(arg, "layout.shallow")) { + field->category = CATEGORY_LAYOUT; + field->field.layout = FIELD_LAYOUT_SHALLOW; } else { die("invalid field '%s'", arg); } @@ -125,6 +134,11 @@ static void repo_info_print_plaintext(struct repo_info *repo_info) { is_bare_repository() ? "true" : "false"); break; + case FIELD_LAYOUT_SHALLOW: + print_key_value("layout.shallow", + is_repository_shallow(repo) ? + "true" : "false"); + break; } break; } @@ -173,6 +187,11 @@ static void repo_info_print_json(struct repo_info *repo_info) jw_object_bool(&jw, "bare", is_bare_repository()); } + + if (layout_fields & FIELD_LAYOUT_SHALLOW) { + jw_object_bool(&jw, "shallow", + is_repository_shallow(repo)); + } jw_end(&jw); } jw_end(&jw); diff --git a/t/t1900-repo-info.sh b/t/t1900-repo-info.sh index 0d1096b40b..5cd2f8d187 100755 --- a/t/t1900-repo-info.sh +++ b/t/t1900-repo-info.sh @@ -6,7 +6,7 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh -DEFAULT_NUMBER_OF_FIELDS=2 +DEFAULT_NUMBER_OF_FIELDS=3 parse_json () { tr '\n' ' ' | "$PERL_PATH" "$TEST_DIRECTORY/t0019/parse_json.perl" @@ -77,6 +77,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 'plaintext: output all default fields' " git repo-info --format=plaintext >actual && test_line_count = $DEFAULT_NUMBER_OF_FIELDS actual -- 2.39.5 (Apple Git-154)