Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Wonseok Oh via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org,  Phillip Wood <phillip.wood123@gmail.com>,
	 Wonseok Oh <wonseok_oh@korea.ac.kr>,
	 Wonseok Oh <marinelay7@gmail.com>
Subject: Re: [PATCH v2 1/2] sequencer: clear saved HEAD OID when picking onto an unborn branch
Date: Wed, 25 Nov 2026 08:57:38 -0800	[thread overview]
Message-ID: <xmqq8q2g97ct.fsf@gitster.g> (raw)
In-Reply-To: <7c0fe312f161247a5e7192e214e8677547521a92.1795577024.git.gitgitgadget@gmail.com> (Wonseok Oh via GitGitGadget's message of "Wed, 25 Nov 2026 03:23:43 +0000")

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

  reply	other threads:[~2026-11-25 16:57 UTC|newest]

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

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=xmqq8q2g97ct.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=marinelay7@gmail.com \
    --cc=phillip.wood123@gmail.com \
    --cc=wonseok_oh@korea.ac.kr \
    /path/to/YOUR_REPLY

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

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