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 2/2] sequencer: save the null OID in abort-safety on an unborn branch
Date: Wed, 25 Nov 2026 09:07:38 -0800	[thread overview]
Message-ID: <xmqq4id496w5.fsf@gitster.g> (raw)
In-Reply-To: <14e015ba240a661d8cf8b6bdbc4d7093bbc42ad3.1795577024.git.gitgitgadget@gmail.com> (Wonseok Oh via GitGitGadget's message of "Wed, 25 Nov 2026 03:23:44 +0000")

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

  reply	other threads:[~2026-11-25 17:07 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
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 [this message]
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=xmqq4id496w5.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