sequencer: comment checked-out branch properly
`git rebase --update-ref` does not insert commands for dependent/sub- branches which are checked out.[1] Instead it leaves a comment about that fact. The comment char is hardcoded (#). In turn the comment line gets interpreted as an invalid command when `core.commentChar`/ `core.commentString` is in use. † 1: See 900b50c242 (rebase: add --update-refs option, 2022-07-19) Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Kristoffer Haugsbakk committed
Nov 25, 2024 at 21:13 UTC
94304b9f48e9c68f3214e25527c3aac865d3ce63
2 files changed
+22
-2
sequencer.c
+3
-2
@@ -6382,8 +6382,9 @@ static int add_decorations_to_list(const struct commit *commit,
6382
/* If the branch is checked out, then leave a comment instead. */
6383
if ((path = branch_checked_out(decoration->name))) {
6384
item->command = TODO_COMMENT;
6385
- strbuf_addf(ctx->buf, "# Ref %s checked out at '%s'\n",
6386
- decoration->name, path);
6385
+ strbuf_commented_addf(ctx->buf, comment_line_str,
6386
+ "Ref %s checked out at '%s'\n",
6387
+ decoration->name, path);
6388
} else {
6389
struct string_list_item *sti;
6390
item->command = TODO_UPDATE_REF;
t/t3400-rebase.sh
+19
@@ -456,4 +456,23 @@ test_expect_success 'rebase when inside worktree subdirectory' '
456
)
457
'
458
459
+test_expect_success 'git rebase --update-ref with core.commentChar and branch on worktree' '
460
+ test_when_finished git branch -D base topic2 &&
461
+ test_when_finished git checkout main &&
462
+ test_when_finished git branch -D wt-topic &&
463
+ test_when_finished git worktree remove wt-topic &&
464
+ git checkout main &&
465
+ git checkout -b base &&
466
+ git checkout -b topic2 &&
467
+ test_commit msg2 &&
468
+ git worktree add wt-topic &&
469
+ git checkout base &&
470
+ test_commit msg3 &&
471
+ git checkout topic2 &&
472
+ GIT_SEQUENCE_EDITOR="cat >actual" git -c core.commentChar=% \
473
+ rebase -i --update-refs base &&
474
+ test_grep "% Ref refs/heads/wt-topic checked out at" actual &&
475
+ test_grep "% Ref refs/heads/topic2 checked out at" actual
476
+'
477
+
478
test_done