{"thread":{"id":"61909","subject":"[PATCH] t3206: test_when_finished before dirtying operations, not after","startedAt":"2024-08-06T00:55:16Z","lastAt":"2024-08-06T17:04:17Z","messageCount":4,"participants":["Junio C Hamano","Eric Sunshine"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"500144","messageId":"xmqqttfyzd01.fsf@gitster.g","threadId":"61909","inReplyTo":null,"subject":"[PATCH] t3206: test_when_finished before dirtying operations, not after","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-08-06T00:55:10Z","receivedAt":"2024-08-06T00:55:16Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Many existing tests in this script perform operation(s) and then use\ntest_when_finished to define how to undo the effect of the\noperation(s).\n\nThis is backwards.  When your operation(s) fail before you manage to\nsuccessfully call test_when_finished (remember, that these commands\nmust be all &&-chained, so a failure of an earlier operation mean\nyour test_when_finished may not be executed at all).  You must\nestablish how to clean up your mess with test_when_finished before\nyou create the mess to be cleaned up.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n\n * During a recent review of a topic, I noticed this file was\n   littered with issues, and marked it as leftoverbits to clean it\n   up after the dust settled.  The dust had settled, so it is a good\n   time to clean up.\n\n t/t3206-range-diff.sh | 52 +++++++++++++++++++++----------------------\n 1 file changed, 26 insertions(+), 26 deletions(-)\n\ndiff --git a/t/t3206-range-diff.sh b/t/t3206-range-diff.sh\nindex a767c3520e..d3bcd74236 100755\n--- a/t/t3206-range-diff.sh\n+++ b/t/t3206-range-diff.sh\n@@ -533,9 +533,9 @@ test_expect_success 'dual-coloring' '\n for prev in topic main..topic\n do\n \ttest_expect_success \"format-patch --range-diff=$prev\" '\n+\t\ttest_when_finished \"rm 000?-*\" &&\n \t\tgit format-patch --cover-letter --range-diff=$prev \\\n \t\t\tmain..unmodified >actual &&\n-\t\ttest_when_finished \"rm 000?-*\" &&\n \t\ttest_line_count = 5 actual &&\n \t\ttest_grep \"^Range-diff:$\" 0000-* &&\n \t\tgrep \"= 1: .* s/5/A\" 0000-* &&\n@@ -560,32 +560,32 @@ test_expect_success \"explicit --no-cover-letter defeats implied --cover-letter\"\n '\n \n test_expect_success 'format-patch --range-diff as commentary' '\n-\tgit format-patch --range-diff=HEAD~1 HEAD~1 >actual &&\n \ttest_when_finished \"rm 0001-*\" &&\n+\tgit format-patch --range-diff=HEAD~1 HEAD~1 >actual &&\n \ttest_line_count = 1 actual &&\n \ttest_grep \"^Range-diff:$\" 0001-* &&\n \tgrep \"> 1: .* new message\" 0001-*\n '\n \n test_expect_success 'format-patch --range-diff reroll-count with a non-integer' '\n-\tgit format-patch --range-diff=HEAD~1 -v2.9 HEAD~1 >actual &&\n \ttest_when_finished \"rm v2.9-0001-*\" &&\n+\tgit format-patch --range-diff=HEAD~1 -v2.9 HEAD~1 >actual &&\n \ttest_line_count = 1 actual &&\n \ttest_grep \"^Range-diff:$\" v2.9-0001-* &&\n \tgrep \"> 1: .* new message\" v2.9-0001-*\n '\n \n test_expect_success 'format-patch --range-diff reroll-count with a integer' '\n-\tgit format-patch --range-diff=HEAD~1 -v2 HEAD~1 >actual &&\n \ttest_when_finished \"rm v2-0001-*\" &&\n+\tgit format-patch --range-diff=HEAD~1 -v2 HEAD~1 >actual &&\n \ttest_line_count = 1 actual &&\n \ttest_grep \"^Range-diff ..* v1:$\" v2-0001-* &&\n \tgrep \"> 1: .* new message\" v2-0001-*\n '\n \n test_expect_success 'format-patch --range-diff with v0' '\n-\tgit format-patch --range-diff=HEAD~1 -v0 HEAD~1 >actual &&\n \ttest_when_finished \"rm v0-0001-*\" &&\n+\tgit format-patch --range-diff=HEAD~1 -v0 HEAD~1 >actual &&\n \ttest_line_count = 1 actual &&\n \ttest_grep \"^Range-diff:$\" v0-0001-* &&\n \tgrep \"> 1: .* new message\" v0-0001-*\n@@ -606,9 +606,9 @@ test_expect_success 'basic with modified format.pretty without \"commit \"' '\n '\n \n test_expect_success 'range-diff compares notes by default' '\n+\ttest_when_finished git notes remove topic unmodified &&\n \tgit notes add -m \"topic note\" topic &&\n \tgit notes add -m \"unmodified note\" unmodified &&\n-\ttest_when_finished git notes remove topic unmodified &&\n \tgit range-diff --no-color main..topic main..unmodified \\\n \t\t>actual &&\n \tsed s/Z/\\ /g >expect <<-EOF &&\n@@ -630,9 +630,9 @@ test_expect_success 'range-diff compares notes by default' '\n '\n \n test_expect_success 'range-diff with --no-notes' '\n+\ttest_when_finished git notes remove topic unmodified &&\n \tgit notes add -m \"topic note\" topic &&\n \tgit notes add -m \"unmodified note\" unmodified &&\n-\ttest_when_finished git notes remove topic unmodified &&\n \tgit range-diff --no-color --no-notes main..topic main..unmodified \\\n \t\t>actual &&\n \tcat >expect <<-EOF &&\n@@ -645,12 +645,12 @@ test_expect_success 'range-diff with --no-notes' '\n '\n \n test_expect_success 'range-diff with multiple --notes' '\n+\ttest_when_finished git notes --ref=note1 remove topic unmodified &&\n \tgit notes --ref=note1 add -m \"topic note1\" topic &&\n \tgit notes --ref=note1 add -m \"unmodified note1\" unmodified &&\n-\ttest_when_finished git notes --ref=note1 remove topic unmodified &&\n+\ttest_when_finished git notes --ref=note2 remove topic unmodified &&\n \tgit notes --ref=note2 add -m \"topic note2\" topic &&\n \tgit notes --ref=note2 add -m \"unmodified note2\" unmodified &&\n-\ttest_when_finished git notes --ref=note2 remove topic unmodified &&\n \tgit range-diff --no-color --notes=note1 --notes=note2 main..topic main..unmodified \\\n \t\t>actual &&\n \tsed s/Z/\\ /g >expect <<-EOF &&\n@@ -678,12 +678,12 @@ test_expect_success 'range-diff with multiple --notes' '\n \n # `range-diff` should act like `log` with regards to notes\n test_expect_success 'range-diff with --notes=custom does not show default notes' '\n+\ttest_when_finished git notes remove topic unmodified &&\n \tgit notes add -m \"topic note\" topic &&\n \tgit notes add -m \"unmodified note\" unmodified &&\n+\ttest_when_finished git notes --ref=custom remove topic unmodified &&\n \tgit notes --ref=custom add -m \"topic note\" topic &&\n \tgit notes --ref=custom add -m \"unmodified note\" unmodified &&\n-\ttest_when_finished git notes remove topic unmodified &&\n-\ttest_when_finished git notes --ref=custom remove topic unmodified &&\n \tgit range-diff --notes=custom main..topic main..unmodified \\\n \t\t>actual &&\n \t! grep \"## Notes ##\" actual &&\n@@ -691,12 +691,12 @@ test_expect_success 'range-diff with --notes=custom does not show default notes'\n '\n \n test_expect_success 'format-patch --range-diff does not compare notes by default' '\n+\ttest_when_finished git notes remove topic unmodified &&\n \tgit notes add -m \"topic note\" topic &&\n \tgit notes add -m \"unmodified note\" unmodified &&\n-\ttest_when_finished git notes remove topic unmodified &&\n+\ttest_when_finished \"rm 000?-*\" &&\n \tgit format-patch --cover-letter --range-diff=$prev \\\n \t\tmain..unmodified >actual &&\n-\ttest_when_finished \"rm 000?-*\" &&\n \ttest_line_count = 5 actual &&\n \ttest_grep \"^Range-diff:$\" 0000-* &&\n \tgrep \"= 1: .* s/5/A\" 0000-* &&\n@@ -708,26 +708,26 @@ test_expect_success 'format-patch --range-diff does not compare notes by default\n '\n \n test_expect_success 'format-patch --notes=custom --range-diff only compares custom notes' '\n+\ttest_when_finished git notes remove topic unmodified &&\n \tgit notes add -m \"topic note\" topic &&\n-\tgit notes --ref=custom add -m \"topic note (custom)\" topic &&\n \tgit notes add -m \"unmodified note\" unmodified &&\n-\tgit notes --ref=custom add -m \"unmodified note (custom)\" unmodified &&\n-\ttest_when_finished git notes remove topic unmodified &&\n \ttest_when_finished git notes --ref=custom remove topic unmodified &&\n+\tgit notes --ref=custom add -m \"topic note (custom)\" topic &&\n+\tgit notes --ref=custom add -m \"unmodified note (custom)\" unmodified &&\n+\ttest_when_finished \"rm 000?-*\" &&\n \tgit format-patch --notes=custom --cover-letter --range-diff=$prev \\\n \t\tmain..unmodified >actual &&\n-\ttest_when_finished \"rm 000?-*\" &&\n \tgrep \"## Notes (custom) ##\" 0000-* &&\n \t! grep \"## Notes ##\" 0000-*\n '\n \n test_expect_success 'format-patch --range-diff with --no-notes' '\n+\ttest_when_finished git notes remove topic unmodified &&\n \tgit notes add -m \"topic note\" topic &&\n \tgit notes add -m \"unmodified note\" unmodified &&\n-\ttest_when_finished git notes remove topic unmodified &&\n+\ttest_when_finished \"rm 000?-*\" &&\n \tgit format-patch --no-notes --cover-letter --range-diff=$prev \\\n \t\tmain..unmodified >actual &&\n-\ttest_when_finished \"rm 000?-*\" &&\n \ttest_line_count = 5 actual &&\n \ttest_grep \"^Range-diff:$\" 0000-* &&\n \tgrep \"= 1: .* s/5/A\" 0000-* &&\n@@ -739,12 +739,12 @@ test_expect_success 'format-patch --range-diff with --no-notes' '\n '\n \n test_expect_success 'format-patch --range-diff with --notes' '\n+\ttest_when_finished git notes remove topic unmodified &&\n \tgit notes add -m \"topic note\" topic &&\n \tgit notes add -m \"unmodified note\" unmodified &&\n-\ttest_when_finished git notes remove topic unmodified &&\n+\ttest_when_finished \"rm 000?-*\" &&\n \tgit format-patch --notes --cover-letter --range-diff=$prev \\\n \t\tmain..unmodified >actual &&\n-\ttest_when_finished \"rm 000?-*\" &&\n \ttest_line_count = 5 actual &&\n \ttest_grep \"^Range-diff:$\" 0000-* &&\n \tgrep \"= 1: .* s/5/A\" 0000-* &&\n@@ -767,13 +767,13 @@ test_expect_success 'format-patch --range-diff with --notes' '\n '\n \n test_expect_success 'format-patch --range-diff with format.notes config' '\n+\ttest_when_finished git notes remove topic unmodified &&\n \tgit notes add -m \"topic note\" topic &&\n \tgit notes add -m \"unmodified note\" unmodified &&\n-\ttest_when_finished git notes remove topic unmodified &&\n \ttest_config format.notes true &&\n+\ttest_when_finished \"rm 000?-*\" &&\n \tgit format-patch --cover-letter --range-diff=$prev \\\n \t\tmain..unmodified >actual &&\n-\ttest_when_finished \"rm 000?-*\" &&\n \ttest_line_count = 5 actual &&\n \ttest_grep \"^Range-diff:$\" 0000-* &&\n \tgrep \"= 1: .* s/5/A\" 0000-* &&\n@@ -796,15 +796,15 @@ test_expect_success 'format-patch --range-diff with format.notes config' '\n '\n \n test_expect_success 'format-patch --range-diff with multiple notes' '\n+\ttest_when_finished git notes --ref=note1 remove topic unmodified &&\n \tgit notes --ref=note1 add -m \"topic note1\" topic &&\n \tgit notes --ref=note1 add -m \"unmodified note1\" unmodified &&\n-\ttest_when_finished git notes --ref=note1 remove topic unmodified &&\n+\ttest_when_finished git notes --ref=note2 remove topic unmodified &&\n \tgit notes --ref=note2 add -m \"topic note2\" topic &&\n \tgit notes --ref=note2 add -m \"unmodified note2\" unmodified &&\n-\ttest_when_finished git notes --ref=note2 remove topic unmodified &&\n+\ttest_when_finished \"rm 000?-*\" &&\n \tgit format-patch --notes=note1 --notes=note2 --cover-letter --range-diff=$prev \\\n \t\tmain..unmodified >actual &&\n-\ttest_when_finished \"rm 000?-*\" &&\n \ttest_line_count = 5 actual &&\n \ttest_grep \"^Range-diff:$\" 0000-* &&\n \tgrep \"= 1: .* s/5/A\" 0000-* &&\n-- \n2.46.0-235-g968ce1ce0e\n\n"},{"id":"500145","messageId":"CAPig+cRO=BqR1WFcni6CSxqyqvt1Ksmsyr0odmqTDKX4JdbDaA@mail.gmail.com","threadId":"61909","inReplyTo":"xmqqttfyzd01.fsf@gitster.g","subject":"Re: [PATCH] t3206: test_when_finished before dirtying operations, not after","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2024-08-06T02:21:59Z","receivedAt":"2024-08-06T02:22:11Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Mon, Aug 5, 2024 at 8:55 PM Junio C Hamano <gitster@pobox.com> wrote:\n> Many existing tests in this script perform operation(s) and then use\n> test_when_finished to define how to undo the effect of the\n> operation(s).\n>\n> This is backwards.  When your operation(s) fail before you manage to\n> successfully call test_when_finished (remember, that these commands\n> must be all &&-chained, so a failure of an earlier operation mean\n> your test_when_finished may not be executed at all).  You must\n> establish how to clean up your mess with test_when_finished before\n> you create the mess to be cleaned up.\n>\n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n> ---\n>  t/t3206-range-diff.sh | 52 +++++++++++++++++++++----------------------\n> diff --git a/t/t3206-range-diff.sh b/t/t3206-range-diff.sh\n> @@ -533,9 +533,9 @@ test_expect_success 'dual-coloring' '\n>  for prev in topic main..topic\n>  do\n>         test_expect_success \"format-patch --range-diff=$prev\" '\n> +               test_when_finished \"rm 000?-*\" &&\n>                 git format-patch --cover-letter --range-diff=$prev \\\n>                         main..unmodified >actual &&\n> -               test_when_finished \"rm 000?-*\" &&\n\nDo we care whether the action invoked by `test_when_finished` itself\nsucceeds or fails? In particular, should this be using `rm -f` rather\nthan `rm`?\n\n    test_when_finished \"rm -f 000?-*\" &&\n\n> @@ -606,9 +606,9 @@ test_expect_success 'basic with modified format.pretty without \"commit \"' '\n>  test_expect_success 'range-diff compares notes by default' '\n> +       test_when_finished git notes remove topic unmodified &&\n>         git notes add -m \"topic note\" topic &&\n>         git notes add -m \"unmodified note\" unmodified &&\n> -       test_when_finished git notes remove topic unmodified &&\n\nSimilarly, should this be using `|| :`?\n\n    test_when_finished \"git notes remove topic unmodified || :\" &&\n"},{"id":"500236","messageId":"xmqq4j7xvbiv.fsf@gitster.g","threadId":"61909","inReplyTo":"CAPig+cRO=BqR1WFcni6CSxqyqvt1Ksmsyr0odmqTDKX4JdbDaA@mail.gmail.com","subject":"Re: [PATCH] t3206: test_when_finished before dirtying operations, not after","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-08-06T16:52:56Z","receivedAt":"2024-08-06T16:53:02Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Eric Sunshine <sunshine@sunshineco.com> writes:\n\n> On Mon, Aug 5, 2024 at 8:55 PM Junio C Hamano <gitster@pobox.com> wrote:\n>> Many existing tests in this script perform operation(s) and then use\n>> test_when_finished to define how to undo the effect of the\n>> operation(s).\n>>\n>> This is backwards.  When your operation(s) fail before you manage to\n>> successfully call test_when_finished (remember, that these commands\n>> must be all &&-chained, so a failure of an earlier operation mean\n>> your test_when_finished may not be executed at all).  You must\n>> establish how to clean up your mess with test_when_finished before\n>> you create the mess to be cleaned up.\n>>\n>> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n>> ---\n>>  t/t3206-range-diff.sh | 52 +++++++++++++++++++++----------------------\n>> diff --git a/t/t3206-range-diff.sh b/t/t3206-range-diff.sh\n>> @@ -533,9 +533,9 @@ test_expect_success 'dual-coloring' '\n>>  for prev in topic main..topic\n>>  do\n>>         test_expect_success \"format-patch --range-diff=$prev\" '\n>> +               test_when_finished \"rm 000?-*\" &&\n>>                 git format-patch --cover-letter --range-diff=$prev \\\n>>                         main..unmodified >actual &&\n>> -               test_when_finished \"rm 000?-*\" &&\n>\n> Do we care whether the action invoked by `test_when_finished` itself\n> succeeds or fails? In particular, should this be using `rm -f` rather\n> than `rm`?\n\nThanks for good eyes.  The original avoids that issue by making sure\nit only installs the clean-up after the operation to create crufts\nsuccessfully completes ;-)  Of course, if it fails in the middle,\nthen the crufts are left behind X-<.\n\n>> @@ -606,9 +606,9 @@ test_expect_success 'basic with modified format.pretty without \"commit \"' '\n>>  test_expect_success 'range-diff compares notes by default' '\n>> +       test_when_finished git notes remove topic unmodified &&\n>>         git notes add -m \"topic note\" topic &&\n>>         git notes add -m \"unmodified note\" unmodified &&\n>> -       test_when_finished git notes remove topic unmodified &&\n>\n> Similarly, should this be using `|| :`?\n\nAh, I forgot that \"notes remove\" would barf when there is no note to\nremove, instead of being idempotent no-op.  Yes, you'd need ||: there.\n\n>     test_when_finished \"git notes remove topic unmodified || :\" &&\n"},{"id":"500237","messageId":"xmqqwmkttwfm.fsf@gitster.g","threadId":"61909","inReplyTo":"xmqqttfyzd01.fsf@gitster.g","subject":"[PATCH v2] t3206: test_when_finished before dirtying operations, not after","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-08-06T17:04:13Z","receivedAt":"2024-08-06T17:04:17Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Many existing tests in this script perform operation(s) and then use\ntest_when_finished to define how to undo the effect of the\noperation(s).\n\nThis is backwards.  When your operation(s) fail before you manage to\nsuccessfully call test_when_finished (remember, that these commands\nmust be all &&-chained, so a failure of an earlier operation mean\nyour test_when_finished may not be executed at all).  You must\nestablish how to clean up your mess with test_when_finished before\nyou create the mess to be cleaned up.\n\nAlso make sure that the body of test_when_finished deals with case\nwhere the cruft it wants to remove failed to be created, by using\n\"rm -f\" (instead of \"rm\") to remove potential cruft files, and\nhaving \"|| :\" after \"git notes remove\" to remove potential cruft\nnotes---both of these by default fail when asked to remove something\nthat does not exist, instead of being silently idempotent no-ops.\n\nHelped-by: Eric Sunshine <sunshine@sunshineco.com>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n * a range-diff appears at the end.  The last paragraph of the\n   proposed log message is new, and the differences in patch text\n   are about making sure test_when_finished commands are prepared\n   for their body failing.\n\n t/t3206-range-diff.sh | 52 +++++++++++++++++++++----------------------\n 1 file changed, 26 insertions(+), 26 deletions(-)\n\ndiff --git a/t/t3206-range-diff.sh b/t/t3206-range-diff.sh\nindex a767c3520e..d2ca43d6aa 100755\n--- a/t/t3206-range-diff.sh\n+++ b/t/t3206-range-diff.sh\n@@ -533,9 +533,9 @@ test_expect_success 'dual-coloring' '\n for prev in topic main..topic\n do\n \ttest_expect_success \"format-patch --range-diff=$prev\" '\n+\t\ttest_when_finished \"rm -f 000?-*\" &&\n \t\tgit format-patch --cover-letter --range-diff=$prev \\\n \t\t\tmain..unmodified >actual &&\n-\t\ttest_when_finished \"rm 000?-*\" &&\n \t\ttest_line_count = 5 actual &&\n \t\ttest_grep \"^Range-diff:$\" 0000-* &&\n \t\tgrep \"= 1: .* s/5/A\" 0000-* &&\n@@ -560,32 +560,32 @@ test_expect_success \"explicit --no-cover-letter defeats implied --cover-letter\"\n '\n \n test_expect_success 'format-patch --range-diff as commentary' '\n+\ttest_when_finished \"rm -f 0001-*\" &&\n \tgit format-patch --range-diff=HEAD~1 HEAD~1 >actual &&\n-\ttest_when_finished \"rm 0001-*\" &&\n \ttest_line_count = 1 actual &&\n \ttest_grep \"^Range-diff:$\" 0001-* &&\n \tgrep \"> 1: .* new message\" 0001-*\n '\n \n test_expect_success 'format-patch --range-diff reroll-count with a non-integer' '\n+\ttest_when_finished \"rm -f v2.9-0001-*\" &&\n \tgit format-patch --range-diff=HEAD~1 -v2.9 HEAD~1 >actual &&\n-\ttest_when_finished \"rm v2.9-0001-*\" &&\n \ttest_line_count = 1 actual &&\n \ttest_grep \"^Range-diff:$\" v2.9-0001-* &&\n \tgrep \"> 1: .* new message\" v2.9-0001-*\n '\n \n test_expect_success 'format-patch --range-diff reroll-count with a integer' '\n+\ttest_when_finished \"rm -f v2-0001-*\" &&\n \tgit format-patch --range-diff=HEAD~1 -v2 HEAD~1 >actual &&\n-\ttest_when_finished \"rm v2-0001-*\" &&\n \ttest_line_count = 1 actual &&\n \ttest_grep \"^Range-diff ..* v1:$\" v2-0001-* &&\n \tgrep \"> 1: .* new message\" v2-0001-*\n '\n \n test_expect_success 'format-patch --range-diff with v0' '\n+\ttest_when_finished \"rm -f v0-0001-*\" &&\n \tgit format-patch --range-diff=HEAD~1 -v0 HEAD~1 >actual &&\n-\ttest_when_finished \"rm v0-0001-*\" &&\n \ttest_line_count = 1 actual &&\n \ttest_grep \"^Range-diff:$\" v0-0001-* &&\n \tgrep \"> 1: .* new message\" v0-0001-*\n@@ -606,9 +606,9 @@ test_expect_success 'basic with modified format.pretty without \"commit \"' '\n '\n \n test_expect_success 'range-diff compares notes by default' '\n+\ttest_when_finished \"git notes remove topic unmodified || :\" &&\n \tgit notes add -m \"topic note\" topic &&\n \tgit notes add -m \"unmodified note\" unmodified &&\n-\ttest_when_finished git notes remove topic unmodified &&\n \tgit range-diff --no-color main..topic main..unmodified \\\n \t\t>actual &&\n \tsed s/Z/\\ /g >expect <<-EOF &&\n@@ -630,9 +630,9 @@ test_expect_success 'range-diff compares notes by default' '\n '\n \n test_expect_success 'range-diff with --no-notes' '\n+\ttest_when_finished \"git notes remove topic unmodified || :\" &&\n \tgit notes add -m \"topic note\" topic &&\n \tgit notes add -m \"unmodified note\" unmodified &&\n-\ttest_when_finished git notes remove topic unmodified &&\n \tgit range-diff --no-color --no-notes main..topic main..unmodified \\\n \t\t>actual &&\n \tcat >expect <<-EOF &&\n@@ -645,12 +645,12 @@ test_expect_success 'range-diff with --no-notes' '\n '\n \n test_expect_success 'range-diff with multiple --notes' '\n+\ttest_when_finished \"git notes --ref=note1 remove topic unmodified || :\" &&\n \tgit notes --ref=note1 add -m \"topic note1\" topic &&\n \tgit notes --ref=note1 add -m \"unmodified note1\" unmodified &&\n-\ttest_when_finished git notes --ref=note1 remove topic unmodified &&\n+\ttest_when_finished \"git notes --ref=note2 remove topic unmodified || :\" &&\n \tgit notes --ref=note2 add -m \"topic note2\" topic &&\n \tgit notes --ref=note2 add -m \"unmodified note2\" unmodified &&\n-\ttest_when_finished git notes --ref=note2 remove topic unmodified &&\n \tgit range-diff --no-color --notes=note1 --notes=note2 main..topic main..unmodified \\\n \t\t>actual &&\n \tsed s/Z/\\ /g >expect <<-EOF &&\n@@ -678,12 +678,12 @@ test_expect_success 'range-diff with multiple --notes' '\n \n # `range-diff` should act like `log` with regards to notes\n test_expect_success 'range-diff with --notes=custom does not show default notes' '\n+\ttest_when_finished \"git notes remove topic unmodified || :\" &&\n \tgit notes add -m \"topic note\" topic &&\n \tgit notes add -m \"unmodified note\" unmodified &&\n+\ttest_when_finished \"git notes --ref=custom remove topic unmodified || :\" &&\n \tgit notes --ref=custom add -m \"topic note\" topic &&\n \tgit notes --ref=custom add -m \"unmodified note\" unmodified &&\n-\ttest_when_finished git notes remove topic unmodified &&\n-\ttest_when_finished git notes --ref=custom remove topic unmodified &&\n \tgit range-diff --notes=custom main..topic main..unmodified \\\n \t\t>actual &&\n \t! grep \"## Notes ##\" actual &&\n@@ -691,12 +691,12 @@ test_expect_success 'range-diff with --notes=custom does not show default notes'\n '\n \n test_expect_success 'format-patch --range-diff does not compare notes by default' '\n+\ttest_when_finished \"git notes remove topic unmodified || :\" &&\n \tgit notes add -m \"topic note\" topic &&\n \tgit notes add -m \"unmodified note\" unmodified &&\n-\ttest_when_finished git notes remove topic unmodified &&\n+\ttest_when_finished \"rm -f 000?-*\" &&\n \tgit format-patch --cover-letter --range-diff=$prev \\\n \t\tmain..unmodified >actual &&\n-\ttest_when_finished \"rm 000?-*\" &&\n \ttest_line_count = 5 actual &&\n \ttest_grep \"^Range-diff:$\" 0000-* &&\n \tgrep \"= 1: .* s/5/A\" 0000-* &&\n@@ -708,26 +708,26 @@ test_expect_success 'format-patch --range-diff does not compare notes by default\n '\n \n test_expect_success 'format-patch --notes=custom --range-diff only compares custom notes' '\n+\ttest_when_finished \"git notes remove topic unmodified || :\" &&\n \tgit notes add -m \"topic note\" topic &&\n-\tgit notes --ref=custom add -m \"topic note (custom)\" topic &&\n \tgit notes add -m \"unmodified note\" unmodified &&\n+\ttest_when_finished \"git notes --ref=custom remove topic unmodified || :\" &&\n+\tgit notes --ref=custom add -m \"topic note (custom)\" topic &&\n \tgit notes --ref=custom add -m \"unmodified note (custom)\" unmodified &&\n-\ttest_when_finished git notes remove topic unmodified &&\n-\ttest_when_finished git notes --ref=custom remove topic unmodified &&\n+\ttest_when_finished \"rm -f 000?-*\" &&\n \tgit format-patch --notes=custom --cover-letter --range-diff=$prev \\\n \t\tmain..unmodified >actual &&\n-\ttest_when_finished \"rm 000?-*\" &&\n \tgrep \"## Notes (custom) ##\" 0000-* &&\n \t! grep \"## Notes ##\" 0000-*\n '\n \n test_expect_success 'format-patch --range-diff with --no-notes' '\n+\ttest_when_finished \"git notes remove topic unmodified || :\" &&\n \tgit notes add -m \"topic note\" topic &&\n \tgit notes add -m \"unmodified note\" unmodified &&\n-\ttest_when_finished git notes remove topic unmodified &&\n+\ttest_when_finished \"rm -f 000?-*\" &&\n \tgit format-patch --no-notes --cover-letter --range-diff=$prev \\\n \t\tmain..unmodified >actual &&\n-\ttest_when_finished \"rm 000?-*\" &&\n \ttest_line_count = 5 actual &&\n \ttest_grep \"^Range-diff:$\" 0000-* &&\n \tgrep \"= 1: .* s/5/A\" 0000-* &&\n@@ -739,12 +739,12 @@ test_expect_success 'format-patch --range-diff with --no-notes' '\n '\n \n test_expect_success 'format-patch --range-diff with --notes' '\n+\ttest_when_finished \"git notes remove topic unmodified || :\" &&\n \tgit notes add -m \"topic note\" topic &&\n \tgit notes add -m \"unmodified note\" unmodified &&\n-\ttest_when_finished git notes remove topic unmodified &&\n+\ttest_when_finished \"rm -f 000?-*\" &&\n \tgit format-patch --notes --cover-letter --range-diff=$prev \\\n \t\tmain..unmodified >actual &&\n-\ttest_when_finished \"rm 000?-*\" &&\n \ttest_line_count = 5 actual &&\n \ttest_grep \"^Range-diff:$\" 0000-* &&\n \tgrep \"= 1: .* s/5/A\" 0000-* &&\n@@ -767,13 +767,13 @@ test_expect_success 'format-patch --range-diff with --notes' '\n '\n \n test_expect_success 'format-patch --range-diff with format.notes config' '\n+\ttest_when_finished \"git notes remove topic unmodified || :\" &&\n \tgit notes add -m \"topic note\" topic &&\n \tgit notes add -m \"unmodified note\" unmodified &&\n-\ttest_when_finished git notes remove topic unmodified &&\n \ttest_config format.notes true &&\n+\ttest_when_finished \"rm -f 000?-*\" &&\n \tgit format-patch --cover-letter --range-diff=$prev \\\n \t\tmain..unmodified >actual &&\n-\ttest_when_finished \"rm 000?-*\" &&\n \ttest_line_count = 5 actual &&\n \ttest_grep \"^Range-diff:$\" 0000-* &&\n \tgrep \"= 1: .* s/5/A\" 0000-* &&\n@@ -796,15 +796,15 @@ test_expect_success 'format-patch --range-diff with format.notes config' '\n '\n \n test_expect_success 'format-patch --range-diff with multiple notes' '\n+\ttest_when_finished \"git notes --ref=note1 remove topic unmodified || :\" &&\n \tgit notes --ref=note1 add -m \"topic note1\" topic &&\n \tgit notes --ref=note1 add -m \"unmodified note1\" unmodified &&\n-\ttest_when_finished git notes --ref=note1 remove topic unmodified &&\n+\ttest_when_finished \"git notes --ref=note2 remove topic unmodified || :\" &&\n \tgit notes --ref=note2 add -m \"topic note2\" topic &&\n \tgit notes --ref=note2 add -m \"unmodified note2\" unmodified &&\n-\ttest_when_finished git notes --ref=note2 remove topic unmodified &&\n+\ttest_when_finished \"rm -f 000?-*\" &&\n \tgit format-patch --notes=note1 --notes=note2 --cover-letter --range-diff=$prev \\\n \t\tmain..unmodified >actual &&\n-\ttest_when_finished \"rm 000?-*\" &&\n \ttest_line_count = 5 actual &&\n \ttest_grep \"^Range-diff:$\" 0000-* &&\n \tgrep \"= 1: .* s/5/A\" 0000-* &&\n\nRange-diff:\n1:  591c4d512f ! 1:  3a3c1a1a44 t3206: test_when_finished before dirtying operations, not after\n    @@ Commit message\n         establish how to clean up your mess with test_when_finished before\n         you create the mess to be cleaned up.\n     \n    +    Also make sure that the body of test_when_finished deals with case\n    +    where the cruft it wants to remove failed to be created, by using\n    +    \"rm -f\" (instead of \"rm\") to remove potential cruft files, and\n    +    having \"|| :\" after \"git notes remove\" to remove potential cruft\n    +    notes---both of these by default fail when asked to remove something\n    +    that does not exist, instead of being silently idempotent no-ops.\n    +\n    +    Helped-by: Eric Sunshine <sunshine@sunshineco.com>\n         Signed-off-by: Junio C Hamano <gitster@pobox.com>\n     \n      ## t/t3206-range-diff.sh ##\n    @@ t/t3206-range-diff.sh: test_expect_success 'dual-coloring' '\n      for prev in topic main..topic\n      do\n      \ttest_expect_success \"format-patch --range-diff=$prev\" '\n    -+\t\ttest_when_finished \"rm 000?-*\" &&\n    ++\t\ttest_when_finished \"rm -f 000?-*\" &&\n      \t\tgit format-patch --cover-letter --range-diff=$prev \\\n      \t\t\tmain..unmodified >actual &&\n     -\t\ttest_when_finished \"rm 000?-*\" &&\n    @@ t/t3206-range-diff.sh: test_expect_success \"explicit --no-cover-letter defeats i\n      '\n      \n      test_expect_success 'format-patch --range-diff as commentary' '\n    --\tgit format-patch --range-diff=HEAD~1 HEAD~1 >actual &&\n    - \ttest_when_finished \"rm 0001-*\" &&\n    -+\tgit format-patch --range-diff=HEAD~1 HEAD~1 >actual &&\n    ++\ttest_when_finished \"rm -f 0001-*\" &&\n    + \tgit format-patch --range-diff=HEAD~1 HEAD~1 >actual &&\n    +-\ttest_when_finished \"rm 0001-*\" &&\n      \ttest_line_count = 1 actual &&\n      \ttest_grep \"^Range-diff:$\" 0001-* &&\n      \tgrep \"> 1: .* new message\" 0001-*\n      '\n      \n      test_expect_success 'format-patch --range-diff reroll-count with a non-integer' '\n    --\tgit format-patch --range-diff=HEAD~1 -v2.9 HEAD~1 >actual &&\n    - \ttest_when_finished \"rm v2.9-0001-*\" &&\n    -+\tgit format-patch --range-diff=HEAD~1 -v2.9 HEAD~1 >actual &&\n    ++\ttest_when_finished \"rm -f v2.9-0001-*\" &&\n    + \tgit format-patch --range-diff=HEAD~1 -v2.9 HEAD~1 >actual &&\n    +-\ttest_when_finished \"rm v2.9-0001-*\" &&\n      \ttest_line_count = 1 actual &&\n      \ttest_grep \"^Range-diff:$\" v2.9-0001-* &&\n      \tgrep \"> 1: .* new message\" v2.9-0001-*\n      '\n      \n      test_expect_success 'format-patch --range-diff reroll-count with a integer' '\n    --\tgit format-patch --range-diff=HEAD~1 -v2 HEAD~1 >actual &&\n    - \ttest_when_finished \"rm v2-0001-*\" &&\n    -+\tgit format-patch --range-diff=HEAD~1 -v2 HEAD~1 >actual &&\n    ++\ttest_when_finished \"rm -f v2-0001-*\" &&\n    + \tgit format-patch --range-diff=HEAD~1 -v2 HEAD~1 >actual &&\n    +-\ttest_when_finished \"rm v2-0001-*\" &&\n      \ttest_line_count = 1 actual &&\n      \ttest_grep \"^Range-diff ..* v1:$\" v2-0001-* &&\n      \tgrep \"> 1: .* new message\" v2-0001-*\n      '\n      \n      test_expect_success 'format-patch --range-diff with v0' '\n    --\tgit format-patch --range-diff=HEAD~1 -v0 HEAD~1 >actual &&\n    - \ttest_when_finished \"rm v0-0001-*\" &&\n    -+\tgit format-patch --range-diff=HEAD~1 -v0 HEAD~1 >actual &&\n    ++\ttest_when_finished \"rm -f v0-0001-*\" &&\n    + \tgit format-patch --range-diff=HEAD~1 -v0 HEAD~1 >actual &&\n    +-\ttest_when_finished \"rm v0-0001-*\" &&\n      \ttest_line_count = 1 actual &&\n      \ttest_grep \"^Range-diff:$\" v0-0001-* &&\n      \tgrep \"> 1: .* new message\" v0-0001-*\n    @@ t/t3206-range-diff.sh: test_expect_success 'basic with modified format.pretty wi\n      '\n      \n      test_expect_success 'range-diff compares notes by default' '\n    -+\ttest_when_finished git notes remove topic unmodified &&\n    ++\ttest_when_finished \"git notes remove topic unmodified || :\" &&\n      \tgit notes add -m \"topic note\" topic &&\n      \tgit notes add -m \"unmodified note\" unmodified &&\n     -\ttest_when_finished git notes remove topic unmodified &&\n    @@ t/t3206-range-diff.sh: test_expect_success 'range-diff compares notes by default\n      '\n      \n      test_expect_success 'range-diff with --no-notes' '\n    -+\ttest_when_finished git notes remove topic unmodified &&\n    ++\ttest_when_finished \"git notes remove topic unmodified || :\" &&\n      \tgit notes add -m \"topic note\" topic &&\n      \tgit notes add -m \"unmodified note\" unmodified &&\n     -\ttest_when_finished git notes remove topic unmodified &&\n    @@ t/t3206-range-diff.sh: test_expect_success 'range-diff with --no-notes' '\n      '\n      \n      test_expect_success 'range-diff with multiple --notes' '\n    -+\ttest_when_finished git notes --ref=note1 remove topic unmodified &&\n    ++\ttest_when_finished \"git notes --ref=note1 remove topic unmodified || :\" &&\n      \tgit notes --ref=note1 add -m \"topic note1\" topic &&\n      \tgit notes --ref=note1 add -m \"unmodified note1\" unmodified &&\n     -\ttest_when_finished git notes --ref=note1 remove topic unmodified &&\n    -+\ttest_when_finished git notes --ref=note2 remove topic unmodified &&\n    ++\ttest_when_finished \"git notes --ref=note2 remove topic unmodified || :\" &&\n      \tgit notes --ref=note2 add -m \"topic note2\" topic &&\n      \tgit notes --ref=note2 add -m \"unmodified note2\" unmodified &&\n     -\ttest_when_finished git notes --ref=note2 remove topic unmodified &&\n    @@ t/t3206-range-diff.sh: test_expect_success 'range-diff with multiple --notes' '\n      \n      # `range-diff` should act like `log` with regards to notes\n      test_expect_success 'range-diff with --notes=custom does not show default notes' '\n    -+\ttest_when_finished git notes remove topic unmodified &&\n    ++\ttest_when_finished \"git notes remove topic unmodified || :\" &&\n      \tgit notes add -m \"topic note\" topic &&\n      \tgit notes add -m \"unmodified note\" unmodified &&\n    -+\ttest_when_finished git notes --ref=custom remove topic unmodified &&\n    ++\ttest_when_finished \"git notes --ref=custom remove topic unmodified || :\" &&\n      \tgit notes --ref=custom add -m \"topic note\" topic &&\n      \tgit notes --ref=custom add -m \"unmodified note\" unmodified &&\n     -\ttest_when_finished git notes remove topic unmodified &&\n    @@ t/t3206-range-diff.sh: test_expect_success 'range-diff with --notes=custom does\n      '\n      \n      test_expect_success 'format-patch --range-diff does not compare notes by default' '\n    -+\ttest_when_finished git notes remove topic unmodified &&\n    ++\ttest_when_finished \"git notes remove topic unmodified || :\" &&\n      \tgit notes add -m \"topic note\" topic &&\n      \tgit notes add -m \"unmodified note\" unmodified &&\n     -\ttest_when_finished git notes remove topic unmodified &&\n    -+\ttest_when_finished \"rm 000?-*\" &&\n    ++\ttest_when_finished \"rm -f 000?-*\" &&\n      \tgit format-patch --cover-letter --range-diff=$prev \\\n      \t\tmain..unmodified >actual &&\n     -\ttest_when_finished \"rm 000?-*\" &&\n    @@ t/t3206-range-diff.sh: test_expect_success 'format-patch --range-diff does not c\n      '\n      \n      test_expect_success 'format-patch --notes=custom --range-diff only compares custom notes' '\n    -+\ttest_when_finished git notes remove topic unmodified &&\n    ++\ttest_when_finished \"git notes remove topic unmodified || :\" &&\n      \tgit notes add -m \"topic note\" topic &&\n     -\tgit notes --ref=custom add -m \"topic note (custom)\" topic &&\n      \tgit notes add -m \"unmodified note\" unmodified &&\n    --\tgit notes --ref=custom add -m \"unmodified note (custom)\" unmodified &&\n    --\ttest_when_finished git notes remove topic unmodified &&\n    - \ttest_when_finished git notes --ref=custom remove topic unmodified &&\n    ++\ttest_when_finished \"git notes --ref=custom remove topic unmodified || :\" &&\n     +\tgit notes --ref=custom add -m \"topic note (custom)\" topic &&\n    -+\tgit notes --ref=custom add -m \"unmodified note (custom)\" unmodified &&\n    -+\ttest_when_finished \"rm 000?-*\" &&\n    + \tgit notes --ref=custom add -m \"unmodified note (custom)\" unmodified &&\n    +-\ttest_when_finished git notes remove topic unmodified &&\n    +-\ttest_when_finished git notes --ref=custom remove topic unmodified &&\n    ++\ttest_when_finished \"rm -f 000?-*\" &&\n      \tgit format-patch --notes=custom --cover-letter --range-diff=$prev \\\n      \t\tmain..unmodified >actual &&\n     -\ttest_when_finished \"rm 000?-*\" &&\n    @@ t/t3206-range-diff.sh: test_expect_success 'format-patch --range-diff does not c\n      '\n      \n      test_expect_success 'format-patch --range-diff with --no-notes' '\n    -+\ttest_when_finished git notes remove topic unmodified &&\n    ++\ttest_when_finished \"git notes remove topic unmodified || :\" &&\n      \tgit notes add -m \"topic note\" topic &&\n      \tgit notes add -m \"unmodified note\" unmodified &&\n     -\ttest_when_finished git notes remove topic unmodified &&\n    -+\ttest_when_finished \"rm 000?-*\" &&\n    ++\ttest_when_finished \"rm -f 000?-*\" &&\n      \tgit format-patch --no-notes --cover-letter --range-diff=$prev \\\n      \t\tmain..unmodified >actual &&\n     -\ttest_when_finished \"rm 000?-*\" &&\n    @@ t/t3206-range-diff.sh: test_expect_success 'format-patch --range-diff with --no-\n      '\n      \n      test_expect_success 'format-patch --range-diff with --notes' '\n    -+\ttest_when_finished git notes remove topic unmodified &&\n    ++\ttest_when_finished \"git notes remove topic unmodified || :\" &&\n      \tgit notes add -m \"topic note\" topic &&\n      \tgit notes add -m \"unmodified note\" unmodified &&\n     -\ttest_when_finished git notes remove topic unmodified &&\n    -+\ttest_when_finished \"rm 000?-*\" &&\n    ++\ttest_when_finished \"rm -f 000?-*\" &&\n      \tgit format-patch --notes --cover-letter --range-diff=$prev \\\n      \t\tmain..unmodified >actual &&\n     -\ttest_when_finished \"rm 000?-*\" &&\n    @@ t/t3206-range-diff.sh: test_expect_success 'format-patch --range-diff with --not\n      '\n      \n      test_expect_success 'format-patch --range-diff with format.notes config' '\n    -+\ttest_when_finished git notes remove topic unmodified &&\n    ++\ttest_when_finished \"git notes remove topic unmodified || :\" &&\n      \tgit notes add -m \"topic note\" topic &&\n      \tgit notes add -m \"unmodified note\" unmodified &&\n     -\ttest_when_finished git notes remove topic unmodified &&\n      \ttest_config format.notes true &&\n    -+\ttest_when_finished \"rm 000?-*\" &&\n    ++\ttest_when_finished \"rm -f 000?-*\" &&\n      \tgit format-patch --cover-letter --range-diff=$prev \\\n      \t\tmain..unmodified >actual &&\n     -\ttest_when_finished \"rm 000?-*\" &&\n    @@ t/t3206-range-diff.sh: test_expect_success 'format-patch --range-diff with forma\n      '\n      \n      test_expect_success 'format-patch --range-diff with multiple notes' '\n    -+\ttest_when_finished git notes --ref=note1 remove topic unmodified &&\n    ++\ttest_when_finished \"git notes --ref=note1 remove topic unmodified || :\" &&\n      \tgit notes --ref=note1 add -m \"topic note1\" topic &&\n      \tgit notes --ref=note1 add -m \"unmodified note1\" unmodified &&\n     -\ttest_when_finished git notes --ref=note1 remove topic unmodified &&\n    -+\ttest_when_finished git notes --ref=note2 remove topic unmodified &&\n    ++\ttest_when_finished \"git notes --ref=note2 remove topic unmodified || :\" &&\n      \tgit notes --ref=note2 add -m \"topic note2\" topic &&\n      \tgit notes --ref=note2 add -m \"unmodified note2\" unmodified &&\n     -\ttest_when_finished git notes --ref=note2 remove topic unmodified &&\n    -+\ttest_when_finished \"rm 000?-*\" &&\n    ++\ttest_when_finished \"rm -f 000?-*\" &&\n      \tgit format-patch --notes=note1 --notes=note2 --cover-letter --range-diff=$prev \\\n      \t\tmain..unmodified >actual &&\n     -\ttest_when_finished \"rm 000?-*\" &&\n-- \n2.46.0-235-g968ce1ce0e\n\n"}]}