Git development
 help / color / mirror / Atom feed
* [PATCH] sequencer: reset saved HEAD OID when picking onto an unborn branch
@ 2026-11-21  6:30 Wonseok Oh via GitGitGadget
  2026-11-23 14:32 ` Phillip Wood
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Wonseok Oh via GitGitGadget @ 2026-11-21  6:30 UTC (permalink / raw)
  To: git; +Cc: Wonseok Oh, Wonseok Oh

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".

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
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH] sequencer: reset saved HEAD OID when picking onto an unborn branch
  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 14:54 ` Junio C Hamano
  2026-11-25  3:23 ` [PATCH v2 0/2] sequencer: save the null OID for " Wonseok Oh via GitGitGadget
  2 siblings, 1 reply; 12+ messages in thread
From: Phillip Wood @ 2026-11-23 14:32 UTC (permalink / raw)
  To: Wonseok Oh via GitGitGadget, git; +Cc: Wonseok Oh, Wonseok Oh

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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] sequencer: reset saved HEAD OID when picking onto an unborn branch
  2026-11-23 14:32 ` Phillip Wood
@ 2026-11-24  2:33   ` Wonseok Oh
  2026-11-24 10:41     ` Phillip Wood
  0 siblings, 1 reply; 12+ messages in thread
From: Wonseok Oh @ 2026-11-24  2:33 UTC (permalink / raw)
  To: phillip.wood; +Cc: Wonseok Oh via GitGitGadget, git

Hi Phillip!

> 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.

> 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.

Indeed. I'll think about which direction makes more sense and follow
up separately.

> 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.

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
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] sequencer: reset saved HEAD OID when picking onto an unborn branch
  2026-11-24  2:33   ` Wonseok Oh
@ 2026-11-24 10:41     ` Phillip Wood
  0 siblings, 0 replies; 12+ messages in thread
From: Phillip Wood @ 2026-11-24 10:41 UTC (permalink / raw)
  To: Wonseok Oh, phillip.wood; +Cc: Wonseok Oh via GitGitGadget, git

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
>>


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] sequencer: reset saved HEAD OID when picking onto an unborn branch
  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 14:54 ` Junio C Hamano
  2026-11-25  3:23 ` [PATCH v2 0/2] sequencer: save the null OID for " Wonseok Oh via GitGitGadget
  2 siblings, 0 replies; 12+ messages in thread
From: Junio C Hamano @ 2026-11-24 14:54 UTC (permalink / raw)
  To: Wonseok Oh via GitGitGadget; +Cc: git, Wonseok Oh, Wonseok Oh

"Wonseok Oh via GitGitGadget" <gitgitgadget@gmail.com> writes:

> 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".
>
> 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.

As Phillip mentioned, the commit message can use some clarification.  In
addition to tightening the first paragraph so the relationship between
oidclr() and sequencer_rollback() reads clearly, the second paragraph
frames the symptoms around anecdotal builds ("in my master build" and
"in Debian's 2.47.3 build") instead of describing the general
undefined-behavior failure modes.  And the final ", and add a test" is
filler that does not add much value.

> +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 &&

This cherry-pick will fail at the very first step.  HEAD stays unborn
and the abort-safety file would be empty.  Even without the code fix, if
the variables on the stack happened to be zero-initialized, doesn't this
test pass by coincidence, or fail in rollback_is_safe() with "could not
parse abort-safety" rather than "could not parse object"?  Perhaps it is
a good idea to check how the command fails and with what error message,
not just having test_must_fail to make sure that the command dies a
controlled death, plus validating that the sequencer/head file stores
$ZERO_OID, to harden the test?

