sequencer: ignore HEAD ref under --update-refs

When using the 'git rebase -i --update-refs' option, the todo list is populated with 'update-ref' commands for all tip refs in the history that is being rebased. Refs that are checked out by some worktree are instead added as a comment to warn the user that they will not be updated. Until now, this included the HEAD ref, which is being updated by the rebase process itself, regardless of the --update-refs option. Remove the comment in this case by ignoring any decorations that match the HEAD ref. Reported-by: Elijah Newren <newren@gmail.com> Signed-off-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Jul 19, 2022 at 18:33 UTC aa37f3e1d892698276b52f347c6374499f6c0759
1 file changed +13
sequencer.c
+13
@@ -5888,12 +5888,25 @@ static int add_decorations_to_list(const struct commit *commit,
5888 struct todo_add_branch_context *ctx)
5889 {
5890 const struct name_decoration *decoration = get_name_decoration(&commit->object);
5891 + const char *head_ref = resolve_ref_unsafe("HEAD",
5892 + RESOLVE_REF_READING,
5893 + NULL,
5894 + NULL);
5895
5896 while (decoration) {
5897 struct todo_item *item;
5898 const char *path;
5899 size_t base_offset = ctx->buf->len;
5900
5901 + /*
5902 + * If the branch is the current HEAD, then it will be
5903 + * updated by the default rebase behavior.
5904 + */
5905 + if (head_ref && !strcmp(head_ref, decoration->name)) {
5906 + decoration = decoration->next;
5907 + continue;
5908 + }
5909 +
5910 ALLOC_GROW(ctx->items,
5911 ctx->items_nr + 1,
5912 ctx->items_alloc);