Skip to content

Commit e69dd4d

Browse files
committed
Merge branch 'kh/sequencer-comment-char' into seen
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 497bdc1 + 63d2de6 commit e69dd4d

File tree

4 files changed

+59
-10
lines changed

4 files changed

+59
-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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,4 +456,20 @@ 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 -c core.commentChar=% rebase --update-refs base
473+
'
474+
459475
test_done

t/t3437-rebase-fixup-options.sh

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

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

t/t3501-revert-cherry-pick.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,18 @@ test_expect_success 'identification of reverted commit (--reference)' '
228228
test_cmp expect actual
229229
'
230230

231+
test_expect_success 'git revert --reference with core.commentChar' '
232+
test_when_finished "git reset --hard to-ident" &&
233+
git checkout --detach to-ident &&
234+
git -c core.commentChar=% revert \
235+
--edit --reference HEAD &&
236+
git log -1 --format=%B HEAD >actual &&
237+
printf "This reverts commit $(git show -s \
238+
--pretty=reference HEAD^).\n\n" \
239+
>expect &&
240+
test_cmp expect actual
241+
'
242+
231243
test_expect_success 'identification of reverted commit (revert.reference)' '
232244
git checkout --detach to-ident &&
233245
git -c revert.reference=true revert --no-edit HEAD &&

0 commit comments

Comments
 (0)