Skip to content

Commit acf2669

Browse files
lucasoshirogitster
authored andcommitted
repo: add the field layout.bare
This commit is part of the series that introduces the new subcommand git-repo-info. The flag --is-bare-repository from git-rev-parse is used for retrieving whether the current repository is bare. This way, it is used for querying repository metadata, fitting in the purpose of git-repo-info. Then, add a new field layout.bare to the git-repo-info subcommand containing that information. Helped-by: Phillip Wood <[email protected]> Helped-by: Junio C Hamano <[email protected]> Helped-by: Justin Tobler <[email protected]> Helped-by: Eric Sunshine <[email protected]> Mentored-by: Karthik Nayak <[email protected]> Mentored-by: Patrick Steinhardt <[email protected]> Signed-off-by: Lucas Seiki Oshiro <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9adb8a7 commit acf2669

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

Documentation/git-repo.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ In order to obtain a set of values from `git repo info`, you should provide
3838
the keys that identify them. Here's a list of the available keys and the
3939
values that they return:
4040

41+
`layout.bare`::
42+
`true` if this is a bare repository, otherwise `false`.
43+
4144
`references.format`::
4245
The reference storage format. The valid values are:
4346
+

builtin/repo.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "builtin.h"
4+
#include "environment.h"
25
#include "parse-options.h"
36
#include "quote.h"
47
#include "refs.h"
@@ -16,6 +19,12 @@ struct field {
1619
get_value_fn *get_value;
1720
};
1821

22+
static int get_layout_bare(struct repository *repo UNUSED, struct strbuf *buf)
23+
{
24+
strbuf_addstr(buf, is_bare_repository() ? "true" : "false");
25+
return 0;
26+
}
27+
1928
static int get_references_format(struct repository *repo, struct strbuf *buf)
2029
{
2130
strbuf_addstr(buf,
@@ -25,6 +34,7 @@ static int get_references_format(struct repository *repo, struct strbuf *buf)
2534

2635
/* repo_info_fields keys must be in lexicographical order */
2736
static const struct field repo_info_fields[] = {
37+
{ "layout.bare", get_layout_bare },
2838
{ "references.format", get_references_format },
2939
};
3040

t/t1900-repo.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,23 @@ test_repo_info 'ref format files is retrieved correctly' \
3838
test_repo_info 'ref format reftable is retrieved correctly' \
3939
'git init --ref-format=reftable' 'format-reftable' 'references.format' 'reftable'
4040

41+
test_repo_info 'bare repository = false is retrieved correctly' \
42+
'git init' 'nonbare' 'layout.bare' 'false'
43+
44+
test_repo_info 'bare repository = true is retrieved correctly' \
45+
'git init --bare' 'bare' 'layout.bare' 'true'
46+
47+
test_expect_success 'values returned in order requested' '
48+
cat >expect <<-\EOF &&
49+
layout.bare=false
50+
references.format=files
51+
layout.bare=false
52+
EOF
53+
git init --ref-format=files ordered &&
54+
git -C ordered repo info layout.bare references.format layout.bare >actual &&
55+
test_cmp expect actual
56+
'
57+
4158
test_expect_success 'git-repo-info fails if an invalid key is requested' '
4259
echo "error: key ${SQ}foo${SQ} not found" >expect &&
4360
test_must_fail git repo info foo 2>actual &&

0 commit comments

Comments
 (0)