> +	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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 0/2] sequencer: save the null OID for an unborn branch
  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 14:54 ` Junio C Hamano
@ 2026-11-25  3:23 ` 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
                     ` (2 more replies)
  2 siblings, 3 replies; 12+ messages in thread
From: Wonseok Oh via GitGitGadget @ 2026-11-25  3:23 UTC (permalink / raw)
  To: git; +Cc: Phillip Wood, Junio C Hamano, Wonseok Oh

When "git cherry-pick" picks multiple commits onto an unborn branch, it
saves an uninitialized object ID in .git/sequencer/head, so "--abort"
behaves unpredictably. Patch 1 saves the null OID there. Patch 2 makes
.git/sequencer/abort-safety hold the null OID for an unborn branch as well,
instead of leaving it empty, as Phillip suggested.

Changes since v1:

 * Reworded patch 1's commit message, as Phillip and Junio suggested.
 * Reworked patch 1's test, as Junio suggested. The first pick now succeeds,
   so HEAD is born before the sequence stops, as described in the commit
   message. The test checks both error messages and verifies that
   .git/sequencer/head holds $ZERO_OID. It can still pass by luck if the
   stack happens to be zeroed.
 * Added patch 2, as Phillip suggested.

Wonseok Oh (2):
  sequencer: clear saved HEAD OID when picking onto an unborn branch
  sequencer: save the null OID in abort-safety on an unborn branch

 sequencer.c                     | 16 +++++++++-------
 t/t3510-cherry-pick-sequence.sh | 26 ++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 7 deletions(-)


base-commit: e1ec09b23c8e0deb21a0b95ac5996422277395d4
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2317%2Fmarinelay%2Fcherry-pick-unborn-abort-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2317/marinelay/cherry-pick-unborn-abort-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/2317

Range-diff vs v1:

 1:  7933c657b6 ! 1:  7c0fe312f1 sequencer: reset saved HEAD OID when picking onto an unborn branch
     @@ Metadata
      Author: Wonseok Oh <marinelay7@gmail.com>
      
       ## Commit message ##
     -    sequencer: reset saved HEAD OID when picking onto an unborn branch
     +    sequencer: clear saved HEAD OID when picking onto an unborn branch
      
     -    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
     +    When picking multiple commits, "git cherry-pick" saves the current HEAD
     +    in .git/sequencer/head so "--abort" can return to it. An unborn branch
     +    has no commit to return to, so cherry-pick is expected to save the null
     +    OID instead. Only then can sequencer_rollback() refuse "--abort" with
          "cannot abort from a branch yet to be born".
      
     -    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.
     +    However, sequencer_pick_revisions() does not handle this case. On an
     +    unborn branch, repo_get_oid() fails to resolve HEAD, and the function
     +    saves the uninitialized 'oid' to .git/sequencer/head. As a result,
     +    "--abort" is not guaranteed to refuse the abort as intended (e.g., the
     +    saved 'oid' may point to a random commit, and "--abort" then moves the
     +    branch there).
      
     -    Clear the object ID to the null OID when HEAD cannot be resolved, and
     -    add a test.
     +    This bug was introduced in 0f974e2124 (cherry-pick: allow to pick to
     +    unborn branches, 2016-06-06). Before that, picking onto an unborn
     +    branch was refused.
     +
     +    Clear 'oid' with oidclr() when HEAD cannot be resolved, so that the
     +    null OID is saved.
      
          Signed-off-by: Wonseok Oh <marinelay7@gmail.com>
      
     @@ t/t3510-cherry-pick-sequence.sh: test_expect_success 'allow skipping commit but
       	test_cmp expect advice
       '
       
     -+test_expect_success 'cannot abort a cherry-pick sequence on a new history' '
     ++test_expect_success 'cannot abort a cherry-pick sequence started on an unborn branch' '
      +	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_must_fail git cherry-pick initial picked 2>err &&
     ++	test_grep "could not apply .* picked" err &&
     ++	echo $ZERO_OID >expect &&
     ++	test_cmp expect .git/sequencer/head &&
     ++	git rev-parse HEAD >expect &&
     ++	test_must_fail git cherry-pick --abort 2>err &&
     ++	test_grep "cannot abort from a branch yet to be born" err &&
     ++	git rev-parse HEAD >actual &&
     ++	test_cmp expect actual
      +'
      +
       test_expect_success 'allow skipping stopped cherry-pick because of untracked file modifications' '
 -:  ---------- > 2:  14e015ba24 sequencer: save the null OID in abort-safety on an unborn branch

-- 
gitgitgadget

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 1/2] sequencer: clear saved HEAD OID when picking onto an unborn branch
  2026-11-25  3:23 ` [PATCH v2 0/2] sequencer: save the null OID for " Wonseok Oh via GitGitGadget
@ 2026-11-25  3:23   ` 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:17   ` [PATCH v2 0/2] sequencer: save the null OID for " Junio C Hamano
  2 siblings, 1 reply; 12+ messages in thread
