Skip to content

Commit c6ff3fe

Browse files
ianhattendorfimplausible
authored andcommitted
Default to GIT_BRANCH_DEFAULT if init.defaultBranch is empty string
We already do this in repo_init_head
1 parent 55d767d commit c6ff3fe

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/repository.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2384,10 +2384,11 @@ int git_repository_initialbranch(git_buf *out, git_repository *repo)
23842384
if ((error = git_repository_config__weakptr(&config, repo)) < 0)
23852385
return error;
23862386

2387-
if ((error = git_config_get_entry(&entry, config, "init.defaultbranch")) == 0) {
2387+
if ((error = git_config_get_entry(&entry, config, "init.defaultbranch")) == 0 &&
2388+
*entry->value) {
23882389
branch = entry->value;
23892390
}
2390-
else if (error == GIT_ENOTFOUND) {
2391+
else if (!error || error == GIT_ENOTFOUND) {
23912392
branch = GIT_BRANCH_DEFAULT;
23922393
}
23932394
else {

tests/repo/getters.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "clar_libgit2.h"
2+
#include "repo/repo_helpers.h"
23

34
void test_repo_getters__is_empty_correctly_deals_with_pristine_looking_repos(void)
45
{
@@ -23,6 +24,18 @@ void test_repo_getters__is_empty_can_detect_used_repositories(void)
2324
git_repository_free(repo);
2425
}
2526

27+
void test_repo_getters__is_empty_can_detect_repositories_with_defaultbranch_config_empty(void)
28+
{
29+
git_repository *repo;
30+
31+
create_tmp_global_config("tmp_global_path", "init.defaultBranch", "");
32+
33+
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
34+
cl_assert_equal_i(false, git_repository_is_empty(repo));
35+
36+
git_repository_free(repo);
37+
}
38+
2639
void test_repo_getters__retrieving_the_odb_honors_the_refcount(void)
2740
{
2841
git_odb *odb;

0 commit comments

Comments
 (0)