Add the field layout.bare to the repo-info command. The data retrieved in this field is the same that currently is obtained by running `git rev-parse --is-bare-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 | 41 ++++++++++++++++++++++++++++++++++++++++- t/t1900-repo-info.sh | 8 +++++++- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/builtin/repo-info.c b/builtin/repo-info.c index 6ce3e6134f..1650d3595c 100644 --- a/builtin/repo-info.c +++ b/builtin/repo-info.c @@ -1,4 +1,8 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "builtin.h" +#include "environment.h" +#include "hash.h" #include "json-writer.h" #include "parse-options.h" #include "quote.h" @@ -10,17 +14,23 @@ enum output_format { }; enum repo_info_category { - CATEGORY_REFERENCES = 1 << 0 + CATEGORY_REFERENCES = 1 << 0, + CATEGORY_LAYOUT = 1 << 1 }; enum repo_info_references_field { FIELD_REFERENCES_FORMAT = 1 << 0 }; +enum repo_info_layout_field { + FIELD_LAYOUT_BARE = 1 << 0 +}; + struct repo_info_field { enum repo_info_category category; union { enum repo_info_references_field references; + enum repo_info_layout_field layout; } field; }; @@ -35,6 +45,10 @@ static struct repo_info_field default_fields[] = { { .category = CATEGORY_REFERENCES, .field.references = FIELD_REFERENCES_FORMAT + }, + { + .category = CATEGORY_LAYOUT, + .field.layout = FIELD_LAYOUT_BARE } }; @@ -74,6 +88,9 @@ static void repo_info_init(struct repo_info *repo_info, if (!strcmp(arg, "references.format")) { field->category = CATEGORY_REFERENCES; field->field.references = FIELD_REFERENCES_FORMAT; + } else if (!strcmp(arg, "layout.bare")) { + field->category = CATEGORY_LAYOUT; + field->field.layout = FIELD_LAYOUT_BARE; } else { die("invalid field '%s'", arg); } @@ -101,6 +118,15 @@ static void repo_info_print_plaintext(struct repo_info *repo_info) { break; } break; + case CATEGORY_LAYOUT: + switch (field->field.layout) { + case FIELD_LAYOUT_BARE: + print_key_value("layout.bare", + is_bare_repository() ? + "true" : "false"); + break; + } + break; } } } @@ -111,6 +137,7 @@ static void repo_info_print_json(struct repo_info *repo_info) int i; unsigned int categories = 0; unsigned int references_fields = 0; + unsigned int layout_fields = 0; struct repository *repo = repo_info->repo; for (i = 0; i < repo_info->n_fields; i++) { @@ -120,6 +147,9 @@ static void repo_info_print_json(struct repo_info *repo_info) case CATEGORY_REFERENCES: references_fields |= field->field.references; break; + case CATEGORY_LAYOUT: + layout_fields |= field->field.layout; + break; } } @@ -136,6 +166,15 @@ static void repo_info_print_json(struct repo_info *repo_info) } jw_end(&jw); } + + if (categories & CATEGORY_LAYOUT) { + jw_object_inline_begin_object(&jw, "layout"); + if (layout_fields & FIELD_LAYOUT_BARE) { + jw_object_bool(&jw, "bare", + is_bare_repository()); + } + jw_end(&jw); + } jw_end(&jw); puts(jw.json.buf); diff --git a/t/t1900-repo-info.sh b/t/t1900-repo-info.sh index d6e6f6ed1d..0d1096b40b 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=1 +DEFAULT_NUMBER_OF_FIELDS=2 parse_json () { tr '\n' ' ' | "$PERL_PATH" "$TEST_DIRECTORY/t0019/parse_json.perl" @@ -71,6 +71,12 @@ test_repo_info 'ref format files is retrieved correctly' ' test_repo_info 'ref format reftable is retrieved correctly' ' git init --ref-format=reftable repo' 'references.format' 'reftable' +test_repo_info 'bare repository = false is retrieved correctly' ' + git init repo' 'layout.bare' 'false' + +test_repo_info 'bare repository = true is retrieved correctly' ' + git init --bare repo' 'layout.bare' '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)