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

Commits on Feb 26, 2023

  1. 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"
    
    This pull request proposes a change to the definition of
    an "empty" repository used in `git_repository_is_empty`.
    
    At present, an empty is repository is one which:
    
    1. has just been initialised
    2. has no references apart from `HEAD`
    3. has a `HEAD` pointing to the unborn `master` branch or,
      if specified, the unborn branch specified in the
      `init.defaultBranch` configuration value
    
    This changes 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 than `master`.
    
    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`. 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 not `master`. This is because,
    whilst `git_repository_is_empty` checks the `init.defaultBranch` to
    try to figure out the initial branch, `git init --initial-branch`
    doesn't set this value, as you can prove like this:
    
    ```bash
    git config init.defaultBranch
    mkdir test-repo
    git init --initial-branch main
    git config init.defaultBranch
    ```
    
    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 libgit2#6049.
    timrogers committed Feb 26, 2023
    Configuration menu
    Copy the full SHA
    da61d11 View commit details
    Browse the repository at this point in the history