Skip to content

Commit 4292837

Browse files
committed
config: open configuration in commondir
A repository's configuartion file can always be found in the GIT_COMMON_DIR, which has been newly introduced. For normal repositories this does change nothing, but for working trees this change allows to access the shared configuration file.
1 parent e940302 commit 4292837

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

src/repository.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -862,8 +862,7 @@ static int load_config(
862862
if ((error = git_config_new(&cfg)) < 0)
863863
return error;
864864

865-
error = git_buf_joinpath(
866-
&config_path, repo->path_repository, GIT_CONFIG_FILENAME_INREPO);
865+
error = git_repository_item_path(&config_path, repo, GIT_REPOSITORY_ITEM_CONFIG);
867866
if (error < 0)
868867
goto on_error;
869868

tests/worktree/config.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include "clar_libgit2.h"
2+
#include "worktree_helpers.h"
3+
4+
#define COMMON_REPO "testrepo"
5+
#define WORKTREE_REPO "testrepo-worktree"
6+
7+
static worktree_fixture fixture =
8+
WORKTREE_FIXTURE_INIT(COMMON_REPO, WORKTREE_REPO);
9+
10+
void test_worktree_config__initialize(void)
11+
{
12+
setup_fixture_worktree(&fixture);
13+
}
14+
15+
void test_worktree_config__cleanup(void)
16+
{
17+
cleanup_fixture_worktree(&fixture);
18+
}
19+
20+
void test_worktree_config__open(void)
21+
{
22+
git_config *cfg;
23+
24+
cl_git_pass(git_repository_config(&cfg, fixture.worktree));
25+
cl_assert(cfg != NULL);
26+
27+
git_config_free(cfg);
28+
}
29+
30+
void test_worktree_config__set(void)
31+
{
32+
git_config *cfg;
33+
int32_t val;
34+
35+
cl_git_pass(git_repository_config(&cfg, fixture.worktree));
36+
cl_git_pass(git_config_set_int32(cfg, "core.dummy", 5));
37+
git_config_free(cfg);
38+
39+
// reopen to verify configuration has been set in the
40+
// common dir
41+
cl_git_pass(git_repository_config(&cfg, fixture.repo));
42+
cl_git_pass(git_config_get_int32(&val, cfg, "core.dummy"));
43+
cl_assert_equal_i(val, 5);
44+
git_config_free(cfg);
45+
}

0 commit comments

Comments
 (0)