From: "Wonseok Oh via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Phillip Wood <phillip.wood123@gmail.com>,
Junio C Hamano <gitster@pobox.com>,
Wonseok Oh <wonseok_oh@korea.ac.kr>
Subject: [PATCH v2 0/2] sequencer: save the null OID for an unborn branch
Date: Wed, 25 Nov 2026 03:23:42 +0000 [thread overview]
Message-ID: <pull.2317.v2.git.1795577024.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.2317.git.1795242633923.gitgitgadget@gmail.com>
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:
* Reworded patch 1's commit message, as Phillip and Junio suggested.
* Reworked patch 1's test, as Junio suggested. The first pick now 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.
* Added patch 2, as Phillip suggested.
Wonseok Oh (2):
sequencer: clear saved HEAD OID when picking onto an unborn branch
sequencer: save the null OID in abort-safety on an unborn branch
sequencer.c | 16 +++++++++-------
t/t3510-cherry-pick-sequence.sh | 26 ++++++++++++++++++++++++++
2 files changed, 35 insertions(+), 7 deletions(-)
base-commit: e1ec09b23c8e0deb21a0b95ac5996422277395d4
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2317%2Fmarinelay%2Fcherry-pick-unborn-abort-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2317/marinelay/cherry-pick-unborn-abort-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/2317
Range-diff vs v1:
1: 7933c657b6 ! 1: 7c0fe312f1 sequencer: reset saved HEAD OID when picking onto an unborn branch
@@ Metadata
Author: Wonseok Oh <marinelay7@gmail.com>
## Commit message ##
- sequencer: reset saved HEAD OID when picking onto an unborn branch
+ sequencer: clear saved HEAD OID when picking onto an unborn branch
- 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
+ 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".
- 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.
+ 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).
- Clear the object ID to the null OID when HEAD cannot be resolved, and
- add a test.
+ This bug was introduced in 0f974e2124 (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>
@@ t/t3510-cherry-pick-sequence.sh: test_expect_success 'allow skipping commit but
test_cmp expect advice
'
-+test_expect_success 'cannot abort a cherry-pick sequence on a new history' '
++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 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_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
+'
+
test_expect_success 'allow skipping stopped cherry-pick because of untracked file modifications' '
-: ---------- > 2: 14e015ba24 sequencer: save the null OID in abort-safety on an unborn branch
--
gitgitgadget
next prev parent reply other threads:[~2026-11-25 3:23 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 ` Wonseok Oh via GitGitGadget [this message]
2026-11-25 3:23 ` [PATCH v2 1/2] sequencer: clear " 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
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=pull.2317.v2.git.1795577024.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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