Repository navigation
Conversation
Welcome to GitGitGadgetHi @marinelay, and welcome to GitGitGadget, the GitHub App to send patch series to the Git mailing list from GitHub Pull Requests. Please make sure that either:
You can CC potential reviewers by adding a footer to the PR description with the following syntax: NOTE: DO NOT copy/paste your CC list from a previous GGG PR's description, Also, it is a good idea to review the commit messages one last time, as the Git project expects them in a quite specific form:
It is in general a good idea to await the automated test ("Checks") in this Pull Request before contributing the patches, e.g. to avoid trivial issues such as unportable code. Contributing the patchesBefore you can contribute the patches, your GitHub username needs to be added to the list of permitted users. Any already-permitted user can do that, by adding a comment to your PR of the form Both the person who commented An alternative is the channel Once on the list of permitted usernames, you can contribute the patches to the Git mailing list by adding a PR comment If you want to see what email(s) would be sent for a After you submit, GitGitGadget will respond with another comment that contains the link to the cover letter mail in the Git mailing list archive. Please make sure to monitor the discussion in that thread and to address comments and suggestions (while the comments and suggestions will be mirrored into the PR by GitGitGadget, you will still want to reply via mail). If you do not want to subscribe to the Git mailing list just to be able to respond to a mail, you can download the mbox from the Git mailing list archive (click the curl -g --user "<EMailAddress>:<Password>" \
--url "imaps://imap.gmail.com/INBOX" -T /path/to/raw.txtTo iterate on your change, i.e. send a revised patch or patch series, you will first want to (force-)push to the same branch. You probably also want to modify your Pull Request description (or title). It is a good idea to summarize the revision by adding something like this to the cover letter (read: by editing the first comment on the PR, i.e. the PR description): To send a new iteration, just add another PR comment with the contents: Need help?New contributors who want advice are encouraged to join git-mentoring@googlegroups.com, where volunteers who regularly contribute to Git are willing to answer newbie questions, give advice, or otherwise provide mentoring to interested contributors. You must join in order to post or view messages, but anyone can join. You may also be able to find help in real time in the developer IRC channel, |
|
/allow |
|
User marinelay is now allowed to use GitGitGadget. |
|
/preview |
|
Preview email sent as pull.2317.git.1795242436486.gitgitgadget@gmail.com |
|
/submit |
|
Submitted as pull.2317.git.1795242633923.gitgitgadget@gmail.com To fetch this version into To fetch this version to local tag |
|
Phillip Wood wrote on the Git mailing list (how to reply to this email): 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 |
|
User |
|
Wonseok Oh wrote on the Git mailing list (how to reply to this email): 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
> |
|
Phillip Wood wrote on the Git mailing list (how to reply to this email): 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
>> |
|
Junio C Hamano wrote on the Git mailing list (how to reply to this email): "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 |
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 0f974e2 (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>
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>
7933c65 to
14e015b
Compare
|
/preview |
|
Preview email sent as pull.2317.v2.git.1795576861.gitgitgadget@gmail.com |
|
/submit |
|
Submitted as pull.2317.v2.git.1795577024.gitgitgadget@gmail.com To fetch this version into To fetch this version to local tag |
|
This patch series was integrated into seen via git@b6ad521. |
| @@ -5788,9 +5788,12 @@ int sequencer_pick_revisions(struct repository *r, | |||
| goto out; | |||
There was a problem hiding this comment.
Junio C Hamano wrote on the Git mailing list (how to reply to this email):
"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.| @@ -644,10 +644,9 @@ static void update_abort_safety_file(void) | |||
| if (!file_exists(git_path_seq_dir())) | |||
There was a problem hiding this comment.
Junio C Hamano wrote on the Git mailing list (how to reply to this email):
"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.There was a problem hiding this comment.
Phillip Wood wrote on the Git mailing list (how to reply to this email):
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.|
Junio C Hamano wrote on the Git mailing list (how to reply to this email): "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. |
|
This branch is now known as |
|
This patch series was integrated into next via git@4931e36. |
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:
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.
cc: Phillip Wood phillip.wood123@gmail.com
cc: Junio C Hamano gitster@pobox.com