repo: add --all to git-repo-info
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>
Lucas Seiki Oshiro committed
Nov 18, 2025 at 17:37 UTC
155caac7d1fa981b21192c598cf9bbffdb5aea12
3 files changed
+51
-5
Documentation/git-repo.adoc
+3
-3
@@ -8,7 +8,7 @@ git-repo - Retrieve information about the repository
8
SYNOPSIS
9
--------
10
[synopsis]
11
-git repo info [--format=(keyvalue|nul)] [-z] [<key>...]
11
+git repo info [--format=(keyvalue|nul)] [-z] [--all | <key>...]
12
git repo structure [--format=(table|keyvalue|nul)]
13
14
DESCRIPTION
@@ -19,13 +19,13 @@ THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE.
19
20
COMMANDS
21
--------
22
-`info [--format=(keyvalue|nul)] [-z] [<key>...]`::
22
+`info [--format=(keyvalue|nul)] [-z] [--all | <key>...]`::
23
Retrieve metadata-related information about the current repository. Only
24
the requested data will be returned based on their keys (see "INFO KEYS"
25
section below).
26
+
27
The values are returned in the same order in which their respective keys were
28
-requested.
28
+requested. The `--all` flag requests the values for all the available keys.
29
+
30
The output format can be chosen through the flag `--format`. Two formats are
31
supported:
builtin/repo.c
+27
-2
@@ -15,7 +15,7 @@
15
#include "utf8.h"
16
17
static const char *const repo_usage[] = {
18
- "git repo info [--format=(keyvalue|nul)] [-z] [<key>...]",
18
+ "git repo info [--format=(keyvalue|nul)] [-z] [--all | <key>...]",
19
"git repo structure [--format=(table|keyvalue|nul)]",
20
NULL
21
};
@@ -129,6 +129,23 @@ static int print_fields(int argc, const char **argv,
129
return ret;
130
}
131
132
+static int print_all_fields(struct repository *repo,
133
+ enum output_format format)
134
+{
135
+ struct strbuf valbuf = STRBUF_INIT;
136
+
137
+ for (size_t i = 0; i < ARRAY_SIZE(repo_info_fields); i++) {
138
+ const struct field *field = &repo_info_fields[i];
139
+
140
+ strbuf_reset(&valbuf);
141
+ field->get_value(repo, &valbuf);
142
+ print_field(format, field->key, valbuf.buf);
143
+ }
144
+
145
+ strbuf_release(&valbuf);
146
+ return 0;
147
+}
148
+
149
static int parse_format_cb(const struct option *opt,
150
const char *arg, int unset UNUSED)
151
{
@@ -152,6 +169,7 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
169
struct repository *repo)
170
{
171
enum output_format format = FORMAT_KEYVALUE;
172
+ int all_keys = 0;
173
struct option options[] = {
174
OPT_CALLBACK_F(0, "format", &format, N_("format"),
175
N_("output format"),
@@ -160,6 +178,7 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
178
N_("synonym for --format=nul"),
179
PARSE_OPT_NONEG | PARSE_OPT_NOARG,
180
parse_format_cb),
181
+ OPT_BOOL(0, "all", &all_keys, N_("print all keys/values")),
182
OPT_END()
183
};
184
@@ -167,7 +186,13 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
186
if (format != FORMAT_KEYVALUE && format != FORMAT_NUL_TERMINATED)
187
die(_("unsupported output format"));
188
170
- return print_fields(argc, argv, repo, format);
189
+ if (all_keys && argc)
190
+ die(_("--all and <key> cannot be used together"));
191
+
192
+ if (all_keys)
193
+ return print_all_fields(repo, format);
194
+ else
195
+ return print_fields(argc, argv, repo, format);
196
}
197
198
struct ref_stats {
t/t1900-repo.sh
+21
@@ -4,6 +4,15 @@ test_description='test git repo-info'
4
5
. ./test-lib.sh
6
7
+# git-repo-info keys. It must contain the same keys listed in the const
8
+# repo_info_fields, in lexicographical order.
9
+REPO_INFO_KEYS='
10
+ layout.bare
11
+ layout.shallow
12
+ object.format
13
+ references.format
14
+'
15
+
16
# Test whether a key-value pair is correctly returned
17
#
18
# 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' '
119
test_cmp expected actual
120
'
121
122
+test_expect_success 'git repo info --all returns all key-value pairs' '
123
+ git repo info $REPO_INFO_KEYS >expect &&
124
+ git repo info --all >actual &&
125
+ test_cmp expect actual
126
+'
127
+
128
+test_expect_success 'git repo info --all <key> aborts' '
129
+ echo "fatal: --all and <key> cannot be used together" >expect &&
130
+ test_must_fail git repo info --all object.format 2>actual &&
131
+ test_cmp expect actual
132
+'
133
+
134
test_done