diff --git a/sequencer.c b/sequencer.c index 2ac78e15b8..508ec71792 100644 --- a/sequencer.c +++ b/sequencer.c @@ -6618,11 +6618,11 @@ static int add_decorations_to_list(const struct commit *commit, struct todo_add_branch_context *ctx) { const struct name_decoration *decoration = get_name_decoration(&commit->object); - const char *head_ref = refs_resolve_ref_unsafe(get_main_ref_store(the_repository), - "HEAD", - RESOLVE_REF_READING, - NULL, - NULL); + char *head_ref = refs_resolve_refdup(get_main_ref_store(the_repository), + "HEAD", + RESOLVE_REF_READING, + NULL, + NULL); while (decoration) { struct todo_item *item; @@ -6674,6 +6674,7 @@ static int add_decorations_to_list(const struct commit *commit, decoration = decoration->next; } + free(head_ref); return 0; } diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh index accaaba4d4..0e7ef33eb1 100755 --- a/t/t3400-rebase.sh +++ b/t/t3400-rebase.sh @@ -483,7 +483,26 @@ test_expect_success 'git rebase --update-ref with core.commentChar and branch on GIT_SEQUENCE_EDITOR="cat >actual" git -c core.commentChar=% \ rebase -i --update-refs base && test_grep "% Ref refs/heads/wt-topic checked out at" actual && - test_grep "% Ref refs/heads/topic2 checked out at" actual + test_grep ! "Ref refs/heads/topic2" actual +' + +test_expect_success 'git rebase --update-refs ignores current branch with branches on worktrees' ' + test_when_finished git branch -D base current a-topic z-topic && + test_when_finished git checkout main && + test_when_finished git worktree remove z-topic && + test_when_finished git worktree remove a-topic && + git checkout -b base main && + git checkout -b current && + test_commit msg4 && + git worktree add a-topic && + git worktree add z-topic && + git checkout base && + test_commit msg5 && + git checkout current && + GIT_SEQUENCE_EDITOR="cat >actual" git rebase -i --update-refs base && + test_grep "# Ref refs/heads/a-topic checked out at" actual && + test_grep "# Ref refs/heads/z-topic checked out at" actual && + test_grep ! "refs/heads/current" actual ' test_done