From: Wonseok Oh via GitGitGadget @ 2026-11-25  3:23 UTC (permalink / raw)
  To: git; +Cc: Phillip Wood, Junio C Hamano, Wonseok Oh, Wonseok Oh

From: Wonseok Oh <marinelay7@gmail.com>

When picking multiple commits, "git cherry-pick" saves the current HEAD
in .git/sequencer/head so "--abort" can return to it. An unborn branch
has no commit to return to, so cherry-pick is expected to save the null
OID instead. Only then can sequencer_rollback() refuse "--abort" with
"cannot abort from a branch yet to be born".

However, sequencer_pick_revisions() does not handle this case. On an
unborn branch, repo_get_oid() fails to resolve HEAD, and the function
saves the uninitialized 'oid' to .git/sequencer/head. As a result,
"--abort" is not guaranteed to refuse the abort as intended (e.g., the
saved 'oid' may point to a random commit, and "--abort" then moves the
branch there).

This bug was introduced in 0f974e2124 (cherry-pick: allow to pick to
unborn branches, 2016-06-06). Before that, picking onto an unborn
branch was refused.

Clear 'oid' with oidclr() when HEAD cannot be resolved, so that the
null OID is saved.

Signed-off-by: Wonseok Oh <marinelay7@gmail.com>
---
 sequencer.c                     |  9 ++++++---
 t/t3510-cherry-pick-sequence.sh | 15 +++++++++++++++
 2 files changed, 21 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..d52fda1c54 100755
