Subject: Re: [PATCH] rebase: set REF_HEAD_DETACH in checkout_up_to_date()

From: Junio C Hamano <[email-masked]>
Date: Thu, 10 Mar 2022 21:55:38 -0800

"John Cai via GitGitGadget" <[email-masked]> writes:

> This is happening because on a fast foward with an oid as a <branch>,
> update_refs() will only call update_ref() with REF_NO_DEREF if
> RESET_HEAD_DETACH is set. This change was made in 176f5d96 (built-in rebase
> --autostash: leave the current branch alone if possible,
> 2018-11-07). In rebase, we are not setting the RESET_HEAD_DETACH flag,
> which means that the update_ref() call ends up dereferencing
> HEAD and updating it to the oid used as <branch>.
>
> The correct behavior is that git rebase should update HEAD to $(git
> rev-parse topic) without dereferencing it.

It is unintuitive that unconditionally setting the RESET_HEAD_DETACH
bit is the right solution.

If the command weren't "rebase master side^0" but "rebase master
side", i.e. "please rebase the side branch itself, not an unnamed
branch created out of the side branch, on master", according to
<reset.h>, we ought to end up being on a detached HEAD, as
reset_head() with the bit

    /* Request a detached checkout */
    #define RESET_HEAD_DETACH (1<<0)

requests a detached checkout.  But that apparently is not what would
happen with your patch applied.

Puzzled.  The solution to the puzzle probably deserves to be in the
proposed log message.

Thanks.