* [PATCH] repo: add new flag --keys to git-repo-info
@ 2025-12-07 19:02 Lucas Seiki Oshiro
2025-12-07 22:14 ` Junio C Hamano
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Lucas Seiki Oshiro @ 2025-12-07 19:02 UTC (permalink / raw)
To: git; +Cc: Lucas Seiki Oshiro
Currently, if the user wants to find what are the available keys,
they need to either check the documentation or to ask to all the
key-value pairs by using --all.
Add a new flag --keys for listing only the available keys without
listing the values.
Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
---
Hi!
After the Junio's suggestion [1], this patch adds a new flag --keys to
git-repo-info. This new flag only prints the available keys, without
printing the corresponding values.
This patch is based on top of master bdc5341ff6 (The sixth batch,
2025-12-05) with lo/repo-struct-z merged.
[1] https://lore.kernel.org/git/xmqq8qg3do99.fsf@gitster.g/
Documentation/git-repo.adoc | 4 ++++
builtin/repo.c | 17 +++++++++++++++++
t/t1900-repo.sh | 13 ++-----------
3 files changed, 23 insertions(+), 11 deletions(-)
diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
index c4a78277df..f0f4d77db8 100644
--- a/Documentation/git-repo.adoc
+++ b/Documentation/git-repo.adoc
@@ -9,6 +9,7 @@ SYNOPSIS
--------
[synopsis]
git repo info [--format=(keyvalue|nul) | -z] [--all | <key>...]
+git repo info --keys
git repo structure [--format=(table|keyvalue|nul) | -z]
DESCRIPTION
@@ -44,6 +45,9 @@ supported:
+
`-z` is an alias for `--format=nul`.
+`info --keys`::
+List all the available keys, one per line.
+
`structure [--format=(table|keyvalue|nul) | -z]`::
Retrieve statistics about the current repository structure. The
following kinds of information are reported:
diff --git a/builtin/repo.c b/builtin/repo.c
index 0dd41b1778..45e9d59d55 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -16,6 +16,7 @@
static const char *const repo_usage[] = {
"git repo info [--format=(keyvalue|nul) | -z] [--all | <key>...]",
+ "git repo info --keys",
"git repo structure [--format=(table|keyvalue|nul) | -z]",
NULL
};
@@ -146,6 +147,16 @@ static int print_all_fields(struct repository *repo,
return 0;
}
+static int print_keys(void)
+{
+ for (size_t i = 0; i < ARRAY_SIZE(repo_info_fields); i++) {
+ const struct field *field = &repo_info_fields[i];
+ puts(field->key);
+ }
+
+ return 0;
+}
+
static int parse_format_cb(const struct option *opt,
const char *arg, int unset UNUSED)
{
@@ -170,6 +181,7 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
{
enum output_format format = FORMAT_KEYVALUE;
int all_keys = 0;
+ int show_keys = 0;
struct option options[] = {
OPT_CALLBACK_F(0, "format", &format, N_("format"),
N_("output format"),
@@ -179,10 +191,15 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
PARSE_OPT_NONEG | PARSE_OPT_NOARG,
parse_format_cb),
OPT_BOOL(0, "all", &all_keys, N_("print all keys/values")),
+ OPT_BOOL(0, "keys", &show_keys, N_("show keys")),
OPT_END()
};
argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
+
+ if (show_keys)
+ return print_keys();
+
if (format != FORMAT_KEYVALUE && format != FORMAT_NUL_TERMINATED)
die(_("unsupported output format"));
diff --git a/t/t1900-repo.sh b/t/t1900-repo.sh
index 51d55f11a5..d6e84a78e5 100755
--- a/t/t1900-repo.sh
+++ b/t/t1900-repo.sh
@@ -4,15 +4,6 @@ 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>
@@ -119,8 +110,8 @@ 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 &&
+test_expect_success 'git repo info --all and git repo info $(git repo info --keys) output the same data' '
+ git repo info $(git repo info --keys) >expect &&
git repo info --all >actual &&
test_cmp expect actual
'
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] repo: add new flag --keys to git-repo-info
2025-12-07 19:02 [PATCH] repo: add new flag --keys to git-repo-info Lucas Seiki Oshiro
@ 2025-12-07 22:14 ` Junio C Hamano
2025-12-08 16:33 ` Lucas Seiki Oshiro
2025-12-08 7:13 ` Patrick Steinhardt
2025-12-09 19:36 ` [PATCH v2 0/2] " Lucas Seiki Oshiro
2 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2025-12-07 22:14 UTC (permalink / raw)
To: Lucas Seiki Oshiro; +Cc: git
Lucas Seiki Oshiro <lucasseikioshiro@gmail.com> writes:
> Currently, if the user wants to find what are the available keys,
> they need to either check the documentation or to ask to all the
> key-value pairs by using --all.
>
> Add a new flag --keys for listing only the available keys without
> listing the values.
We do not need to say "Currently," but other than that the above is
very well written. Easy to grok and to the point.
> [synopsis]
> git repo info [--format=(keyvalue|nul) | -z] [--all | <key>...]
> +git repo info --keys
> git repo structure [--format=(table|keyvalue|nul) | -z]
So "git repo info --keys --all" or "git repo info --keys --format=..."
is not supported. Does the implementation behave sensibly when given
such nonsense commands? Let's see.
> @@ -170,6 +181,7 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
> {
> enum output_format format = FORMAT_KEYVALUE;
> int all_keys = 0;
> + int show_keys = 0;
> struct option options[] = {
> OPT_CALLBACK_F(0, "format", &format, N_("format"),
> N_("output format"),
> @@ -179,10 +191,15 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
> PARSE_OPT_NONEG | PARSE_OPT_NOARG,
> parse_format_cb),
> OPT_BOOL(0, "all", &all_keys, N_("print all keys/values")),
> + OPT_BOOL(0, "keys", &show_keys, N_("show keys")),
> OPT_END()
> };
>
> argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
> +
> + if (show_keys)
> + return print_keys();
> +
> if (format != FORMAT_KEYVALUE && format != FORMAT_NUL_TERMINATED)
> die(_("unsupported output format"));
OK, so it is:
"git repo info --all --keys" and "git repo info --keys layout.bare"
both behave as if "git repo --keys" was given, ignoring
everything else.
Shouldn't "--keys" be explicitly marked incompatible with "--all"
and remaining keys in argc/argv[]?
While there is no strong reason why anybody must use NUL-terminated
output format, simply because repo_info_fields[] contains no tokens
with strange byte values, but just as principle, shouldn't
"git repo info --keys -z"
do what is naturally expected?
Perhaps
if (format != ...)
die(_("unsupported output format"));
if (show_keys && (all_keys || argc))
die(_("--keys cannot be used with a <key> or --all"));
if (show_keys)
return print_keys(output_format);
with a trivial update to print_keys() to support NUL-terminated
records, instead of puts()?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] repo: add new flag --keys to git-repo-info
2025-12-07 19:02 [PATCH] repo: add new flag --keys to git-repo-info Lucas Seiki Oshiro
2025-12-07 22:14 ` Junio C Hamano
@ 2025-12-08 7:13 ` Patrick Steinhardt
2025-12-09 19:36 ` [PATCH v2 0/2] " Lucas Seiki Oshiro
2 siblings, 0 replies; 7+ messages in thread
From: Patrick Steinhardt @ 2025-12-08 7:13 UTC (permalink / raw)
To: Lucas Seiki Oshiro; +Cc: git
On Sun, Dec 07, 2025 at 04:02:10PM -0300, Lucas Seiki Oshiro wrote:
> Currently, if the user wants to find what are the available keys,
> they need to either check the documentation or to ask to all the
This sentence doesn't quite parse. I think you wanted to say "ask for
all" instead of "ask to all" here.
All the other points were already covered by Junio, so I won't comment
on these parts.
Thanks!
Patrick
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] repo: add new flag --keys to git-repo-info
2025-12-07 22:14 ` Junio C Hamano
@ 2025-12-08 16:33 ` Lucas Seiki Oshiro
0 siblings, 0 replies; 7+ messages in thread
From: Lucas Seiki Oshiro @ 2025-12-08 16:33 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Patrick Steinhardt
> We do not need to say "Currently," but other than that the above is
> very well written. Easy to grok and to the point.
Thanks!
> Shouldn't "--keys" be explicitly marked incompatible with "--all"
> and remaining keys in argc/argv[]?
Yes, I'll work on that.
> While there is no strong reason why anybody must use NUL-terminated
> output format, simply because repo_info_fields[] contains no tokens
> with strange byte values, but just as principle, shouldn't
>
> "git repo info --keys -z"
>
> do what is naturally expected?
Hmmm... Perhaps it's too much for this simple flag. `-z` is tied to
--format here, and if we want to support -z we'll also need to
support --format.
What about adding a "default" format for --format? This way, it
would translate to:
- keyvalue, when using info without --keys
- table, when using structure
- using puts, when using info with --keys
Another solution, of course, would be aborting when --format, -z or
--all are used with --keys.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 0/2] repo: add new flag --keys to git-repo-info
2025-12-07 19:02 [PATCH] repo: add new flag --keys to git-repo-info Lucas Seiki Oshiro
2025-12-07 22:14 ` Junio C Hamano
2025-12-08 7:13 ` Patrick Steinhardt
@ 2025-12-09 19:36 ` Lucas Seiki Oshiro
2025-12-09 19:36 ` [PATCH v2 1/2] repo: add a default output format to enum output_format Lucas Seiki Oshiro
2025-12-09 19:36 ` [PATCH v2 2/2] repo: add new flag --keys to git-repo-info Lucas Seiki Oshiro
2 siblings, 2 replies; 7+ messages in thread
From: Lucas Seiki Oshiro @ 2025-12-09 19:36 UTC (permalink / raw)
To: git; +Cc: ps, Lucas Seiki Oshiro
Hi!
This patch series adds a new flag --keys to git-repo-info. This new flag
only prints the available keys, without printing the corresponding
values.
The main change in this version is the compatibility with the flags -z
and --format, allowing the keys to be printed following the
null-terminated format.
This patch is based on top of master bdc5341ff6 (The sixth batch,
2025-12-05) with lo/repo-struct-z merged.
Lucas Seiki Oshiro (2):
repo: add a default output format to enum output_format
repo: add new flag --keys to git-repo-info
Documentation/git-repo.adoc | 11 ++++++++++
builtin/repo.c | 41 ++++++++++++++++++++++++++++++++++++-
t/t1900-repo.sh | 33 +++++++++++++++++++----------
3 files changed, 73 insertions(+), 12 deletions(-)
Range-diff against v1:
-: ---------- > 1: 9eb2549806 repo: add a default output format to enum output_format
1: 1b9b7dceb7 ! 2: c5b7ba8824 repo: add new flag --keys to git-repo-info
@@ Metadata
## Commit message ##
repo: add new flag --keys to git-repo-info
- Currently, if the user wants to find what are the available keys,
- they need to either check the documentation or to ask to all the
- key-value pairs by using --all.
+ If the user wants to find what are the available keys, they need to
+ either check the documentation or to ask for all the key-value pairs
+ by using --all.
Add a new flag --keys for listing only the available keys without
listing the values.
@@ Documentation/git-repo.adoc: SYNOPSIS
--------
[synopsis]
git repo info [--format=(keyvalue|nul) | -z] [--all | <key>...]
-+git repo info --keys
++git repo info --keys [--format=(default|nul) | -z]
git repo structure [--format=(table|keyvalue|nul) | -z]
DESCRIPTION
@@ Documentation/git-repo.adoc: supported:
+
`-z` is an alias for `--format=nul`.
-+`info --keys`::
-+List all the available keys, one per line.
++`info --keys [--format=(default|nul) | -z]`::
++ List all the available keys, one per line. The output format can be chosen
++ through the flag `--format`. The following formats are supported:
+++
++`default`:::
++ output the keys one per line.
++
++`nul`:::
++ similar to `default`, but using a NUL character after each value.
+
`structure [--format=(table|keyvalue|nul) | -z]`::
Retrieve statistics about the current repository structure. The
@@ builtin/repo.c
static const char *const repo_usage[] = {
"git repo info [--format=(keyvalue|nul) | -z] [--all | <key>...]",
-+ "git repo info --keys",
++ "git repo info --keys [--format=(default|nul) | -z]",
"git repo structure [--format=(table|keyvalue|nul) | -z]",
NULL
};
@@ builtin/repo.c: static int print_all_fields(struct repository *repo,
return 0;
}
-+static int print_keys(void)
++static int print_keys(enum output_format format)
+{
++ char sep;
++
++ switch (format) {
++ case FORMAT_DEFAULT:
++ sep = '\n';
++ break;
++ case FORMAT_NUL_TERMINATED:
++ sep = '\0';
++ break;
++ default:
++ die(_("--keys can only be used with --format=default or --format=nul"));
++ }
++
+ for (size_t i = 0; i < ARRAY_SIZE(repo_info_fields); i++) {
+ const struct field *field = &repo_info_fields[i];
-+ puts(field->key);
++ printf("%s%c", field->key, sep);
+ }
+
+ return 0;
@@ builtin/repo.c: static int print_all_fields(struct repository *repo,
{
@@ builtin/repo.c: static int cmd_repo_info(int argc, const char **argv, const char *prefix,
{
- enum output_format format = FORMAT_KEYVALUE;
+ enum output_format format = FORMAT_DEFAULT;
int all_keys = 0;
+ int show_keys = 0;
struct option options[] = {
@@ builtin/repo.c: static int cmd_repo_info(int argc, const char **argv, const char
};
argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
+
++ if (show_keys && (all_keys || argc))
++ die(_("--keys cannot be used with a <key> or --all"));
+
+ if (show_keys)
-+ return print_keys();
++ return print_keys(format);
+
- if (format != FORMAT_KEYVALUE && format != FORMAT_NUL_TERMINATED)
- die(_("unsupported output format"));
+ if (format == FORMAT_DEFAULT)
+ format = FORMAT_KEYVALUE;
## t/t1900-repo.sh ##
@@ t/t1900-repo.sh: test_expect_success 'git repo info uses the last requested form
git repo info --all >actual &&
test_cmp expect actual
'
+@@ t/t1900-repo.sh: test_expect_success 'git repo info --all <key> aborts' '
+ test_cmp expect actual
+ '
+
++test_expect_success 'git repo info --keys --format=nul uses nul-terminated output' '
++ git repo info --keys --format=default >default &&
++ lf_to_nul <default > expect &&
++ git repo info --keys --format=nul >actual &&
++ test_cmp expect actual
++'
++
++test_expect_success 'git repo info --keys aborts when using --format other than default or nul' '
++ echo "fatal: --keys can only be used with --format=default or --format=nul" >expect &&
++ test_must_fail git repo info --keys --format=keyvalue 2>actual &&
++ test_cmp expect actual
++'
++
++test_expect_success 'git repo info --keys aborts when requesting keys' '
++ echo "fatal: --keys cannot be used with a <key> or --all" >expect &&
++ test_must_fail git repo info --keys --all 2>actual_all &&
++ test_must_fail git repo info --keys some.key 2>actual_key &&
++ test_cmp expect actual_all &&
++ test_cmp expect actual_key
++'
+ test_done
--
2.50.1 (Apple Git-155)
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 1/2] repo: add a default output format to enum output_format
2025-12-09 19:36 ` [PATCH v2 0/2] " Lucas Seiki Oshiro
@ 2025-12-09 19:36 ` Lucas Seiki Oshiro
2025-12-09 19:36 ` [PATCH v2 2/2] repo: add new flag --keys to git-repo-info Lucas Seiki Oshiro
1 sibling, 0 replies; 7+ messages in thread
From: Lucas Seiki Oshiro @ 2025-12-09 19:36 UTC (permalink / raw)
To: git; +Cc: ps, Lucas Seiki Oshiro
Add a `FORMAT_DEFAULT` value to `enum output_format`. Change the initial
value of `format` to `FORMAT_DEFAULT` in cmd_repo_info, indicating that
the initial value hasn't been changed. Also map the string "default" to
this new value in `parse_format_cb`, allowing future patches to add
support to --format=default.
Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
---
builtin/repo.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/builtin/repo.c b/builtin/repo.c
index 0dd41b1778..1cd12e7eea 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -23,6 +23,7 @@ static const char *const repo_usage[] = {
typedef int get_value_fn(struct repository *repo, struct strbuf *buf);
enum output_format {
+ FORMAT_DEFAULT,
FORMAT_TABLE,
FORMAT_KEYVALUE,
FORMAT_NUL_TERMINATED,
@@ -159,6 +160,8 @@ static int parse_format_cb(const struct option *opt,
*format = FORMAT_KEYVALUE;
else if (!strcmp(arg, "table"))
*format = FORMAT_TABLE;
+ else if (!strcmp(arg, "default"))
+ *format = FORMAT_DEFAULT;
else
die(_("invalid format '%s'"), arg);
@@ -168,7 +171,7 @@ static int parse_format_cb(const struct option *opt,
static int cmd_repo_info(int argc, const char **argv, const char *prefix,
struct repository *repo)
{
- enum output_format format = FORMAT_KEYVALUE;
+ enum output_format format = FORMAT_DEFAULT;
int all_keys = 0;
struct option options[] = {
OPT_CALLBACK_F(0, "format", &format, N_("format"),
@@ -183,6 +186,10 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
};
argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
+
+ if (format == FORMAT_DEFAULT)
+ format = FORMAT_KEYVALUE;
+
if (format != FORMAT_KEYVALUE && format != FORMAT_NUL_TERMINATED)
die(_("unsupported output format"));
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 2/2] repo: add new flag --keys to git-repo-info
2025-12-09 19:36 ` [PATCH v2 0/2] " Lucas Seiki Oshiro
2025-12-09 19:36 ` [PATCH v2 1/2] repo: add a default output format to enum output_format Lucas Seiki Oshiro
@ 2025-12-09 19:36 ` Lucas Seiki Oshiro
1 sibling, 0 replies; 7+ messages in thread
From: Lucas Seiki Oshiro @ 2025-12-09 19:36 UTC (permalink / raw)
To: git; +Cc: ps, Lucas Seiki Oshiro
If the user wants to find what are the available keys, they need to
either check the documentation or to ask for all the key-value pairs
by using --all.
Add a new flag --keys for listing only the available keys without
listing the values.
Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
---
Documentation/git-repo.adoc | 11 +++++++++++
builtin/repo.c | 32 ++++++++++++++++++++++++++++++++
t/t1900-repo.sh | 33 ++++++++++++++++++++++-----------
3 files changed, 65 insertions(+), 11 deletions(-)
diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
index c4a78277df..fd0683631c 100644
--- a/Documentation/git-repo.adoc
+++ b/Documentation/git-repo.adoc
@@ -9,6 +9,7 @@ SYNOPSIS
--------
[synopsis]
git repo info [--format=(keyvalue|nul) | -z] [--all | <key>...]
+git repo info --keys [--format=(default|nul) | -z]
git repo structure [--format=(table|keyvalue|nul) | -z]
DESCRIPTION
@@ -44,6 +45,16 @@ supported:
+
`-z` is an alias for `--format=nul`.
+`info --keys [--format=(default|nul) | -z]`::
+ List all the available keys, one per line. The output format can be chosen
+ through the flag `--format`. The following formats are supported:
++
+`default`:::
+ output the keys one per line.
+
+`nul`:::
+ similar to `default`, but using a NUL character after each value.
+
`structure [--format=(table|keyvalue|nul) | -z]`::
Retrieve statistics about the current repository structure. The
following kinds of information are reported:
diff --git a/builtin/repo.c b/builtin/repo.c
index 1cd12e7eea..48341f9245 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -16,6 +16,7 @@
static const char *const repo_usage[] = {
"git repo info [--format=(keyvalue|nul) | -z] [--all | <key>...]",
+ "git repo info --keys [--format=(default|nul) | -z]",
"git repo structure [--format=(table|keyvalue|nul) | -z]",
NULL
};
@@ -147,6 +148,29 @@ static int print_all_fields(struct repository *repo,
return 0;
}
+static int print_keys(enum output_format format)
+{
+ char sep;
+
+ switch (format) {
+ case FORMAT_DEFAULT:
+ sep = '\n';
+ break;
+ case FORMAT_NUL_TERMINATED:
+ sep = '\0';
+ break;
+ default:
+ die(_("--keys can only be used with --format=default or --format=nul"));
+ }
+
+ for (size_t i = 0; i < ARRAY_SIZE(repo_info_fields); i++) {
+ const struct field *field = &repo_info_fields[i];
+ printf("%s%c", field->key, sep);
+ }
+
+ return 0;
+}
+
static int parse_format_cb(const struct option *opt,
const char *arg, int unset UNUSED)
{
@@ -173,6 +197,7 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
{
enum output_format format = FORMAT_DEFAULT;
int all_keys = 0;
+ int show_keys = 0;
struct option options[] = {
OPT_CALLBACK_F(0, "format", &format, N_("format"),
N_("output format"),
@@ -182,11 +207,18 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
PARSE_OPT_NONEG | PARSE_OPT_NOARG,
parse_format_cb),
OPT_BOOL(0, "all", &all_keys, N_("print all keys/values")),
+ OPT_BOOL(0, "keys", &show_keys, N_("show keys")),
OPT_END()
};
argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
+ if (show_keys && (all_keys || argc))
+ die(_("--keys cannot be used with a <key> or --all"));
+
+ if (show_keys)
+ return print_keys(format);
+
if (format == FORMAT_DEFAULT)
format = FORMAT_KEYVALUE;
diff --git a/t/t1900-repo.sh b/t/t1900-repo.sh
index 51d55f11a5..e8802413a6 100755
--- a/t/t1900-repo.sh
+++ b/t/t1900-repo.sh
@@ -4,15 +4,6 @@ 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>
@@ -119,8 +110,8 @@ 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 &&
+test_expect_success 'git repo info --all and git repo info $(git repo info --keys) output the same data' '
+ git repo info $(git repo info --keys) >expect &&
git repo info --all >actual &&
test_cmp expect actual
'
@@ -131,4 +122,24 @@ test_expect_success 'git repo info --all <key> aborts' '
test_cmp expect actual
'
+test_expect_success 'git repo info --keys --format=nul uses nul-terminated output' '
+ git repo info --keys --format=default >default &&
+ lf_to_nul <default > expect &&
+ git repo info --keys --format=nul >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'git repo info --keys aborts when using --format other than default or nul' '
+ echo "fatal: --keys can only be used with --format=default or --format=nul" >expect &&
+ test_must_fail git repo info --keys --format=keyvalue 2>actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'git repo info --keys aborts when requesting keys' '
+ echo "fatal: --keys cannot be used with a <key> or --all" >expect &&
+ test_must_fail git repo info --keys --all 2>actual_all &&
+ test_must_fail git repo info --keys some.key 2>actual_key &&
+ test_cmp expect actual_all &&
+ test_cmp expect actual_key
+'
test_done
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-12-09 19:46 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-07 19:02 [PATCH] repo: add new flag --keys to git-repo-info Lucas Seiki Oshiro
2025-12-07 22:14 ` Junio C Hamano
2025-12-08 16:33 ` Lucas Seiki Oshiro
2025-12-08 7:13 ` Patrick Steinhardt
2025-12-09 19:36 ` [PATCH v2 0/2] " Lucas Seiki Oshiro
2025-12-09 19:36 ` [PATCH v2 1/2] repo: add a default output format to enum output_format Lucas Seiki Oshiro
2025-12-09 19:36 ` [PATCH v2 2/2] repo: add new flag --keys to git-repo-info Lucas Seiki Oshiro
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).