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
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:
#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
};
return ret;
}
+static int print_all_fields(struct repository *repo,
+ enum output_format format)
+{
+ struct strbuf valbuf = STRBUF_INIT;
+
+ for (size_t 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);
+ return 0;
+}
+
static int parse_format_cb(const struct option *opt,
const char *arg, int unset UNUSED)
{
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"),
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()
};
if (format != FORMAT_KEYVALUE && format != FORMAT_NUL_TERMINATED)
die(_("unsupported output format"));
- return print_fields(argc, argv, repo, format);
+ if (all_keys && argc)
+ die(_("--all and <key> cannot be used together"));
+
+ if (all_keys)
+ return print_all_fields(repo, format);
+ else
+ return print_fields(argc, argv, repo, format);
}
struct ref_stats {
. ./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>
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