{"thread":{"id":"49812","subject":"[PATCH 0/1] Allow \"no-op hunks\" when editing the diff in git add -e","startedAt":"2018-11-12T20:54:51Z","lastAt":"2018-11-12T23:12:23Z","messageCount":3,"participants":["Johannes Schindelin via GitGitGadget","Josh Steadmon"],"isPatch":true,"patchVersion":1,"patchTotal":1},"messages":[{"id":"363083","messageId":"pull.74.git.gitgitgadget@gmail.com","threadId":"49812","inReplyTo":null,"subject":"[PATCH 0/1] Allow \"no-op hunks\" when editing the diff in git add -e","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2018-11-12T20:54:47Z","receivedAt":"2018-11-12T20:54:51Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"I use git add -e frequently. Often there are multiple hunks and I end up\ndeleting the + lines and converting the - lines to context lines, as I like\nto stage massive changes in an incremental fashion (and commit those staged\nchanges incrementally, too).\n\nSome time after I invented git add -e, this feature was broken, and I had to\nstart identifying and deleting those hunks with no changes.\n\nI finally got around to find the regression, and to fix it. Here is the\noutcome of this effort.\n\nJohannes Schindelin (1):\n  apply --recount: allow \"no-op hunks\"\n\n apply.c                |  2 +-\n t/t4136-apply-check.sh | 12 ++++++++++++\n 2 files changed, 13 insertions(+), 1 deletion(-)\n\n\nbase-commit: 8858448bb49332d353febc078ce4a3abcc962efe\nPublished-As: https://github.com/gitgitgadget/git/releases/tags/pr-74%2Fdscho%2Fapply-recount-empty-hunk-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-74/dscho/apply-recount-empty-hunk-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/74\n-- \ngitgitgadget\n"},{"id":"363084","messageId":"dffe2e1144e4a3533f67784abd36671b078105d3.1542056085.git.gitgitgadget@gmail.com","threadId":"49812","inReplyTo":"pull.74.git.gitgitgadget@gmail.com","subject":"[PATCH 1/1] apply --recount: allow \"no-op hunks\"","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2018-11-12T20:54:49Z","receivedAt":"2018-11-12T20:54:52Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nWhen editing patches e.g. in `git add -e`, it is quite common that a\nhunk ends up having no -/+ lines, i.e. it is now supposed to do nothing.\n\nThis use case was broken by ad6e8ed37bc1 (apply: reject a hunk that does\nnot do anything, 2015-06-01) with the good intention of catching a very\nreal, different issue in hand-edited patches.\n\nSo let's use the `--recount` option as the tell-tale whether the user\nwould actually be okay with no-op hunks.\n\nAdd a test case to make sure that this use case does not regress again.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n apply.c                |  2 +-\n t/t4136-apply-check.sh | 12 ++++++++++++\n 2 files changed, 13 insertions(+), 1 deletion(-)\n\ndiff --git a/apply.c b/apply.c\nindex 073d5f0451..76955afb00 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -1748,7 +1748,7 @@ static int parse_fragment(struct apply_state *state,\n \t}\n \tif (oldlines || newlines)\n \t\treturn -1;\n-\tif (!deleted && !added)\n+\tif (!patch->recount && !deleted && !added)\n \t\treturn -1;\n \n \tfragment->leading = leading;\ndiff --git a/t/t4136-apply-check.sh b/t/t4136-apply-check.sh\nindex 6d92872318..4c3f264a63 100755\n--- a/t/t4136-apply-check.sh\n+++ b/t/t4136-apply-check.sh\n@@ -29,6 +29,18 @@ test_expect_success 'apply exits non-zero with no-op patch' '\n \ttest_must_fail git apply --check input\n '\n \n+test_expect_success '`apply --recount` allows no-op patch' '\n+\techo 1 >1 &&\n+\tgit apply --recount --check <<-\\EOF\n+\tdiff --get a/1 b/1\n+\tindex 6696ea4..606eddd 100644\n+\t--- a/1\n+\t+++ b/1\n+\t@@ -1,1 +1,1 @@\n+\t 1\n+\tEOF\n+'\n+\n test_expect_success 'invalid combination: create and copy' '\n \ttest_must_fail git apply --check - <<-\\EOF\n \tdiff --git a/1 b/2\n-- \ngitgitgadget\n"},{"id":"363098","messageId":"20181112231214.GB126896@google.com","threadId":"49812","inReplyTo":"dffe2e1144e4a3533f67784abd36671b078105d3.1542056085.git.gitgitgadget@gmail.com","subject":"Re: [PATCH 1/1] apply --recount: allow \"no-op hunks\"","fromName":"Josh Steadmon","fromEmail":"steadmon@google.com","sentAt":"2018-11-12T23:12:14Z","receivedAt":"2018-11-12T23:12:23Z","isPatch":true,"sender":{"key":"steadmon@google.com","avatar":"https://avatars.githubusercontent.com/u/2654920?v=4"},"body":"On 2018.11.12 12:54, Johannes Schindelin via GitGitGadget wrote:\n> From: Johannes Schindelin <johannes.schindelin@gmx.de>\n> \n> When editing patches e.g. in `git add -e`, it is quite common that a\n> hunk ends up having no -/+ lines, i.e. it is now supposed to do nothing.\n> \n> This use case was broken by ad6e8ed37bc1 (apply: reject a hunk that does\n> not do anything, 2015-06-01) with the good intention of catching a very\n> real, different issue in hand-edited patches.\n> \n> So let's use the `--recount` option as the tell-tale whether the user\n> would actually be okay with no-op hunks.\n> \n> Add a test case to make sure that this use case does not regress again.\n> \n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nLooks good to me.\n\nReviewed-by: Josh Steadmon <steadmon@google.com>\n"}]}