Git development
 help / color / mirror / Atom feed
From: Phillip Wood <phillip.wood123@gmail.com>
To: Wonseok Oh <wonseok_oh@korea.ac.kr>, phillip.wood@dunelm.org.uk
Cc: Wonseok Oh via GitGitGadget <gitgitgadget@gmail.com>,
	git@vger.kernel.org
Subject: Re: [PATCH] sequencer: reset saved HEAD OID when picking onto an unborn branch
Date: Tue, 24 Nov 2026 10:41:31 +0000	[thread overview]
Message-ID: <6d20285a-f8ec-4dbd-bc23-a97f42ec9260@gmail.com> (raw)
In-Reply-To: <CAD2pp5sZ29TT6JHwA88XTC3dymjrtAbKmy-gyyZ1oiA2pEomxA@mail.gmail.com>

Hi Wonseck

On 24/11/2026 02:33, Wonseok Oh wrote:
> 
>> I had a hard time parsing the second half of that sentence.
>> sequencer_rollback() expects us to have saved the null OID when HEAD
>> points to an unborn branch, but instead we save some random junk because
>> we haven't initialized the 'head' variable. The use of an uninitialized
>> variable comes from 0f974e2124 (cherry-pick: allow to pick to unborn
>> branches, 2016-06-06). Before that commit we refused to cherry-pick onto
>> an unborn branch and so did not use 'head' unless it was initialized.
> 
> Thanks for the review and for digging into the history.
> I'll reword the commit message along these lines
> and mention 0f974e2124 in the updated patch.

That's great

> 
>> I see that rollback_is_safe() expects to see a null OID when picking
>> onto an unborn branch, but update_abort_safety_file() writes an empty
>> file in that case. We should be consistent about the way we represent an
>> unborn branch in the state files. Arguably an empty file is a better way
>> of representing an unborn branch because there is no OID.
> 
> Along with the reworded commit message,
> should the updated patch also save an empty ".git/sequencer/head" on
> an unborn branch,
> to align with update_abort_safety_file()?
> If so, I'm happy to include that change.

Thinking about it some more, older versions of git are expecting to read 
a null OID in both cases, so we should standardize on that.

Thanks

Phillip

