diff mbox series

[v5,11/12] sequencer: ignore HEAD ref under --update-refs

Message ID 2a6577974c7f72c075cb403b4b2573c6d1c7f033.1658255624.git.gitgitgadget@gmail.com (mailing list archive)
State Accepted
Commit aa37f3e1d892698276b52f347c6374499f6c0759
Headers show
Series rebase: update branches in multi-part topic | expand

Commit Message

Derrick Stolee July 19, 2022, 6:33 p.m. UTC
From: Derrick Stolee <derrickstolee@github.com>

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>
---
 sequencer.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
diff mbox series

Patch

diff --git a/sequencer.c b/sequencer.c
index 67812c0294f..1602649332b 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -5853,12 +5853,25 @@  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 = resolve_ref_unsafe("HEAD",
+						  RESOLVE_REF_READING,
+						  NULL,
+						  NULL);
 
 	while (decoration) {
 		struct todo_item *item;
 		const char *path;
 		size_t base_offset = ctx->buf->len;
 
+		/*
+		 * If the branch is the current HEAD, then it will be
+		 * updated by the default rebase behavior.
+		 */
+		if (head_ref && !strcmp(head_ref, decoration->name)) {
+			decoration = decoration->next;
+			continue;
+		}
+
 		ALLOC_GROW(ctx->items,
 			ctx->items_nr + 1,
 			ctx->items_alloc);