Skip to content

Commit e001483

Browse files
LemmingAvalanchegitster
authored andcommitted
sequencer: comment --reference subject line properly
Comment the subject line used in `git cherry-pick --reference` properly. Follow the existing pattern and use the case described in the original commit message[1] as the `core.commentChar` test case: If the user exits the editor without touching this line by mistake, what we prepare to become the first line of the body, i.e. "This reverts commit 8fa7f667 (do this and that, 2022-04-25)", ends up to be the title of the resulting commit. † 1: 43966ab (revert: optionally refer to commit in the "reference" format, 2022-05-26) Signed-off-by: Kristoffer Haugsbakk <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 58dff9c commit e001483

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

sequencer.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,8 +2341,8 @@ static int do_pick_commit(struct repository *r,
23412341
next = parent;
23422342
next_label = msg.parent_label;
23432343
if (opts->commit_use_reference) {
2344-
strbuf_addstr(&ctx->message,
2345-
"# *** SAY WHY WE ARE REVERTING ON THE TITLE LINE ***");
2344+
strbuf_commented_addf(&ctx->message, comment_line_str,
2345+
"*** SAY WHY WE ARE REVERTING ON THE TITLE LINE ***");
23462346
} else if (skip_prefix(msg.subject, "Revert \"", &orig_subject) &&
23472347
/*
23482348
* We don't touch pre-existing repeated reverts, because
@@ -2352,12 +2352,13 @@ static int do_pick_commit(struct repository *r,
23522352
!starts_with(orig_subject, "Revert \"")) {
23532353
strbuf_addstr(&ctx->message, "Reapply \"");
23542354
strbuf_addstr(&ctx->message, orig_subject);
2355+
strbuf_addstr(&ctx->message, "\n");
23552356
} else {
23562357
strbuf_addstr(&ctx->message, "Revert \"");
23572358
strbuf_addstr(&ctx->message, msg.subject);
2358-
strbuf_addstr(&ctx->message, "\"");
2359+
strbuf_addstr(&ctx->message, "\"\n");
23592360
}
2360-
strbuf_addstr(&ctx->message, "\n\nThis reverts commit ");
2361+
strbuf_addstr(&ctx->message, "\nThis reverts commit ");
23612362
refer_to_commit(opts, &ctx->message, commit);
23622363

23632364
if (commit->parents && commit->parents->next) {

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)