Skip to content

Commit 02a1d80

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 9eb06c9 commit 02a1d80

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

Documentation/git-repo.adoc

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

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

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 should 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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ test_repo_info 'ref format files is retrieved correctly' '
3535
test_repo_info 'ref format reftable is retrieved correctly' '
3636
git init --ref-format=reftable' 'format-reftable' 'references.format' 'reftable'
3737

38+
test_repo_info 'bare repository = false is retrieved correctly' \
39+
'git init' 'nonbare' 'layout.bare' 'false'
40+
41+
test_repo_info 'bare repository = true is retrieved correctly' \
42+
'git init --bare' 'bare' 'layout.bare' 'true'
43+
3844
test_expect_success 'git-repo-info fails if an invalid key is requested' '
3945
echo "error: key '\'foo\'' not found" >expected_err &&
4046
test_must_fail git repo info foo 2>actual_err &&
@@ -54,4 +60,14 @@ test_expect_success 'only one value is returned if the same key is requested twi
5460
test_cmp expect actual
5561
'
5662

63+
test_expect_success 'output is returned correctly when two keys are requested' '
64+
cat >expected <<-\EOF &&
65+
layout.bare=false
66+
references.format=files
67+
EOF
68+
git init --ref-format=files two-keys &&
69+
git -C two-keys repo info layout.bare references.format > actual &&
70+
test_cmp expected actual
71+
'
72+
5773
test_done

0 commit comments

Comments
 (0)