Skip to content
  • Hariom Verma's avatar
    receive.denyCurrentBranch: respect all worktrees · 4ef34648
    Hariom Verma authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    The receive.denyCurrentBranch config option controls what happens if
    you push to a branch that is checked out into a non-bare repository.
    By default, it rejects it. It can be disabled via `ignore` or `warn`.
    Another yet trickier option is `updateInstead`.
    
    However, this setting was forgotten when the git worktree command was
    introduced: only the main worktree's current branch is respected.
    
    With this change, all worktrees are respected.
    
    That change also leads to revealing another bug,
    i.e. `receive.denyCurrentBranch = true` was ignored when pushing into a
    non-bare repository's unborn current branch using ref namespaces. As
    `is_ref_checked_out()` returns 0 which means `receive-pack` does not get
    into conditional statement to switch `deny_current_branch` accordingly
    (ignore, warn, refuse, unconfigured, updateInstead).
    
    receive.denyCurrentBranch uses the function `refs_resolve_ref_unsafe()`
    (called via `resolve_refdup()`) to resolve the symbolic ref HEAD, but
    that function fails when HEAD does not point at a valid commit.
    As we replace the call to `refs_resolve_ref_unsafe()` with
    `find_shared_symref()`, which has no problem finding the worktree for a
    given branch even if it is unborn yet, this bug is fixed at the same
    time: receive.denyCurrentBranch now also handles worktrees with unborn
    branches as intended even while using ref namespaces.
    
    Helped-by: default avatarJohannes Schindelin <johannes.schindelin@gmx.de>
    Signed-off-by: Hariom Verma's avatarHariom Verma <hariom18599@gmail.com>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    4ef34648