--- a/t/t3510-cherry-pick-sequence.sh
+++ b/t/t3510-cherry-pick-sequence.sh
@@ -269,6 +269,21 @@ 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 started on an unborn branch' '
+	pristine_detach initial &&
+	git checkout --orphan new_disconnected_seq &&
+	git reset --hard &&
+	test_must_fail git cherry-pick initial picked 2>err &&
+	test_grep "could not apply .* picked" err &&
+	echo $ZERO_OID >expect &&
+	test_cmp expect .git/sequencer/head &&
+	git rev-parse HEAD >expect &&
+	test_must_fail git cherry-pick --abort 2>err &&
+	test_grep "cannot abort from a branch yet to be born" err &&
+	git rev-parse HEAD >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'allow skipping stopped cherry-pick because of untracked file modifications' '
 	test_when_finished "rm unrelated" &&
 	pristine_detach initial &&
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 2/2] sequencer: save the null OID in abort-safety on an unborn branch
  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  3:23   ` Wonseok Oh via GitGitGadget
  2026-11-25 17:07     ` Junio C Hamano
  2026-11-25 17:17   ` [PATCH v2 0/2] sequencer: save the null OID for " Junio C Hamano
  2 siblings, 1 reply; 12+ messages in thread
From: Wonseok Oh via GitGitGadget @ 2026-11-25  3:23 UTC (permalink / raw)
  To: git; +Cc: Phillip Wood, Junio C Hamano, Wonseok Oh, Wonseok Oh

From: Wonseok Oh <marinelay7@gmail.com>

On an unborn branch, .git/sequencer/head holds the null OID, but
update_abort_safety_file() writes an empty .git/sequencer/abort-safety.
Write the null OID there as well so both state files represent an
unborn branch the same way, as older versions of Git expect.

Suggested-by: Phillip Wood <phillip.wood123@gmail.com>
Signed-off-by: Wonseok Oh <marinelay7@gmail.com>
---
 sequencer.c                     |  7 +++----
 t/t3510-cherry-pick-sequence.sh | 11 +++++++++++
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/sequencer.c b/sequencer.c
index 20bfe00ba3..e0bfc6305a 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -644,10 +644,9 @@ static void update_abort_safety_file(void)
 	if (!file_exists(git_path_seq_dir()))
 		return;
 
-	if (!repo_get_oid(the_repository, "HEAD", &head))
-		write_file(git_path_abort_safety_file(), "%s", oid_to_hex(&head));
-	else
-		write_file(git_path_abort_safety_file(), "%s", "");
+	if (repo_get_oid(the_repository, "HEAD", &head))
+		oidclr(&head, the_repository->hash_algo);
+	write_file(git_path_abort_safety_file(), "%s", oid_to_hex(&head));
 }
 
 static int fast_forward_to(struct repository *r,
diff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh
index d52fda1c54..fb1ce079f8 100755
--- a/t/t3510-cherry-pick-sequence.sh
+++ b/t/t3510-cherry-pick-sequence.sh
@@ -284,6 +284,17 @@ test_expect_success 'cannot abort a cherry-pick sequence started on an unborn br
 	test_cmp expect actual
 '
 
+test_expect_success 'unborn branch is saved as the null OID in the sequencer state' '
+	pristine_detach initial &&
+	git checkout --orphan new_disconnected_state &&
+	git reset --hard &&
+	test_must_fail git cherry-pick base..anotherpick 2>err &&
+	test_grep "could not apply .* unrelatedpick" err &&
+	echo $ZERO_OID >expect &&
+	test_cmp expect .git/sequencer/head &&
+	test_cmp expect .git/sequencer/abort-safety
+'
+
 test_expect_success 'allow skipping stopped cherry-pick because of untracked file modifications' '
 	test_when_finished "rm unrelated" &&
 	pristine_detach initial &&
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 1/2] sequencer: clear saved HEAD OID when picking onto an unborn branch
  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
  0 siblings, 0 replies; 12+ messages in thread
From: Junio C Hamano @ 2026-11-25 16:57 UTC (permalink / raw)
  To: Wonseok Oh via GitGitGadget; +Cc: git, Phillip Wood, Wonseok Oh, Wonseok Oh

"Wonseok Oh via GitGitGadget" <gitgitgadget@gmail.com> writes:

> However, sequencer_pick_revisions() does not handle this case. On an
> unborn branch, repo_get_oid() fails to resolve HEAD, and the function
> saves the uninitialized 'oid' to .git/sequencer/head. As a result,
> "--abort" is not guaranteed to refuse the abort as intended (e.g., the
> saved 'oid' may point to a random commit, and "--abort" then moves the
> branch there).

Nicely described.

In sequencer_pick_revisions(), an earlier loop over opts->revs->pending
declares an inner struct object_id oid of its own, so the outer oid can
either hold arbitrary stack garbage (including an invalid '.algo' member
passed to oid_to_hex()) or retain the OID of the last commit checked in
that loop.

> 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))) {

Calling oidclr(&oid, r->hash_algo) initializes both '.hash' and '.algo'
members, so save_head(oid_to_hex(&oid)) writes the right null OID for
the repository's hash algorithm.  Later, sequencer_rollback() parses
.git/sequencer/head and hits its is_null_oid(&oid) check to reject
"--abort" before touching HEAD.

> diff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh
> index 9400ddfc45..d52fda1c54 100755
> --- a/t/t3510-cherry-pick-sequence.sh
> +++ b/t/t3510-cherry-pick-sequence.sh
> @@ -269,6 +269,21 @@ 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 started on an unborn branch' '
> +	pristine_detach initial &&
> +	git checkout --orphan new_disconnected_seq &&
> +	git reset --hard &&
> +	test_must_fail git cherry-pick initial picked 2>err &&
> +	test_grep "could not apply .* picked" err &&
> +	echo $ZERO_OID >expect &&
> +	test_cmp expect .git/sequencer/head &&
> +	git rev-parse HEAD >expect &&
> +	test_must_fail git cherry-pick --abort 2>err &&
> +	test_grep "cannot abort from a branch yet to be born" err &&
> +	git rev-parse HEAD >actual &&
> +	test_cmp expect actual
> +'

Checking that "initial" applies cleanly so the sequence stops at
"picked", validating .git/sequencer/head directly against $ZERO_OID, and
verifying that HEAD stays put on "--abort" closes the gaps from v1.

Looking good.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 2/2] sequencer: save the null OID in abort-safety on an unborn branch
  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
  0 siblings, 1 reply; 12+ messages in thread
From: Junio C Hamano @ 2026-11-25 17:07 UTC (permalink / raw)
  To: Wonseok Oh via GitGitGadget; +Cc: git, Phillip Wood, Wonseok Oh, Wonseok Oh

"Wonseok Oh via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: Wonseok Oh <marinelay7@gmail.com>
>
> On an unborn branch, .git/sequencer/head holds the null OID, but
> update_abort_safety_file() writes an empty .git/sequencer/abort-safety.
> Write the null OID there as well so both state files represent an
> unborn branch the same way, as older versions of Git expect.

Don't later versions of Git including the latest one also barf if
get_oid_hex() is unhappy on the contents of the abort-safety file?

In sequencer.c, rollback_is_safe() reads the file like this

    if (strbuf_read_file(&sb, git_path_abort_safety_file(), 0) >= 0) {
            strbuf_trim(&sb);
            if (get_oid_hex(sb.buf, &expected_head)) {
                    strbuf_release(&sb);
                    die(_("could not parse %s"),
                        git_path_abort_safety_file());
            }
            strbuf_release(&sb);
    }

If a multi-commit cherry-pick on an unborn branch stops without
CHERRY_PICK_HEAD (or after "git reset --merge") and the user runs "git
cherry-pick --skip", sequencer_skip() calls rollback_is_safe() and hits
that die(), I think.

If there is another reroll, mentioning that rollback_is_safe() fails to
parse an empty file would make the motivation even clearer.

> diff --git a/sequencer.c b/sequencer.c
> index 20bfe00ba3..e0bfc6305a 100644
> --- a/sequencer.c
> +++ b/sequencer.c
> @@ -644,10 +644,9 @@ static void update_abort_safety_file(void)
>  	if (!file_exists(git_path_seq_dir()))
>  		return;
>  
> -	if (!repo_get_oid(the_repository, "HEAD", &head))
> -		write_file(git_path_abort_safety_file(), "%s", oid_to_hex(&head));
> -	else
> -		write_file(git_path_abort_safety_file(), "%s", "");
> +	if (repo_get_oid(the_repository, "HEAD", &head))
> +		oidclr(&head, the_repository->hash_algo);
> +	write_file(git_path_abort_safety_file(), "%s", oid_to_hex(&head));
>  }

The implementation is clean and covers all callers of
update_abort_safety_file().  Trivially correct.

> diff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh
> index d52fda1c54..fb1ce079f8 100755
> --- a/t/t3510-cherry-pick-sequence.sh
> +++ b/t/t3510-cherry-pick-sequence.sh
> @@ -284,6 +284,17 @@ test_expect_success 'cannot abort a cherry-pick sequence started on an unborn br
>  	test_cmp expect actual
>  '
>  
> +test_expect_success 'unborn branch is saved as the null OID in the sequencer state' '
> +	pristine_detach initial &&
> +	git checkout --orphan new_disconnected_state &&
> +	git reset --hard &&
> +	test_must_fail git cherry-pick base..anotherpick 2>err &&
> +	test_grep "could not apply .* unrelatedpick" err &&
> +	echo $ZERO_OID >expect &&
> +	test_cmp expect .git/sequencer/head &&
> +	test_cmp expect .git/sequencer/abort-safety
> +'

Here "unrelatedpick" conflicts against the empty tree, so HEAD stays
unborn and both state files are checked directly.

We could also add a check to run "git reset --merge" followed by "git
cherry-pick --skip" to cover rollback_is_safe() as well, though checking
the state file directly already verifies the change.

Looking good.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 0/2] sequencer: save the null OID for an unborn branch
  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  3:23   ` [PATCH v2 2/2] sequencer: save the null OID in abort-safety on " Wonseok Oh via GitGitGadget
