From: Lucas Seiki Oshiro <lucasseikioshiro@gmail•com>
To: git@vger•kernel.org
Cc: sunshine@sunshineco•com, ps@pks•im, karthik.188@gmail•com,
gitster@pobox•com,
Lucas Seiki Oshiro <lucasseikioshiro@gmail•com>
Subject: [PATCH v4 2/2] repo: add --all to git-repo-info
Date: Mon, 17 Nov 2025 12:02:52 -0300 [thread overview]
Message-ID: <20251117151844.14802-3-lucasseikioshiro@gmail.com> (raw)
In-Reply-To: <20251117151844.14802-1-lucasseikioshiro@gmail.com>
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>
---
Documentation/git-repo.adoc | 6 +++---
builtin/repo.c | 28 +++++++++++++++++++++++++++-
t/t1900-repo.sh | 21 +++++++++++++++++++++
3 files changed, 51 insertions(+), 4 deletions(-)
diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
index ce43cb19c8..70f0a6d2e4 100644
--- a/Documentation/git-repo.adoc
+++ b/Documentation/git-repo.adoc
@@ -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>...]
git repo structure [--format=(table|keyvalue|nul)]
DESCRIPTION
@@ -19,13 +19,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:
diff --git a/builtin/repo.c b/builtin/repo.c
index f9fb418494..22a9ecb3a1 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -15,7 +15,7 @@
#include "utf8.h"
static const char *const repo_usage[] = {
- "git repo info [--format=(keyvalue|nul)] [-z] [<key>...]",
+ "git repo info [--format=(keyvalue|nul)] [-z] [--all | <key>...]",
"git repo structure [--format=(table|keyvalue|nul)]",
NULL
};
@@ -129,6 +129,22 @@ 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;
+
+ for (unsigned long i = 0; i < ARRAY_SIZE(repo_info_fields); i++) {
+ const struct field *field = &repo_info_fields[i];
+
+ strbuf_reset(&valbuf);
+ field->get_value(repo, &valbuf);
+ print_field(format, field->key, valbuf.buf);
+ }
+
+ strbuf_release(&valbuf);
+}
+
static int parse_format_cb(const struct option *opt,
const char *arg, int unset UNUSED)
{
@@ -152,6 +168,7 @@ static int cmd_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"),
@@ -160,6 +177,7 @@ static int cmd_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_("print all keys/values")),
OPT_END()
};
@@ -167,6 +185,14 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
if (format != FORMAT_KEYVALUE && format != FORMAT_NUL_TERMINATED)
die(_("unsupported output format"));
+ 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);
}
diff --git a/t/t1900-repo.sh b/t/t1900-repo.sh
index 2beba67889..51d55f11a5 100755
--- a/t/t1900-repo.sh
+++ b/t/t1900-repo.sh
@@ -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
--
2.50.1 (Apple Git-155)
next prev parent reply other threads:[~2025-11-17 15:22 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-15 22:36 [PATCH] repo: add --all to git-repo-info Lucas Seiki Oshiro
2025-09-15 23:58 ` Junio C Hamano
2025-09-16 8:06 ` Patrick Steinhardt
2025-09-16 16:19 ` Junio C Hamano
2025-09-17 5:34 ` Patrick Steinhardt
2025-10-26 22:52 ` [PATCH v3 0/2] " Lucas Seiki Oshiro
2025-10-26 22:52 ` [PATCH v3 1/2] repo: factor out field printing to dedicated function Lucas Seiki Oshiro
2025-10-26 23:53 ` Eric Sunshine
2025-10-26 23:56 ` Eric Sunshine
2025-10-27 14:56 ` Junio C Hamano
2025-10-27 16:09 ` Eric Sunshine
2025-10-26 22:52 ` [PATCH v3 2/2] repo: add --all to git-repo-info Lucas Seiki Oshiro
2025-10-27 0:22 ` Eric Sunshine
2025-10-27 0:24 ` Eric Sunshine
2025-11-17 15:02 ` [PATCH v4 0/2] " Lucas Seiki Oshiro
2025-11-17 15:02 ` [PATCH v4 1/2] repo: factor out field printing to dedicated function Lucas Seiki Oshiro
2025-11-17 18:48 ` Junio C Hamano
2025-11-17 15:02 ` Lucas Seiki Oshiro [this message]
2025-11-17 18:58 ` [PATCH v4 2/2] repo: add --all to git-repo-info Junio C Hamano
2025-11-18 20:16 ` Lucas Seiki Oshiro
2025-11-18 21:28 ` Junio C Hamano
2025-11-20 22:50 ` Lucas Seiki Oshiro
2025-11-19 7:32 ` Eric Sunshine
2025-11-19 14:33 ` Junio C Hamano
2025-11-17 18:14 ` [PATCH v4 0/2] " Junio C Hamano
2025-11-18 20:37 ` [PATCH v5 " Lucas Seiki Oshiro
2025-11-18 20:37 ` [PATCH v5 1/2] repo: factor out field printing to dedicated function Lucas Seiki Oshiro
2025-11-18 20:37 ` [PATCH v5 2/2] repo: add --all to git-repo-info Lucas Seiki Oshiro
2025-11-18 21:34 ` [PATCH v5 0/2] " Junio C Hamano
2025-11-19 7:35 ` Eric Sunshine
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251117151844.14802-3-lucasseikioshiro@gmail.com \
--to=lucasseikioshiro@gmail$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=gitster@pobox$(echo .)com \
--cc=karthik.188@gmail$(echo .)com \
--cc=ps@pks$(echo .)im \
--cc=sunshine@sunshineco$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox