Skip to content
  • Duy Nguyen's avatar
    worktree.c: check whether branch is rebased in another worktree · 8d9fdd70
    Duy Nguyen authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    This function find_shared_symref() is used in a couple places:
    
    1) in builtin/branch.c: it's used to detect if a branch is checked out
       elsewhere and refuse to delete the branch.
    
    2) in builtin/notes.c: it's used to detect if a note is being merged in
       another worktree
    
    3) in branch.c, the function die_if_checked_out() is actually used by
       "git checkout" and "git worktree add" to see if a branch is already
       checked out elsewhere and refuse the operation.
    
    In cases 1 and 3, if a rebase is ongoing, "HEAD" will be in detached
    mode, find_shared_symref() fails to detect it and declares "no branch is
    checked out here", which is not really what we want.
    
    This patch tightens the test. If the given symref is "HEAD", we try to
    detect if rebase is ongoing. If so return the branch being rebased. This
    makes checkout and branch delete operations safer because you can't
    checkout a branch being rebased in another place, or delete it.
    
    Special case for checkout. If the current branch is being rebased,
    git-rebase.sh may use "git checkout" to abort and return back to the
    original branch. The updated test in find_shared_symref() will prevent
    that and "git rebase --abort" will fail as a result.
    find_shared_symref() and die_if_checked_out() have to learn a new
    option ignore_current_worktree to loosen the test a bit.
    
    Signed-off-by: default avatarNguyễn Thái Ngọc Duy <pclouds@gmail.com>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    8d9fdd70