{"thread":{"id":"66902","subject":"[PATCH] sequencer: reset saved HEAD OID when picking onto an unborn branch","startedAt":"2026-11-21T06:30:33Z","lastAt":"2026-11-21T06:30:33Z","messageCount":1,"participants":["Wonseok Oh via GitGitGadget"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"559019","messageId":"pull.2317.git.1795242633923.gitgitgadget@gmail.com","threadId":"66902","inReplyTo":null,"subject":"[PATCH] sequencer: reset saved HEAD OID when picking onto an unborn branch","fromName":"Wonseok Oh via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-21T06:30:33Z","receivedAt":"2026-11-21T06:30:33Z","isPatch":true,"sender":{"key":"name:Wonseok Oh","avatar":null},"body":"From: Wonseok Oh <marinelay7@gmail.com>\n\nWhen picking multiple commits, \"git cherry-pick\" stores the current HEAD\nin .git/sequencer/head for \"--abort\" to return to. If the branch is\nunborn, repo_get_oid() fails and leaves the object ID uninitialized,\nbut sequencer_pick_revisions() saves it anyway instead of clearing it\nto the null OID that sequencer_rollback() checks for to report\n\"cannot abort from a branch yet to be born\".\n\nAs a result, \"--abort\" errors out with \"Could not parse object\" in my\nmaster build, while in Debian's 2.47.3 build the uninitialized memory\nhappened to hold the last picked commit's OID and moved the new branch\nthere.\n\nClear the object ID to the null OID when HEAD cannot be resolved, and\nadd a test.\n\nSigned-off-by: Wonseok Oh <marinelay7@gmail.com>\n---\n    sequencer: reset saved HEAD OID when picking onto an unborn branch\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-2317%2Fmarinelay%2Fcherry-pick-unborn-abort-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2317/marinelay/cherry-pick-unborn-abort-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/2317\n\n sequencer.c                     |  9 ++++++---\n t/t3510-cherry-pick-sequence.sh | 10 ++++++++++\n 2 files changed, 16 insertions(+), 3 deletions(-)\n\ndiff --git a/sequencer.c b/sequencer.c\nindex 4a1c0e70b8..20bfe00ba3 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -5788,9 +5788,12 @@ int sequencer_pick_revisions(struct repository *r,\n \t\tgoto out;\n \t}\n \n-\tif (repo_get_oid(r, \"HEAD\", &oid) && (opts->action == REPLAY_REVERT)) {\n-\t\tres = error(_(\"can't revert as initial commit\"));\n-\t\tgoto out;\n+\tif (repo_get_oid(r, \"HEAD\", &oid)) {\n+\t\tif (opts->action == REPLAY_REVERT) {\n+\t\t\tres = error(_(\"can't revert as initial commit\"));\n+\t\t\tgoto out;\n+\t\t}\n+\t\toidclr(&oid, r->hash_algo);\n \t}\n \n \tif (save_head(oid_to_hex(&oid))) {\ndiff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh\nindex 9400ddfc45..75004bba0c 100755\n--- a/t/t3510-cherry-pick-sequence.sh\n+++ b/t/t3510-cherry-pick-sequence.sh\n@@ -269,6 +269,16 @@ test_expect_success 'allow skipping commit but not abort for a new history' '\n \ttest_cmp expect advice\n '\n \n+test_expect_success 'cannot abort a cherry-pick sequence on a new history' '\n+\tpristine_detach initial &&\n+\tgit checkout --orphan new_disconnected_seq &&\n+\tgit reset --hard &&\n+\ttest_must_fail git cherry-pick base..anotherpick &&\n+\ttest_must_fail git cherry-pick --abort 2>advice &&\n+\ttest_grep \"cannot abort from a branch yet to be born\" advice &&\n+\ttest_must_fail git rev-parse --verify HEAD\n+'\n+\n test_expect_success 'allow skipping stopped cherry-pick because of untracked file modifications' '\n \ttest_when_finished \"rm unrelated\" &&\n \tpristine_detach initial &&\n\nbase-commit: e1ec09b23c8e0deb21a0b95ac5996422277395d4\n-- \ngitgitgadget\n\n"}]}