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

worktree: detect from secondary worktree if main worktree is bare #1829

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Commits on Nov 14, 2024

  1. worktree: detect from secondary worktree if main worktree is bare

    Setup:
    1. Have a bare repo with core.bare = true in config.worktree
    2. Create a new worktree
    
    Behavior:
    From the secondary worktree the main worktree appears as non-bare.
    
    Expected:
    From the secondary worktree the main worktree should appear as bare.
    
    Why current behavior is not good?
    If the main worktree is detected as not bare it doesn't allow
    checking out the branch of the main worktree. There are possibly
    other problems associated with that behavior.
    
    Why is it happening?
    While we're inside the secondary worktree we don't initialize the main
    worktree's repository with its configuration.
    
    How is it fixed?
    Load actual configs of the main worktree. Also, skip the config loading
    step if we're already inside the current worktree because in that case we
    rely on is_bare_repository() to return the correct result.
    
    Other solutions considered:
    Alternatively, instead of incorrectly always using
    `the_repository` as the main worktree's repository, we can detect
    and load the actual repository of the main worktree and then use
    that repository's `is_bare` value extracted from correct configs.
    However, this approach is a bit riskier and could also affect
    performance. Since we had the assignment `worktree->repo =
    the_repository` for a long time already, I decided it's safe to
    keep it as it is for now; it can be still fixed separately from
    this change.
    
    Real life use case:
    1. Have a bare repo
    2. Create a worktree from the bare repo
    3. In the secondary worktree enable sparse-checkout - this enables
    extensions.worktreeConfig and keeps core.bare=true setting in
    config.worktree of the bare worktree
    4. The secondary worktree or any other non-bare worktree created
    won't be able to use branch main (not even once), but it should be
    able to.
    
    Signed-off-by: Olga Pilipenco <[email protected]>
    olga-mcbfe committed Nov 14, 2024
    Configuration menu
    Copy the full SHA
    9e7170f View commit details
    Browse the repository at this point in the history