Skip to content

Commit 84693f6

Browse files
committed
Merge branch 'kh/sequencer-comment-char' into next
The sequencer failed to honor core.commentString in some places. * kh/sequencer-comment-char: sequencer: comment commit messages properly sequencer: comment `--reference` subject line properly sequencer: comment checked-out branch properly
2 parents 65eba16 + 7e2f377 commit 84693f6

File tree

4 files changed

+64
-10
lines changed

4 files changed

+64
-10
lines changed

sequencer.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,10 +1941,10 @@ static int seen_squash(struct replay_ctx *ctx)
19411941

19421942
static void update_comment_bufs(struct strbuf *buf1, struct strbuf *buf2, int n)
19431943
{
1944-
strbuf_setlen(buf1, 2);
1944+
strbuf_setlen(buf1, strlen(comment_line_str) + 1);
19451945
strbuf_addf(buf1, _(nth_commit_msg_fmt), n);
19461946
strbuf_addch(buf1, '\n');
1947-
strbuf_setlen(buf2, 2);
1947+
strbuf_setlen(buf2, strlen(comment_line_str) + 1);
19481948
strbuf_addf(buf2, _(skip_nth_commit_msg_fmt), n);
19491949
strbuf_addch(buf2, '\n');
19501950
}
@@ -1963,8 +1963,12 @@ static void update_squash_message_for_fixup(struct strbuf *msg)
19631963
size_t orig_msg_len;
19641964
int i = 1;
19651965

1966-
strbuf_addf(&buf1, "# %s\n", _(first_commit_msg_str));
1967-
strbuf_addf(&buf2, "# %s\n", _(skip_first_commit_msg_str));
1966+
strbuf_add_commented_lines(&buf1, _(first_commit_msg_str),
1967+
strlen(_(first_commit_msg_str)),
1968+
comment_line_str);
1969+
strbuf_add_commented_lines(&buf2, _(skip_first_commit_msg_str),
1970+
strlen(_(skip_first_commit_msg_str)),
1971+
comment_line_str);
19681972
s = start = orig_msg = strbuf_detach(msg, &orig_msg_len);
19691973
while (s) {
19701974
const char *next;
@@ -2341,8 +2345,8 @@ static int do_pick_commit(struct repository *r,
23412345
next = parent;
23422346
next_label = msg.parent_label;
23432347
if (opts->commit_use_reference) {
2344-
strbuf_addstr(&ctx->message,
2345-
"# *** SAY WHY WE ARE REVERTING ON THE TITLE LINE ***");
2348+
strbuf_commented_addf(&ctx->message, comment_line_str,
2349+
"*** SAY WHY WE ARE REVERTING ON THE TITLE LINE ***");
23462350
} else if (skip_prefix(msg.subject, "Revert \"", &orig_subject) &&
23472351
/*
23482352
* We don't touch pre-existing repeated reverts, because
@@ -2352,12 +2356,13 @@ static int do_pick_commit(struct repository *r,
23522356
!starts_with(orig_subject, "Revert \"")) {
23532357
strbuf_addstr(&ctx->message, "Reapply \"");
23542358
strbuf_addstr(&ctx->message, orig_subject);
2359+
strbuf_addstr(&ctx->message, "\n");
23552360
} else {
23562361
strbuf_addstr(&ctx->message, "Revert \"");
23572362
strbuf_addstr(&ctx->message, msg.subject);
2358-
strbuf_addstr(&ctx->message, "\"");
2363+
strbuf_addstr(&ctx->message, "\"\n");
23592364
}
2360-
strbuf_addstr(&ctx->message, "\n\nThis reverts commit ");
2365+
strbuf_addstr(&ctx->message, "\nThis reverts commit ");
23612366
refer_to_commit(opts, &ctx->message, commit);
23622367

23632368
if (commit->parents && commit->parents->next) {
@@ -6382,8 +6387,9 @@ static int add_decorations_to_list(const struct commit *commit,
63826387
/* If the branch is checked out, then leave a comment instead. */
63836388
if ((path = branch_checked_out(decoration->name))) {
63846389
item->command = TODO_COMMENT;
6385-
strbuf_addf(ctx->buf, "# Ref %s checked out at '%s'\n",
6386-
decoration->name, path);
6390+
strbuf_commented_addf(ctx->buf, comment_line_str,
6391+
"Ref %s checked out at '%s'\n",
6392+
decoration->name, path);
63876393
} else {
63886394
struct string_list_item *sti;
63896395
item->command = TODO_UPDATE_REF;

t/t3400-rebase.sh

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

458+
test_expect_success 'git rebase --update-ref with core.commentChar and branch on worktree' '
459+
test_when_finished git branch -D base topic2 &&
460+
test_when_finished git checkout main &&
461+
test_when_finished git branch -D wt-topic &&
462+
test_when_finished git worktree remove wt-topic &&
463+
git checkout main &&
464+
git checkout -b base &&
465+
git checkout -b topic2 &&
466+
test_commit msg2 &&
467+
git worktree add wt-topic &&
468+
git checkout base &&
469+
test_commit msg3 &&
470+
git checkout topic2 &&
471+
GIT_SEQUENCE_EDITOR="cat >actual" git -c core.commentChar=% \
472+
rebase -i --update-refs base &&
473+
test_grep "% Ref refs/heads/wt-topic checked out at" actual &&
474+
test_grep "% Ref refs/heads/topic2 checked out at" actual
475+
'
476+
458477
test_done

t/t3437-rebase-fixup-options.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,21 @@ test_expect_success 'fixup -C with conflicts gives correct message' '
126126
test_cmp expected-author actual-author
127127
'
128128

129+
test_expect_success 'conflicting fixup -C after fixup with custom comment string' '
130+
test_config core.commentString COMMENT &&
131+
test_when_finished "test_might_fail git rebase --abort" &&
132+
git checkout --detach A3 &&
133+
test_must_fail env FAKE_LINES="1 fixup 2 fixup_-C 4" git rebase -i A &&
134+
echo resolved >A &&
135+
git add A &&
136+
FAKE_COMMIT_AMEND=edited git rebase --continue &&
137+
test_commit_message HEAD <<-\EOF
138+
A3
139+
140+
edited
141+
EOF
142+
'
143+
129144
test_expect_success 'skipping fixup -C after fixup gives correct message' '
130145
test_when_finished "test_might_fail git rebase --abort" &&
131146
git checkout --detach A3 &&

t/t3501-revert-cherry-pick.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,20 @@ test_expect_success 'identification of reverted commit (--reference)' '
227227
test_cmp expect actual
228228
'
229229

230+
test_expect_success 'git revert --reference with core.commentChar' '
231+
test_when_finished "git reset --hard to-ident" &&
232+
git checkout --detach to-ident &&
233+
GIT_EDITOR="head -n4 >actual" git -c core.commentChar=% revert \
234+
--edit --reference HEAD &&
235+
cat <<-EOF >expect &&
236+
% *** SAY WHY WE ARE REVERTING ON THE TITLE LINE ***
237+
238+
This reverts commit $(git show -s --pretty=reference HEAD^).
239+
240+
EOF
241+
test_cmp expect actual
242+
'
243+
230244
test_expect_success 'identification of reverted commit (revert.reference)' '
231245
git checkout --detach to-ident &&
232246
git -c revert.reference=true revert --no-edit HEAD &&

0 commit comments

Comments
 (0)