git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] sequencer: reset saved HEAD OID when picking onto an unborn branch

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Nov 23, 2026, 14:32 UTC
Message-ID
<27abe897-cba1-4561-816a-875c064ab8c0@gmail.com>
In-Reply-To
<pull.2317.git.1795242633923.gitgitgadget@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:
Show 7 quoted lines
> 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
Show 54 quoted lines
> 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
Previous: Wonseok Oh via GitGitGadgetNext: Wonseok Oh
Message 2 of 8 in “sequencer: reset saved HEAD OID when picking onto an unborn branch”
  1. sequencer: reset saved HEAD OID when picking onto an unborn branchWonseok Oh via GitGitGadget, Nov 21, 2026
  2. Phillip WoodNov 23, 2026
  3. Wonseok OhNov 24, 2026
  4. Phillip WoodNov 24, 2026
  5. Junio C HamanoNov 24, 2026
  6. 0/2 sequencer: save the null OID for an unborn branchWonseok Oh via GitGitGadget, Nov 25, 2026
  7. 1/2 sequencer: clear saved HEAD OID when picking onto an unborn branchWonseok Oh via GitGitGadget, Nov 25, 2026
  8. 2/2 sequencer: save the null OID in abort-safety on an unborn branchWonseok Oh via GitGitGadget, Nov 25, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.