@ 2026-11-25 17:17   ` Junio C Hamano
  2 siblings, 0 replies; 12+ messages in thread
From: Junio C Hamano @ 2026-11-25 17:17 UTC (permalink / raw)
  To: Wonseok Oh via GitGitGadget; +Cc: git, Phillip Wood, Wonseok Oh

"Wonseok Oh via GitGitGadget" <gitgitgadget@gmail.com> writes:

> When "git cherry-pick" picks multiple commits onto an unborn branch, it
> saves an uninitialized object ID in .git/sequencer/head, so "--abort"
> behaves unpredictably. Patch 1 saves the null OID there. Patch 2 makes
> .git/sequencer/abort-safety hold the null OID for an unborn branch as well,
> instead of leaving it empty, as Phillip suggested.

The split in this iteration addresses the feedback from v1 cleanly.

Keeping the fix for the uninitialized OID in .git/sequencer/head
separate from the .git/sequencer/abort-safety update makes both changes
straightforward to verify, and the test adjustments in patch 1 match the
commit log scenario well.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 2/2] sequencer: save the null OID in abort-safety on an unborn branch
  2026-11-25 17:07     ` Junio C Hamano
@ 2026-11-26 16:32       ` Phillip Wood
  0 siblings, 0 replies; 12+ messages in thread
From: Phillip Wood @ 2026-11-26 16:32 UTC (permalink / raw)
  To: Junio C Hamano, Wonseok Oh via GitGitGadget; +Cc: git, Wonseok Oh, Wonseok Oh

On 25/11/2026 17:07, Junio C Hamano wrote:
> "Wonseok Oh via GitGitGadget" <gitgitgadget@gmail.com> writes:
> 
>> From: Wonseok Oh <marinelay7@gmail.com>
>>
>> On an unborn branch, .git/sequencer/head holds the null OID, but
>> update_abort_safety_file() writes an empty .git/sequencer/abort-safety.
>> Write the null OID there as well so both state files represent an
>> unborn branch the same way, as older versions of Git expect.
> 
> Don't later versions of Git including the latest one also barf if
> get_oid_hex() is unhappy on the contents of the abort-safety file?
> 
> In sequencer.c, rollback_is_safe() reads the file like this
> 
>      if (strbuf_read_file(&sb, git_path_abort_safety_file(), 0) >= 0) {
>              strbuf_trim(&sb);
>              if (get_oid_hex(sb.buf, &expected_head)) {
>                      strbuf_release(&sb);
>                      die(_("could not parse %s"),
>                          git_path_abort_safety_file());
>              }
>              strbuf_release(&sb);
>      }
> 
> If a multi-commit cherry-pick on an unborn branch stops without
> CHERRY_PICK_HEAD (or after "git reset --merge") and the user runs "git
> cherry-pick --skip", sequencer_skip() calls rollback_is_safe() and hits
> that die(), I think.
> 
> If there is another reroll, mentioning that rollback_is_safe() fails to
> parse an empty file would make the motivation even clearer.

I agree that would be clearer - the important thing is that we're 
changing the way we write the file to match what we expect to read. The 
implementation here and patch 1 look good to me.

Thanks

Phillip

> 
>> diff --git a/sequencer.c b/sequencer.c
>> index 20bfe00ba3..e0bfc6305a 100644
>> --- a/sequencer.c
>> +++ b/sequencer.c
>> @@ -644,10 +644,9 @@ static void update_abort_safety_file(void)
>>   	if (!file_exists(git_path_seq_dir()))
>>   		return;
>>   
>> -	if (!repo_get_oid(the_repository, "HEAD", &head))
>> -		write_file(git_path_abort_safety_file(), "%s", oid_to_hex(&head));
>> -	else
>> -		write_file(git_path_abort_safety_file(), "%s", "");
>> +	if (repo_get_oid(the_repository, "HEAD", &head))
>> +		oidclr(&head, the_repository->hash_algo);
>> +	write_file(git_path_abort_safety_file(), "%s", oid_to_hex(&head));
>>   }
> 
> The implementation is clean and covers all callers of
> update_abort_safety_file().  Trivially correct.
> 
>> diff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh
>> index d52fda1c54..fb1ce079f8 100755
>> --- a/t/t3510-cherry-pick-sequence.sh
>> +++ b/t/t3510-cherry-pick-sequence.sh
>> @@ -284,6 +284,17 @@ test_expect_success 'cannot abort a cherry-pick sequence started on an unborn br
>>   	test_cmp expect actual
>>   '
>>   
>> +test_expect_success 'unborn branch is saved as the null OID in the sequencer state' '
>> +	pristine_detach initial &&
>> +	git checkout --orphan new_disconnected_state &&
>> +	git reset --hard &&
>> +	test_must_fail git cherry-pick base..anotherpick 2>err &&
>> +	test_grep "could not apply .* unrelatedpick" err &&
>> +	echo $ZERO_OID >expect &&
>> +	test_cmp expect .git/sequencer/head &&
>> +	test_cmp expect .git/sequencer/abort-safety
>> +'
> 
> Here "unrelatedpick" conflicts against the empty tree, so HEAD stays
> unborn and both state files are checked directly.
> 
> We could also add a check to run "git reset --merge" followed by "git
> cherry-pick --skip" to cover rollback_is_safe() as well, though checking
> the state file directly already verifies the change.
> 
> Looking good.


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2026-11-26 16:32 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox