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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request proposes a change to the definition of an "empty" repository used in
git_repository_is_empty
.At present, an empty repository is one which:
HEAD
HEAD
pointing to the unbornmaster
branch or, if specified, the unborn branch specified in theinit.defaultBranch
configuration valueThis pull request updates the definition of "empty", removing requirement 3.
Why? Since
git_repository_is_empty
was first implemented, there has been significant cultural change in the Git community towards using an "initial branch" other thanmaster
.Because of this change, the current implementation of
git_repository_is_empty
considers repos to be not empty which an ordinary observer would consider to be empty.Specifically, this happens where a repo is initialized with
git init --initial-branch <initial_branch_which_is_not_master>
.An ordinary observer would consider such a repo to be empty, but currently, libgit2 considers it to be non-empty if the
initial-branch
is notmaster
.This is because, whilst
git_repository_is_empty
checks theinit.defaultBranch
to try to figure out the initial branch,git init --initial-branch
doesn't set this value, as you can prove like this:I'm not necessarily expecting this PR to be merged as is or ever - but I want to start a conversation about this, given that the current implementation is surprising and likely confusing.
See #6049.