> 
> Thanks
> Wonseok Oh
> 
> 2026년 11월 23일 (월) 오후 11:32, Phillip Wood <phillip.wood123@gmail.com>님이 작성:
>>
>> Hi Wonseok
>>
>> Thanks for working on this. I think that as an immediate fix for the use
>> of an uninitialized variable the patch looks good, but I'm not sure the
>> behavior of cherry-pick and revert onto an unborn branch makes much sense.
>>
>> On 21/11/2026 06:30, Wonseok Oh via GitGitGadget wrote:
>>> From: Wonseok Oh <marinelay7@gmail.com>
>>>
>>> When picking multiple commits, "git cherry-pick" stores the current HEAD
>>> in .git/sequencer/head for "--abort" to return to. If the branch is
>>> unborn, repo_get_oid() fails and leaves the object ID uninitialized,
>>> but sequencer_pick_revisions() saves it anyway instead of clearing it
>>> to the null OID that sequencer_rollback() checks for to report
>>> "cannot abort from a branch yet to be born".
>>
>> I had a hard time parsing the second half of that sentence.
>> sequencer_rollback() expects us to have saved the null OID when HEAD
>> points to an unborn branch, but instead we save some random junk because
>> we haven't initialized the 'head' variable. The use of an uninitialized
>> variable comes from 0f974e2124 (cherry-pick: allow to pick to unborn
>> branches, 2016-06-06). Before that commit we refused to cherry-pick onto
>> an unborn branch and so did not use 'head' unless it was initialized.
>>
>> It is rather strange that when sequencer_rollback() rejects an unborn
>> branch it refuses to remove the sequencer state so that it is impossible
>> to abort a multi-pick cherry-pick started on an unborn branch. It is
>> also strange that we will try and revert a single commit onto an unborn
>> branch but not multiple commits. 7acaaac275 (revert: allow single-pick
>> in the middle of cherry-pick sequence, 2011-12-10) inserted a separate
>> code path for single picks before the check for an unborn branch, so
>> prior that commit we refused to cherry-pick and revert onto an unborn
>> branch regardless of the number of commits. Going further back in
>> history, the check for an unborn branch was introduced by 04d3d3cfc4
>> (revert: Save data for continuing after conflict resolution,
>> 2011-08-04). The commit message does not mention a reason for
>> introducing that check and therefore changing the behavior but I assume
>> it was to avoid having to support aborting to an unborn branch.
>>
>> It would be nice to either remove the check for an unborn branch when
>> reverting multiple commits, or move the check so that it covers single
>> picks as well. It would also be good to allow the user to abort when
>> cherry-picking onto a unborn branch. Those changes don't need to be part
>> of this series though, they can always come later.
>>
>> I see that rollback_is_safe() expects to see a null OID when picking
>> onto an unborn branch, but update_abort_safety_file() writes an empty
>> file in that case. We should be consistent about the way we represent an
>> unborn branch in the state files. Arguably an empty file is a better way
>> of representing an unborn branch because there is no OID.
>>
>> Thanks
>>
>> Phillip
>>
>>> As a result, "--abort" errors out with "Could not parse object" in my
>>> master build, while in Debian's 2.47.3 build the uninitialized memory
>>> happened to hold the last picked commit's OID and moved the new branch
>>> there.
>>>
>>> Clear the object ID to the null OID when HEAD cannot be resolved, and
>>> add a test.
>>>
>>> Signed-off-by: Wonseok Oh <marinelay7@gmail.com>
>>> ---
>>>       sequencer: reset saved HEAD OID when picking onto an unborn branch
>>>
>>> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2317%2Fmarinelay%2Fcherry-pick-unborn-abort-v1
>>> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2317/marinelay/cherry-pick-unborn-abort-v1
>>> Pull-Request: https://github.com/gitgitgadget/git/pull/2317
>>>
>>>    sequencer.c                     |  9 ++++++---
>>>    t/t3510-cherry-pick-sequence.sh | 10 ++++++++++
>>>    2 files changed, 16 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/sequencer.c b/sequencer.c
>>> index 4a1c0e70b8..20bfe00ba3 100644
>>> --- a/sequencer.c
>>> +++ b/sequencer.c
>>> @@ -5788,9 +5788,12 @@ int sequencer_pick_revisions(struct repository *r,
>>>                goto out;
>>>        }
>>>
>>> -     if (repo_get_oid(r, "HEAD", &oid) && (opts->action == REPLAY_REVERT)) {
>>> -             res = error(_("can't revert as initial commit"));
>>> -             goto out;
>>> +     if (repo_get_oid(r, "HEAD", &oid)) {
>>> +             if (opts->action == REPLAY_REVERT) {
>>> +                     res = error(_("can't revert as initial commit"));
>>> +                     goto out;
>>> +             }
>>> +             oidclr(&oid, r->hash_algo);
>>>        }
>>>
>>>        if (save_head(oid_to_hex(&oid))) {
>>> diff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh
>>> index 9400ddfc45..75004bba0c 100755
>>> --- a/t/t3510-cherry-pick-sequence.sh
>>> +++ b/t/t3510-cherry-pick-sequence.sh
>>> @@ -269,6 +269,16 @@ test_expect_success 'allow skipping commit but not abort for a new history' '
>>>        test_cmp expect advice
>>>    '
>>>
>>> +test_expect_success 'cannot abort a cherry-pick sequence on a new history' '
>>> +     pristine_detach initial &&
>>> +     git checkout --orphan new_disconnected_seq &&
>>> +     git reset --hard &&
>>> +     test_must_fail git cherry-pick base..anotherpick &&
>>> +     test_must_fail git cherry-pick --abort 2>advice &&
>>> +     test_grep "cannot abort from a branch yet to be born" advice &&
>>> +     test_must_fail git rev-parse --verify HEAD
>>> +'
>>> +
>>>    test_expect_success 'allow skipping stopped cherry-pick because of untracked file modifications' '
>>>        test_when_finished "rm unrelated" &&
>>>        pristine_detach initial &&
>>>
>>> base-commit: e1ec09b23c8e0deb21a0b95ac5996422277395d4
>>


  reply	other threads:[~2026-11-24 10:41 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-21  6:30 [PATCH] sequencer: reset saved HEAD OID when picking onto an unborn branch Wonseok Oh via GitGitGadget
2026-11-23 14:32 ` Phillip Wood
2026-11-24  2:33   ` Wonseok Oh
2026-11-24 10:41     ` Phillip Wood [this message]
2026-11-24 14:54 ` Junio C Hamano
2026-11-25  3:23 ` [PATCH v2 0/2] sequencer: save the null OID for " Wonseok Oh via GitGitGadget
2026-11-25  3:23   ` [PATCH v2 1/2] sequencer: clear saved HEAD OID when picking onto " Wonseok Oh via GitGitGadget
2026-11-25 16:57     ` Junio C Hamano
2026-11-25  3:23   ` [PATCH v2 2/2] sequencer: save the null OID in abort-safety on " Wonseok Oh via GitGitGadget
2026-11-25 17:07     ` Junio C Hamano
2026-11-26 16:32       ` Phillip Wood
2026-11-25 17:17   ` [PATCH v2 0/2] sequencer: save the null OID for " Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6d20285a-f8ec-4dbd-bc23-a97f42ec9260@gmail.com \
    --to=phillip.wood123@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=phillip.wood@dunelm.org.uk \
    --cc=wonseok_oh@korea.ac.kr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox