Git development
 help / color / mirror / Atom feed
From: "Wonseok Oh via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Wonseok Oh <wonseok_oh@korea.ac.kr>, Wonseok Oh <marinelay7@gmail.com>
Subject: [PATCH] sequencer: reset saved HEAD OID when picking onto an unborn branch
Date: Sat, 21 Nov 2026 06:30:33 +0000	[thread overview]
Message-ID: <pull.2317.git.1795242633923.gitgitgadget@gmail.com> (raw)

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

                 reply	other threads:[~2026-11-21  6:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=pull.2317.git.1795242633923.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=marinelay7@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