the keys that identify them. Here's a list of the available keys and the
values that they return:
+`layout.bare`::
+ `true` if this is a bare repository, otherwise `false`.
+
`references.format`::
The reference storage format. The valid values are:
+
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "builtin.h"
+#include "environment.h"
#include "parse-options.h"
#include "quote.h"
#include "refs.h"
get_value_fn *get_value;
};
+static int get_layout_bare(struct repository *repo UNUSED, struct strbuf *buf)
+{
+ strbuf_addstr(buf, is_bare_repository() ? "true" : "false");
+ return 0;
+}
+
static int get_references_format(struct repository *repo, struct strbuf *buf)
{
strbuf_addstr(buf,
/* repo_info_fields keys must be in lexicographical order */
static const struct field repo_info_fields[] = {
+ { "layout.bare", get_layout_bare },
{ "references.format", get_references_format },
};
test_repo_info 'ref format reftable is retrieved correctly' \
'git init --ref-format=reftable' 'format-reftable' 'references.format' 'reftable'
+test_repo_info 'bare repository = false is retrieved correctly' \
+ 'git init' 'nonbare' 'layout.bare' 'false'
+
+test_repo_info 'bare repository = true is retrieved correctly' \
+ 'git init --bare' 'bare' 'layout.bare' 'true'
+
+test_expect_success 'values returned in order requested' '
+ cat >expect <<-\EOF &&
+ layout.bare=false
+ references.format=files
+ layout.bare=false
+ EOF
+ git init --ref-format=files ordered &&
+ git -C ordered repo info layout.bare references.format layout.bare >actual &&
+ test_cmp expect actual
+'
+
test_expect_success 'git-repo-info fails if an invalid key is requested' '
echo "error: key ${SQ}foo${SQ} not found" >expect &&
test_must_fail git repo info foo 2>actual &&