Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2023-09-14 21:16:59 +0300
committerJunio C Hamano <gitster@pobox.com>2023-09-14 21:16:59 +0300
commitf73604fabf7aa8bc294f346f6a610adb5a464e5e (patch)
treece46f57d0962e4da900de1fcd73b02c2e9255586
parent86b56ff267962ab91aa368b10d6df10b1e9e291e (diff)
parentc9192f9e45f12f7e4c93488eb77a3098e75a78cc (diff)
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
-rw-r--r--Documentation/git-revert.txt10
-rw-r--r--sequencer.c11
-rwxr-xr-xt/t3501-revert-cherry-pick.sh23
3 files changed, 44 insertions, 0 deletions
diff --git a/Documentation/git-revert.txt b/Documentation/git-revert.txt
index d2e10d3dce..cbe0208834 100644
--- a/Documentation/git-revert.txt
+++ b/Documentation/git-revert.txt
@@ -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
-------------
diff --git a/sequencer.c b/sequencer.c
index afebf7e37c..3c5fdd68f4 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -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);
diff --git a/t/t3501-revert-cherry-pick.sh b/t/t3501-revert-cherry-pick.sh
index e2ef619323..4158590322 100755
--- a/t/t3501-revert-cherry-pick.sh
+++ b/t/t3501-revert-cherry-pick.sh
@@ -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" &&