Skip to content

Commit 94304b9

Browse files
LemmingAvalanchegitster
authored andcommitted
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 900b50c (rebase: add --update-refs option, 2022-07-19) Signed-off-by: Kristoffer Haugsbakk <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fd37853 commit 94304b9

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

sequencer.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6382,8 +6382,9 @@ static int add_decorations_to_list(const struct commit *commit,
63826382
/* If the branch is checked out, then leave a comment instead. */
63836383
if ((path = branch_checked_out(decoration->name))) {
63846384
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);
63876388
} else {
63886389
struct string_list_item *sti;
63896390
item->command = TODO_UPDATE_REF;

t/t3400-rebase.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,4 +456,23 @@ test_expect_success 'rebase when inside worktree subdirectory' '
456456
)
457457
'
458458

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+
459478
test_done

0 commit comments

Comments
 (0)