Skip to content

Commit 3f4bc21

Browse files
committed
repo: ignore empty init.defaultbranch
The init.defaultbranch option may be set, but empty. In this case, we should ignore it instead of trying to set our default branch to `refs/heads/`.
1 parent 32350e8 commit 3f4bc21

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/repository.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2092,7 +2092,8 @@ static int repo_init_head(const char *repo_dir, const char *given)
20922092
if (given) {
20932093
initial_head = given;
20942094
} else if ((error = git_config_open_default(&cfg)) >= 0 &&
2095-
(error = git_config_get_string_buf(&cfg_branch, cfg, "init.defaultbranch")) >= 0) {
2095+
(error = git_config_get_string_buf(&cfg_branch, cfg, "init.defaultbranch")) >= 0 &&
2096+
*cfg_branch.ptr) {
20962097
initial_head = cfg_branch.ptr;
20972098
}
20982099

tests/repo/init.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,3 +688,19 @@ void test_repo_init__defaultbranch_config(void)
688688

689689
git_reference_free(head);
690690
}
691+
692+
void test_repo_init__defaultbranch_config_empty(void)
693+
{
694+
git_reference *head;
695+
696+
cl_set_cleanup(&cleanup_repository, "repo");
697+
698+
create_tmp_global_config("tmp_global_path", "init.defaultbranch", "");
699+
700+
cl_git_pass(git_repository_init(&g_repo, "repo", 0));
701+
cl_git_pass(git_reference_lookup(&head, g_repo, "HEAD"));
702+
703+
cl_assert_equal_s("refs/heads/master", git_reference_symbolic_target(head));
704+
705+
git_reference_free(head);
706+
}

0 commit comments

Comments
 (0)