]> git.ipfire.org Git - thirdparty/git.git/commitdiff
repo: add --all to git-repo-info
authorLucas Seiki Oshiro <lucasseikioshiro@gmail.com>
Sun, 26 Oct 2025 22:52:08 +0000 (19:52 -0300)
committerJunio C Hamano <gitster@pobox.com>
Sun, 26 Oct 2025 23:35:12 +0000 (16:35 -0700)
Add a new flag `--all` to git-repo-info for requesting values for all
the available keys. By using this flag, the user can retrieve all the
values instead of searching what are the desired keys for what they
wants.

Helped-by: Karthik Nayak <karthik.188@gmail.com>
Helped-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-repo.adoc
builtin/repo.c
t/t1900-repo.sh

index 209afd1b6152be5bfce3eea56ca5c8538e7cd657..e61af9ce3b8d059138c6c137629c67d3917c5684 100644 (file)
@@ -8,7 +8,7 @@ git-repo - Retrieve information about the repository
 SYNOPSIS
 --------
 [synopsis]
-git repo info [--format=(keyvalue|nul)] [-z] [<key>...]
+git repo info [--format=(keyvalue|nul)] [-z] [--all | <key>...]
 
 DESCRIPTION
 -----------
@@ -18,13 +18,13 @@ THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE.
 
 COMMANDS
 --------
-`info [--format=(keyvalue|nul)] [-z] [<key>...]`::
+`info [--format=(keyvalue|nul)] [-z] [--all | <key>...]`::
        Retrieve metadata-related information about the current repository. Only
        the requested data will be returned based on their keys (see "INFO KEYS"
        section below).
 +
 The values are returned in the same order in which their respective keys were
-requested.
+requested. The `--all` flag requests the values for all the available keys.
 +
 The output format can be chosen through the flag `--format`. Two formats are
 supported:
index 3b071e9a50f2e9e61c17951c54ea4da396c8dc41..67d647bb3c72b949c3ef6d5e8e8bcac20e3f8ab8 100644 (file)
@@ -9,7 +9,7 @@
 #include "shallow.h"
 
 static const char *const repo_usage[] = {
-       "git repo info [--format=(keyvalue|nul)] [-z] [<key>...]",
+       "git repo info [--format=(keyvalue|nul)] [-z] [--all | <key>...]",
        NULL
 };
 
@@ -124,6 +124,24 @@ static int print_fields(int argc, const char **argv,
        return ret;
 }
 
+static void print_all_fields(struct repository *repo,
+                            enum output_format format)
+{
+       struct strbuf valbuf = STRBUF_INIT;
+       struct strbuf quotbuf = STRBUF_INIT;
+
+       for (unsigned long i = 0; i < ARRAY_SIZE(repo_info_fields); i++) {
+               struct field field = repo_info_fields[i];
+
+               strbuf_reset(&valbuf);
+               field.get_value(repo, &valbuf);
+               print_field(format, field.key, &valbuf, &quotbuf);
+       }
+
+       strbuf_release(&valbuf);
+       strbuf_release(&quotbuf);
+}
+
 static int parse_format_cb(const struct option *opt,
                           const char *arg, int unset UNUSED)
 {
@@ -145,6 +163,7 @@ static int repo_info(int argc, const char **argv, const char *prefix,
                     struct repository *repo)
 {
        enum output_format format = FORMAT_KEYVALUE;
+       int all_keys = 0;
        struct option options[] = {
                OPT_CALLBACK_F(0, "format", &format, N_("format"),
                               N_("output format"),
@@ -153,11 +172,20 @@ static int repo_info(int argc, const char **argv, const char *prefix,
                               N_("synonym for --format=nul"),
                               PARSE_OPT_NONEG | PARSE_OPT_NOARG,
                               parse_format_cb),
+               OPT_BOOL(0, "all", &all_keys, N_("return all keys")),
                OPT_END()
        };
 
        argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
 
+       if (all_keys) {
+               if (argc)
+                       die(_("--all and <key> cannot be used together"));
+
+               print_all_fields(repo, format);
+               return 0;
+       }
+
        return print_fields(argc, argv, repo, format);
 }
 
index 2beba67889af25d3547a223e62f45037dba7f171..51d55f11a5ed664bc5927b12677f56ad76f32070 100755 (executable)
@@ -4,6 +4,15 @@ test_description='test git repo-info'
 
 . ./test-lib.sh
 
+# git-repo-info keys. It must contain the same keys listed in the const
+# repo_info_fields, in lexicographical order.
+REPO_INFO_KEYS='
+       layout.bare
+       layout.shallow
+       object.format
+       references.format
+'
+
 # Test whether a key-value pair is correctly returned
 #
 # Usage: test_repo_info <label> <init command> <repo_name> <key> <expected value>
@@ -110,4 +119,16 @@ test_expect_success 'git repo info uses the last requested format' '
        test_cmp expected actual
 '
 
+test_expect_success 'git repo info --all returns all key-value pairs' '
+       git repo info $REPO_INFO_KEYS >expect &&
+       git repo info --all >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'git repo info --all <key> aborts' '
+       echo "fatal: --all and <key> cannot be used together" >expect &&
+       test_must_fail git repo info --all object.format 2>actual &&
+       test_cmp expect actual
+'
+
 test_done