Skip to content

Commit 883cb1b

Browse files
ossilatorgitster
authored andcommitted
sequencer: beautify subject of reverts of reverts
Instead of generating a silly-looking `Revert "Revert "foo""`, make it a more humane `Reapply "foo"`. This is done for two reasons: - To cover the actually common case of just a double revert. - To encourage people to rewrite summaries of recursive reverts by setting an example (a subsequent commit will also do this explicitly in the documentation). To achieve these goals, the mechanism does not need to be particularly sophisticated. Therefore, more complicated alternatives which would "compress more efficiently" have not been implemented. Signed-off-by: Oswald Buddenhagen <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fac96df commit 883cb1b

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

sequencer.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2249,13 +2249,24 @@ static int do_pick_commit(struct repository *r,
22492249
*/
22502250

22512251
if (command == TODO_REVERT) {
2252+
const char *orig_subject;
2253+
22522254
base = commit;
22532255
base_label = msg.label;
22542256
next = parent;
22552257
next_label = msg.parent_label;
22562258
if (opts->commit_use_reference) {
22572259
strbuf_addstr(&msgbuf,
22582260
"# *** SAY WHY WE ARE REVERTING ON THE TITLE LINE ***");
2261+
} else if (skip_prefix(msg.subject, "Revert \"", &orig_subject) &&
2262+
/*
2263+
* We don't touch pre-existing repeated reverts, because
2264+
* theoretically these can be nested arbitrarily deeply,
2265+
* thus requiring excessive complexity to deal with.
2266+
*/
2267+
!starts_with(orig_subject, "Revert \"")) {
2268+
strbuf_addstr(&msgbuf, "Reapply \"");
2269+
strbuf_addstr(&msgbuf, orig_subject);
22592270
} else {
22602271
strbuf_addstr(&msgbuf, "Revert \"");
22612272
strbuf_addstr(&msgbuf, msg.subject);

t/t3501-revert-cherry-pick.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,29 @@ test_expect_success 'advice from failed revert' '
176176
test_cmp expected actual
177177
'
178178

179+
test_expect_subject () {
180+
echo "$1" >expect &&
181+
git log -1 --pretty=%s >actual &&
182+
test_cmp expect actual
183+
}
184+
185+
test_expect_success 'titles of fresh reverts' '
186+
test_commit --no-tag A file1 &&
187+
test_commit --no-tag B file1 &&
188+
git revert --no-edit HEAD &&
189+
test_expect_subject "Revert \"B\"" &&
190+
git revert --no-edit HEAD &&
191+
test_expect_subject "Reapply \"B\"" &&
192+
git revert --no-edit HEAD &&
193+
test_expect_subject "Revert \"Reapply \"B\"\""
194+
'
195+
196+
test_expect_success 'title of legacy double revert' '
197+
test_commit --no-tag "Revert \"Revert \"B\"\"" file1 &&
198+
git revert --no-edit HEAD &&
199+
test_expect_subject "Revert \"Revert \"Revert \"B\"\"\""
200+
'
201+
179202
test_expect_success 'identification of reverted commit (default)' '
180203
test_commit to-ident &&
181204
test_when_finished "git reset --hard to-ident" &&

0 commit comments

Comments
 (0)