diff options
author | Ian Hattendorf <ianh@axosoft.com> | 2021-04-01 11:34:38 -0700 |
---|---|---|
committer | Ian Hattendorf <ianh@axosoft.com> | 2021-04-01 11:34:38 -0700 |
commit | 7891e15375e1f9737f8e6a348fae36f0d6f5c2f6 (patch) | |
tree | 4099cfdfdbda376f6e09bda733b1e012c496b80b | |
parent | 508361401fbb5d87118045eaeae3356a729131aa (diff) | |
download | libgit2-7891e15375e1f9737f8e6a348fae36f0d6f5c2f6.tar.gz |
Default to GIT_BRANCH_DEFAULT if init.defaultBranch is empty string
We already do this in repo_init_head
-rw-r--r-- | src/repository.c | 5 | ||||
-rw-r--r-- | tests/repo/getters.c | 13 |
2 files changed, 16 insertions, 2 deletions
diff --git a/src/repository.c b/src/repository.c index de1a89582..2c8b8192e 100644 --- a/src/repository.c +++ b/src/repository.c @@ -2384,10 +2384,11 @@ int git_repository_initialbranch(git_buf *out, git_repository *repo) if ((error = git_repository_config__weakptr(&config, repo)) < 0) return error; - if ((error = git_config_get_entry(&entry, config, "init.defaultbranch")) == 0) { + if ((error = git_config_get_entry(&entry, config, "init.defaultbranch")) == 0 && + *entry->value) { branch = entry->value; } - else if (error == GIT_ENOTFOUND) { + else if (!error || error == GIT_ENOTFOUND) { branch = GIT_BRANCH_DEFAULT; } else { diff --git a/tests/repo/getters.c b/tests/repo/getters.c index b8ede126c..d401bb832 100644 --- a/tests/repo/getters.c +++ b/tests/repo/getters.c @@ -1,4 +1,5 @@ #include "clar_libgit2.h" +#include "repo/repo_helpers.h" void test_repo_getters__is_empty_correctly_deals_with_pristine_looking_repos(void) { @@ -23,6 +24,18 @@ void test_repo_getters__is_empty_can_detect_used_repositories(void) git_repository_free(repo); } +void test_repo_getters__is_empty_can_detect_repositories_with_defaultbranch_config_empty(void) +{ + git_repository *repo; + + create_tmp_global_config("tmp_global_path", "init.defaultBranch", ""); + + cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git"))); + cl_assert_equal_i(false, git_repository_is_empty(repo)); + + git_repository_free(repo); +} + void test_repo_getters__retrieving_the_odb_honors_the_refcount(void) { git_odb *odb; |