Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING CHANGE: Change the behaviour of git_repository_is_empty to better align with expectations in a world where master isn't always the "initial branch" #6508

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions include/git2/repository.h
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,7 @@ GIT_EXTERN(int) git_repository_head_unborn(git_repository *repo);
* Check if a repository is empty
*
* An empty repository has just been initialized and contains no references
* apart from HEAD, which must be pointing to the unborn master branch,
* or the branch specified for the repository in the `init.defaultBranch`
* configuration variable.
* apart from HEAD.
*
* @param repo Repo to test
* @return 1 if the repository is empty, 0 if it isn't, error code
Expand Down
7 changes: 1 addition & 6 deletions src/libgit2/repository.c
Original file line number Diff line number Diff line change
Expand Up @@ -2867,21 +2867,16 @@ int git_repository_initialbranch(git_str *out, git_repository *repo)
int git_repository_is_empty(git_repository *repo)
{
git_reference *head = NULL;
git_str initialbranch = GIT_STR_INIT;
int result = 0;

if ((result = git_reference_lookup(&head, repo, GIT_HEAD_FILE)) < 0 ||
(result = git_repository_initialbranch(&initialbranch, repo)) < 0)
if ((result = git_reference_lookup(&head, repo, GIT_HEAD_FILE)) < 0)
goto done;

result = (git_reference_type(head) == GIT_REFERENCE_SYMBOLIC &&
strcmp(git_reference_symbolic_target(head), initialbranch.ptr) == 0 &&
repo_contains_no_reference(repo));

done:
git_reference_free(head);
git_str_dispose(&initialbranch);

return result;
}

Expand Down