1
0
mirror of https://github.com/git/git synced 2024-07-05 00:58:49 +00:00

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
This commit is contained in:
Junio C Hamano 2023-09-14 11:16:59 -07:00
commit f73604fabf
3 changed files with 44 additions and 0 deletions

View File

@ -142,6 +142,16 @@ EXAMPLES
changes. The revert only modifies the working tree and the
index.
DISCUSSION
----------
While git creates a basic commit message automatically, it is
_strongly_ recommended to explain why the original commit is being
reverted.
In addition, repeatedly reverting reverts will result in increasingly
unwieldy subject lines, for example 'Reapply "Reapply "<original subject>""'.
Please consider rewording these to be shorter and more unique.
CONFIGURATION
-------------

View File

@ -2257,6 +2257,8 @@ static int do_pick_commit(struct repository *r,
*/
if (command == TODO_REVERT) {
const char *orig_subject;
base = commit;
base_label = msg.label;
next = parent;
@ -2264,6 +2266,15 @@ static int do_pick_commit(struct repository *r,
if (opts->commit_use_reference) {
strbuf_addstr(&msgbuf,
"# *** SAY WHY WE ARE REVERTING ON THE TITLE LINE ***");
} else if (skip_prefix(msg.subject, "Revert \"", &orig_subject) &&
/*
* We don't touch pre-existing repeated reverts, because
* theoretically these can be nested arbitrarily deeply,
* thus requiring excessive complexity to deal with.
*/
!starts_with(orig_subject, "Revert \"")) {
strbuf_addstr(&msgbuf, "Reapply \"");
strbuf_addstr(&msgbuf, orig_subject);
} else {
strbuf_addstr(&msgbuf, "Revert \"");
strbuf_addstr(&msgbuf, msg.subject);

View File

@ -176,6 +176,29 @@ test_expect_success 'advice from failed revert' '
test_cmp expected actual
'
test_expect_subject () {
echo "$1" >expect &&
git log -1 --pretty=%s >actual &&
test_cmp expect actual
}
test_expect_success 'titles of fresh reverts' '
test_commit --no-tag A file1 &&
test_commit --no-tag B file1 &&
git revert --no-edit HEAD &&
test_expect_subject "Revert \"B\"" &&
git revert --no-edit HEAD &&
test_expect_subject "Reapply \"B\"" &&
git revert --no-edit HEAD &&
test_expect_subject "Revert \"Reapply \"B\"\""
'
test_expect_success 'title of legacy double revert' '
test_commit --no-tag "Revert \"Revert \"B\"\"" file1 &&
git revert --no-edit HEAD &&
test_expect_subject "Revert \"Revert \"Revert \"B\"\"\""
'
test_expect_success 'identification of reverted commit (default)' '
test_commit to-ident &&
test_when_finished "git reset --hard to-ident" &&