Skip to content

Commit f73604f

Browse files
committed
Merge branch 'ob/revert-of-revert-is-reapply'
The default log message created by "git revert", when reverting a commit that records a revert, has been tweaked. * ob/revert-of-revert-is-reapply: git-revert.txt: add discussion sequencer: beautify subject of reverts of reverts
2 parents 86b56ff + c9192f9 commit f73604f

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

Documentation/git-revert.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,16 @@ EXAMPLES
142142
changes. The revert only modifies the working tree and the
143143
index.
144144

145+
DISCUSSION
146+
----------
147+
148+
While git creates a basic commit message automatically, it is
149+
_strongly_ recommended to explain why the original commit is being
150+
reverted.
151+
In addition, repeatedly reverting reverts will result in increasingly
152+
unwieldy subject lines, for example 'Reapply "Reapply "<original subject>""'.
153+
Please consider rewording these to be shorter and more unique.
154+
145155
CONFIGURATION
146156
-------------
147157

sequencer.c

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

22592259
if (command == TODO_REVERT) {
2260+
const char *orig_subject;
2261+
22602262
base = commit;
22612263
base_label = msg.label;
22622264
next = parent;
22632265
next_label = msg.parent_label;
22642266
if (opts->commit_use_reference) {
22652267
strbuf_addstr(&msgbuf,
22662268
"# *** SAY WHY WE ARE REVERTING ON THE TITLE LINE ***");
2269+
} else if (skip_prefix(msg.subject, "Revert \"", &orig_subject) &&
2270+
/*
2271+
* We don't touch pre-existing repeated reverts, because
2272+
* theoretically these can be nested arbitrarily deeply,
2273+
* thus requiring excessive complexity to deal with.
2274+
*/
2275+
!starts_with(orig_subject, "Revert \"")) {
2276+
strbuf_addstr(&msgbuf, "Reapply \"");
2277+
strbuf_addstr(&msgbuf, orig_subject);
22672278
} else {
22682279
strbuf_addstr(&msgbuf, "Revert \"");
22692280
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)