Skip to content

Commit 515d034

Browse files
LemmingAvalanchegitster
authored andcommitted
sequencer: comment --reference subject line properly
`git revert --reference <commit>` leaves behind a comment in the first line:[1] # *** SAY WHY WE ARE REVERTING ON THE TITLE LINE *** Meaning that the commit will just consist of the next line if the user exits the editor directly: This reverts commit <--format=reference commit> But the comment char here is hardcoded (#). Which means that the comment line will inadvertently be included in the commit message if `core.commentChar`/`core.commentString` is in use. † 1: See 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 94304b9 commit 515d034

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,20 @@ 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_EDITOR="head -n4 >actual" git -c core.commentChar=% revert \
235+
--edit --reference HEAD &&
236+
cat <<-EOF >expect &&
237+
% *** SAY WHY WE ARE REVERTING ON THE TITLE LINE ***
238+
239+
This reverts commit $(git show -s --pretty=reference HEAD^).
240+
241+
EOF
242+
test_cmp expect actual
243+
'
244+
231245
test_expect_success 'identification of reverted commit (revert.reference)' '
232246
git checkout --detach to-ident &&
233247
git -c revert.reference=true revert --no-edit HEAD &&

0 commit comments

Comments
 (0)