From patchwork Fri Dec 6 13:08:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11276109 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 88F701593 for ; Fri, 6 Dec 2019 13:08:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6755624673 for ; Fri, 6 Dec 2019 13:08:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CYI5PNRm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726278AbfLFNIa (ORCPT ); Fri, 6 Dec 2019 08:08:30 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:33969 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726244AbfLFNIa (ORCPT ); Fri, 6 Dec 2019 08:08:30 -0500 Received: by mail-wr1-f68.google.com with SMTP id t2so7733904wrr.1 for ; Fri, 06 Dec 2019 05:08:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=aSIEo2CTD1Fq9I0+q8CZJbf/EZO+q7zNa6MBn/pl+dI=; b=CYI5PNRm5q0Z/jBlkWgKJaZAnG9VduoI9aQzLVOX8QDBzG82A6+41rf9ZaddKMFIL5 cGm2nvtaSKHFrZ4Vkm3jJNL/yT6VkwU0xwKymaP7jcoG7HdYZ3MlZm+6VJ7M/0Wtbd0B hJ84n+foSPlUfw3pb3ubgLqOiZoT13U1C2riSmzkpcHqZtle9tqlAKmV8Aor2t38o0Dx OESjfvWlmoLBeXkDPcpsbVLRzykNqm3fRSr3ybEcGrQj810CrebqlrDaHV05hs4RlhPr FjyAvGNx4zwEcnMPL7dJUY9WXrEEtIe6914G9BllPhHgl/Is7m0eqrxAIjZ89D9zJzqF RZKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=aSIEo2CTD1Fq9I0+q8CZJbf/EZO+q7zNa6MBn/pl+dI=; b=jddR7fDyU4U1ofHkEhal1ZYw2hCRJe5lnOguWHeDf910OU+KB6jLfTEsd4vOjHBzhZ pG13ayJN4fJRTqJ5slg615wRPrbx2XvjhCNOt33Fy8bML2rK6unRcGCCJB91Zb8Vxmci CSmwQjC+M80XrrP6KPW5efcPQnLoutTFp8Zc2EeZnMMT9JG4cDK9EhQ+9kWW+uY0PWHJ 7ggLfEdU/pIdPPCW/qsIDDff+imyIULqFNTop9OwtcabfjK99meGenKy/DVUgCl2KWpm flrSE8/f2esG7K17bK/RqFCIyzAU+cVRh0gqBHyE6PYlZDPWLxm5TPv7gpdo6gQyrOUp f2Jw== X-Gm-Message-State: APjAAAVb3aEOQ84iTKseKNMqU0HmkRcwGORmVtHDPSXAD08L+2KXn/me 7vIA7y5AeHiG3jfIVpHaXEM50zhQ X-Google-Smtp-Source: APXvYqzKsdS/EPLpsWc8mhDweQ2CIsyb3Yq/Ft+ntXNHy8Z+1Ig9GunBFLHwN/Q3ME8HHtQenowtTA== X-Received: by 2002:adf:f80c:: with SMTP id s12mr15500663wrp.1.1575637707624; Fri, 06 Dec 2019 05:08:27 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n8sm16061398wrx.42.2019.12.06.05.08.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Dec 2019 05:08:27 -0800 (PST) Message-Id: In-Reply-To: References: From: "Johannes Schindelin via GitGitGadget" Date: Fri, 06 Dec 2019 13:08:19 +0000 Subject: [PATCH 1/7] t3701: add a test for advanced split-hunk editing Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Junio C Hamano , Johannes Schindelin Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin In this developer's workflows, it often happens that a hunk needs to be edited in a way that adds lines, and sometimes even reduces the number of context lines. Let's add a regression test for this. Note that just like the preceding test case, the new test case is *not* handled gracefully by the current `git add -p`. It will be handled correctly by the upcoming built-in `git add -p`, though. Signed-off-by: Johannes Schindelin --- t/t3701-add-interactive.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index d4f9386621..4da99e27af 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -403,6 +403,28 @@ test_expect_failure 'split hunk "add -p (no, yes, edit)"' ' ! grep "^+31" actual ' +test_expect_failure 'edit, adding lines to the first hunk' ' + test_write_lines 10 11 20 30 40 50 51 60 >test && + git reset && + tr _ " " >patch <<-EOF && + @@ -1,5 +1,6 @@ + _10 + +11 + +12 + _20 + +21 + +22 + _30 + EOF + # test sequence is s(plit), e(dit), n(o) + # q n q q is there to make sure we exit at the end. + printf "%s\n" s e n q n q q | + EDITOR=./fake_editor.sh git add -p 2>error && + test_must_be_empty error && + git diff --cached >actual && + grep "^+22" actual +' + test_expect_success 'patch mode ignores unmerged entries' ' git reset --hard && test_commit conflict && From patchwork Fri Dec 6 13:08:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11276111 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B6E2513B6 for ; Fri, 6 Dec 2019 13:08:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 949A22075C for ; Fri, 6 Dec 2019 13:08:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HW8Wpye5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726312AbfLFNIc (ORCPT ); Fri, 6 Dec 2019 08:08:32 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:50850 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726246AbfLFNIa (ORCPT ); Fri, 6 Dec 2019 08:08:30 -0500 Received: by mail-wm1-f66.google.com with SMTP id p9so7786579wmg.0 for ; Fri, 06 Dec 2019 05:08:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=dk4jHk9V8pKAO9UUtocjKNsOEWJO42Db7pR93uzxgG8=; b=HW8Wpye5UsXzKD0D/AntCvESL8d/zVvvtFatVXeIgIwpAOJu5FSWnGS5OtjwPzUKsH h55bIDKWfbsFVX6MXcSYor3cHUwcBS9fwhZ+yvgnZxQrWLV2YrTKTlGxNNbCs4xlBnqE h0gmULSFbMjZ5mTCSZT0/qiha7h3Ydl6HgcMWw7jlimMQp63NBRg9pYjqGwgpfpnLbY9 +LqJkiLdVGcBCdlZB8yysno2/MT7cVvmWMF5dclBDqJMmtA43K+DW+uZIYVbnoVBCAyO Tc5b6STfRusgHo3AZTUIpsKBB7LBcQdcB9CfVHa8L+j/4Cvxk0oFocfQE6Ss8IJlNgAU w/bQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=dk4jHk9V8pKAO9UUtocjKNsOEWJO42Db7pR93uzxgG8=; b=h7PFjkBL87+ptX3ORQA6gEtL5EehLAJQ1HkZsmlRSVYR0zTKrVBLn3kbt5JyBCJa58 m+lJbmdrXRqZ8N9+4f431U/Xfi8TZg1MA4gWwf+lcB5GnJSdWPRqhEQ8ej/tYBWrYQiw KBfVw56F7HBKgH44H+eruV76PhKpCXGWYUcVb9+zgi6Fb9UqgXknFHySw5mu3Op2KVTs PoopOI2rNJXWVkcOkb8NLjg8z+ma0bLlre0eZ+01NAu42915+dw8PMRqG34UI3MbAIzX dSmzsGMGB7VIwC5BG8mwB/pG7Mty3wPolmySssFJxCk5CMwEbixR+mDEsIXpvbpnlHf6 qEQQ== X-Gm-Message-State: APjAAAU1GY1ZnvWHZR4hvbtNnyfK9sl6FEgRbVwIJQHrgJxryoxwcAQv bkVNzE+Jgwge9ID3VRtARLIBrlQW X-Google-Smtp-Source: APXvYqzqNq8RUde4XVK/ZmSR4RwBCuKxpBizkI1pDiIZqb5dqiEkLzQhv5Ngw5UgZ2PqcACDjhF9zw== X-Received: by 2002:a7b:cc81:: with SMTP id p1mr10831000wma.62.1575637708456; Fri, 06 Dec 2019 05:08:28 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id x18sm15963252wrr.75.2019.12.06.05.08.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Dec 2019 05:08:28 -0800 (PST) Message-Id: In-Reply-To: References: From: "Johannes Schindelin via GitGitGadget" Date: Fri, 06 Dec 2019 13:08:20 +0000 Subject: [PATCH 2/7] t3701: avoid depending on the TTY prerequisite Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Junio C Hamano , Johannes Schindelin Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin The TTY prerequisite is a rather heavy one: it not only requires Perl to work, but also the IO/Pty.pm module (with native support, and it requires pseudo terminals, too). In particular, test cases marked with the TTY prerequisite would be skipped in Git for Windows' SDK. In the case of `git add -p`, we do not actually need that big a hammer, as we do not want to test any functionality that requires a pseudo terminal; all we want is for the interactive add command to use color, even when being called from within the test suite. And we found exactly such a trick earlier already: when we added a test case to verify that the main loop of `git add -i` is colored appropriately. Let's use that trick instead of the TTY prerequisite. While at it, we avoid the pipes, as we do not want a SIGPIPE to break the regression test cases (which will be much more likely when we do not run everything through Perl because that is inherently slower). Signed-off-by: Johannes Schindelin --- t/t3701-add-interactive.sh | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index 4da99e27af..793ce28297 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -23,6 +23,17 @@ diff_cmp () { test_cmp "$1.filtered" "$2.filtered" } +# This function uses a trick to manipulate the interactive add to use color: +# the `want_color()` function special-cases the situation where a pager was +# spawned and Git now wants to output colored text: to detect that situation, +# the environment variable `GIT_PAGER_IN_USE` is set. However, color is +# suppressed despite that environment variable if the `TERM` variable +# indicates a dumb terminal, so we set that variable, too. + +force_color () { + env GIT_PAGER_IN_USE=true TERM=vt100 "$@" +} + test_expect_success 'setup (initial)' ' echo content >file && git add file && @@ -451,35 +462,38 @@ test_expect_success 'patch mode ignores unmerged entries' ' diff_cmp expected diff ' -test_expect_success TTY 'diffs can be colorized' ' +test_expect_success 'diffs can be colorized' ' git reset --hard && echo content >test && - printf y | test_terminal git add -p >output 2>&1 && + printf y >y && + force_color git add -p >output 2>&1 test && test_config interactive.diffFilter "sed s/^/foo:/" && - printf y | test_terminal git add -p >output 2>&1 && + printf y >y && + force_color git add -p >output 2>&1 test && test_config interactive.diffFilter "echo too-short" && - printf y | test_must_fail test_terminal git add -p + printf y >y && + test_must_fail force_color git add -p What now>$SP Bye. EOF - test_write_lines h | GIT_PAGER_IN_USE=true TERM=vt100 git add -i >actual.colored && + test_write_lines h | force_color git add -i >actual.colored && test_decode_color actual && test_i18ncmp expect actual ' From patchwork Fri Dec 6 13:08:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11276113 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 193B1186D for ; Fri, 6 Dec 2019 13:08:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E2A782464E for ; Fri, 6 Dec 2019 13:08:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="qSfkr6UQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726298AbfLFNId (ORCPT ); Fri, 6 Dec 2019 08:08:33 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:46545 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726168AbfLFNIb (ORCPT ); Fri, 6 Dec 2019 08:08:31 -0500 Received: by mail-wr1-f67.google.com with SMTP id z7so7617433wrl.13 for ; Fri, 06 Dec 2019 05:08:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=FbYx9s5BzVDyeboThLHY4f9FslCWDrhTHE6FCY7J7qQ=; b=qSfkr6UQPbMcdoXANwgnxjui4K2v8vbx6DF/buFLBKqk/GLzP78ZrUywL5acjB4Su0 fRK5cl5myHhrsGmNs6TBjNgELlGYe/NK0y9uto0+uuWiPlr+b8IJtaLNkf74v+3irjUq VHYfBuVjr0KTm7epVbaDA4bMXTXvF7sbEz3gIabDneVULhTaFqqc/xHyj3jETrSu4u+l /ZG4PAGJhLWWkMrovDCuRWcuxDvIzNPC9J8lGaoURJmSuOqjOV984kSr+MeGmp/cLA4L lTrpFxSMPNKDYVBv+9uuw+swKpqgR+vQCHwG82/NlaMhWS8XNy9xQADGiwiyRBGEPqL3 vLTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=FbYx9s5BzVDyeboThLHY4f9FslCWDrhTHE6FCY7J7qQ=; b=CWQhvDzYd/3z9hRJ7fMgDWmOZwGEsGcxbX4zmOaX1T8VsZ4VPX/Gu4RBqVNbkoEC/9 fwgjHhRRes4TpJCJuM2Cud2T1x9LOE1HJSpKqt34rq3IVztVVO7TNxIn5oNuhZspylm9 qr9aWsaXF0QrxCW1Qu6eEeELwWs4h3xktkzgn4zTch0FmlH/+6LhX3740pwIwPzE+qjC VCNyoFe93ByyPknJHKuKidj2hkui97h9iZaKOhUKx3L7twWqs3cHWt6Kykxt0S/qk7yp Jj4PhUaaJlpj2NIOcbUsDOLudA9Ll6zeOGSG1gnc/883ZgXJXkwv6v1eXysZqQ2YXrlC XJCQ== X-Gm-Message-State: APjAAAXEZ4t5m7d/JEJg5iM6WWnE1zWYvfetk7Iy4SP3aZ+3sa2BJ1ws c0mc4Pwippl9lER7pkpTl/Gvw5+a X-Google-Smtp-Source: APXvYqzZIaPFJEF7PalObgJkqt0yD+fnL1F6e91NmO6I7/TH7ueJ4NHNbcqAYGI5OVeS6zw+46PkAQ== X-Received: by 2002:a5d:65c5:: with SMTP id e5mr15688426wrw.311.1575637709133; Fri, 06 Dec 2019 05:08:29 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z12sm3390565wmd.16.2019.12.06.05.08.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Dec 2019 05:08:28 -0800 (PST) Message-Id: In-Reply-To: References: From: "Johannes Schindelin via GitGitGadget" Date: Fri, 06 Dec 2019 13:08:21 +0000 Subject: [PATCH 3/7] t3701: add a test for the different `add -p` prompts Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Junio C Hamano , Johannes Schindelin Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin The `git add -p` command offers different prompts for regular diff hunks vs mode change pseudo hunks vs diffs deleting files. Let's cover this in the regresion test suite, in preparation for re-implementing `git add -p` in C. For the mode change prompt, we use a trick that lets this test case pass even on systems without executable bit, i.e. where `core.filemode = false` (such as Windows): we first add the file to the index with `git add --chmod=+x`, and then call `git add -p` with `core.filemode` forced to `true`. The file on disk has no executable bit set, therefore we will see a mode change. Signed-off-by: Johannes Schindelin --- t/t3701-add-interactive.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index 793ce28297..c90aaa25b0 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -105,7 +105,6 @@ test_expect_success 'revert works (commit)' ' grep "unchanged *+3/-0 file" output ' - test_expect_success 'setup expected' ' cat >expected <<-\EOF EOF @@ -274,6 +273,24 @@ test_expect_success FILEMODE 'stage mode and hunk' ' # end of tests disabled when filemode is not usable +test_expect_success 'different prompts for mode change/deleted' ' + git reset --hard && + >file && + >deleted && + git add --chmod=+x file deleted && + echo changed >file && + rm deleted && + test_write_lines n n n | + git -c core.filemode=true add -p >actual && + sed -n "s/^\(([0-9/]*) Stage .*?\).*/\1/p" actual >actual.filtered && + cat >expect <<-\EOF && + (1/1) Stage deletion [y,n,q,a,d,?]? + (1/2) Stage mode change [y,n,q,a,d,j,J,g,/,?]? + (2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,?]? + EOF + test_cmp expect actual.filtered +' + test_expect_success 'setup again' ' git reset --hard && test_chmod +x file && From patchwork Fri Dec 6 13:08:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11276117 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CED2D13B6 for ; Fri, 6 Dec 2019 13:08:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AD66324675 for ; Fri, 6 Dec 2019 13:08:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NbFYRGXk" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726328AbfLFNIe (ORCPT ); Fri, 6 Dec 2019 08:08:34 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:43912 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726171AbfLFNIb (ORCPT ); Fri, 6 Dec 2019 08:08:31 -0500 Received: by mail-wr1-f65.google.com with SMTP id d16so7654453wre.10 for ; Fri, 06 Dec 2019 05:08:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=2FmewC98EFcV+WnDki6MmC2bm/34VnAVJLh13ciP2rE=; b=NbFYRGXkbfoTjf6DxOOQDR196hav6Mu6dmO9/DmmZPAX2Z9frqf52cBfU/3fcZR+KJ aMZBmWTdFAnw0Re/yHIyO6CMS+Z7GmJpnPjIugcUQ/i8/Fq16WBTYRpuYX9lksL0AbPM LvJ6bfrB6xWjVQ7Dfc2axC3Snxbz+/icqJaqk3+o/iCxpuSqaI5eTRvhOJdi6jK5NN9v qgHDdwmNXAcGDAFO3QGor1RQ894nww4HwcWeAv4jdZGk/h9CBLftCouV7Zbl+Af2oUEV +n71StDCEEj5QdPyx91ju2ck/OhMam88bxKtiq00H0hxDTuSBSXY+ifLy0zelDDXTnDn ORNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=2FmewC98EFcV+WnDki6MmC2bm/34VnAVJLh13ciP2rE=; b=HpPjfnjbRqioukCGqmdLFQCxDbzZsRAnnyOmStbw8SHfGud1LPUPJA/0KpESOUwhiJ uBXVn3B2HxIX3iMt8hjkD35yAmZimceHl4ul39Y3JWzwsf6uAVIqM8q6svTYrj88ZzHw kz/9dyGra+CAvm5Pn/g4wybrdZkI4Sk+n0w2uisqXQthuIrnQ5Sm7WkQrwKmNOVZDtIf a8lGPhYJuK/12GK5G3oRyRop9PkBWd4BENPImXC3pORKthohCxdSteLlhUrZxFIQUrFo TelhFz3AbHiMBJQUaYAs2Pm8F8tws1Q6MTUBv54ahAH826ze0czbu706O7/KJ9F9VOI2 OPhQ== X-Gm-Message-State: APjAAAX6FHPT9ZYGTghD+vCTB7fn/TlSakdph3G2ObCDdtmmxum+8a6E Ft2C2ouLAUk482MlBa16Js80cyFh X-Google-Smtp-Source: APXvYqw76J9TmhZMWu2zLkxVIXX78+/Z1KqLO0dIAYirF/k30dy8lpyxFD0h1LoUhK03xKuqrVhOCQ== X-Received: by 2002:a5d:6ca1:: with SMTP id a1mr15301076wra.36.1575637709883; Fri, 06 Dec 2019 05:08:29 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y20sm3209443wmi.25.2019.12.06.05.08.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Dec 2019 05:08:29 -0800 (PST) Message-Id: <2219b37fd58dea0d503777177ea79f68ea892dc7.1575637705.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Johannes Schindelin via GitGitGadget" Date: Fri, 06 Dec 2019 13:08:22 +0000 Subject: [PATCH 4/7] t3701: verify the shown messages when nothing can be added Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Junio C Hamano , Johannes Schindelin Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin In preparation for re-implementing `git add -p` in pure C (where we will purposefully keep the implementation of `git add -p` separate from the implementation of `git add -i`), let's verify that the user is told the same things as in the Perl version when the diff file is either empty or contains only entries about binary files. Signed-off-by: Johannes Schindelin --- t/t3701-add-interactive.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index c90aaa25b0..797610e96d 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -291,6 +291,17 @@ test_expect_success 'different prompts for mode change/deleted' ' test_cmp expect actual.filtered ' +test_expect_success 'correct message when there is nothing to do' ' + git reset --hard && + git add -p 2>err && + test_i18ngrep "No changes" err && + printf "\\0123" >binary && + git add binary && + printf "\\0abc" >binary && + git add -p 2>err && + test_i18ngrep "Only binary files changed" err +' + test_expect_success 'setup again' ' git reset --hard && test_chmod +x file && From patchwork Fri Dec 6 13:08:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11276115 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D9ABC13B6 for ; Fri, 6 Dec 2019 13:08:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B83BA24673 for ; Fri, 6 Dec 2019 13:08:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nTtphh9r" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726345AbfLFNIf (ORCPT ); Fri, 6 Dec 2019 08:08:35 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:35102 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726244AbfLFNIc (ORCPT ); Fri, 6 Dec 2019 08:08:32 -0500 Received: by mail-wm1-f67.google.com with SMTP id c20so5812637wmb.0 for ; Fri, 06 Dec 2019 05:08:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=pVjJ1d97OpG4rro4F3oFJL8ULZntWJLHWsqB7HlzzP4=; b=nTtphh9rgKmmpfkOeikVLjOlQ8e99T5+ZXX9LVZyAciOKdxvTjLXj7ejR621JLsj5P d9fFnvYdnlS9yHvymsTY7fSOE6nwC4MJLqtIbXUr1kpAbsTfzSWXjrhjEnRskyD/DaWS 6xHKQOsVcQgOUWytEapD2w/iSMdqzpUu2CYknkcvPlpTjUGMDbkNLtBs53xoTkRRKzqN /eu5zDmrppwjnklYqk+celyuap3bgNSO34uaIHPaKpaX2QBU3R3y/w873tQ57JLSSm02 6U65aqzU8SsnOfE+tl37XFy8eQutFfdmEoDZIrK1y/nnrZ0hOzCztHEUNmyC7g+Y+7hi g8vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=pVjJ1d97OpG4rro4F3oFJL8ULZntWJLHWsqB7HlzzP4=; b=NePKz6jneKpgmDgOwnWTIn0+4wfpCur5T5HaerCdarjwVgB5lAEQVq2x7idTXk24ft PisO1JrTi6sTfZKPU8hjXa7g2M9YG+TToSBhONrklAV99m7Xt/L0mlXmapNmZBffBWJ8 qX1qVC30Mz6Wb3stAgYAbGy9I5AiibonwRr3IvplPIaE1z4RJ6jT/qzpWy5R3tia9p29 16FC1qxwNBCSPET7fqYWjKnLwIS9VE1y24UL9L2nYh7f4qbQIIlTtCmaR9U3AxYJ+WDu 19DlXTHyDicN+CNtEteVa8HNXTJCLBFDbTV+/Ckap00p1UcgBjJPp785ilaohcZ84mpi RHsw== X-Gm-Message-State: APjAAAXjahPcY+Mn6n76ja2PIGjnBYL6NVknUlSVeFom9lkizzY4zyVo 3fTkP9jwhZRShBW67TWuPJQndIE4 X-Google-Smtp-Source: APXvYqwF8Un3Nr4Edlden20V0YflFI5Fb/hSNNBy+DJLNOpIp+xfB1+TCQIiDQEyl6lfrgptL/+pIw== X-Received: by 2002:a1c:dc82:: with SMTP id t124mr3962441wmg.122.1575637710541; Fri, 06 Dec 2019 05:08:30 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z4sm3407474wme.17.2019.12.06.05.08.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Dec 2019 05:08:30 -0800 (PST) Message-Id: <3f219fd789b3cf1c4d9c42b71a175d31df1afeeb.1575637705.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Johannes Schindelin via GitGitGadget" Date: Fri, 06 Dec 2019 13:08:23 +0000 Subject: [PATCH 5/7] t3701: verify that the diff.algorithm config setting is handled Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Junio C Hamano , Johannes Schindelin Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin Without this patch, there is actually no test in Git's test suite that covers the diff.algorithm feature. Let's add one. We do this by passing a bogus value and then expecting `git diff-files` to produce the appropriate error message. Signed-off-by: Johannes Schindelin --- t/t3701-add-interactive.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index 797610e96d..f43634102e 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -524,6 +524,16 @@ test_expect_success 'detect bogus diffFilter output' ' test_must_fail force_color git add -p file && + git add file && + echo changed >file && + git -c diff.algorithm=bogus add -p 2>err && + test_i18ngrep "error: option diff-algorithm accepts " err +' + test_expect_success 'patch-mode via -i prompts for files' ' git reset --hard && From patchwork Fri Dec 6 13:08:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11276121 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 36F5D13B6 for ; Fri, 6 Dec 2019 13:08:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 15C7624677 for ; Fri, 6 Dec 2019 13:08:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nD0JNe5U" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726347AbfLFNIi (ORCPT ); Fri, 6 Dec 2019 08:08:38 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:39915 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726302AbfLFNId (ORCPT ); Fri, 6 Dec 2019 08:08:33 -0500 Received: by mail-wm1-f65.google.com with SMTP id s14so7269302wmh.4 for ; Fri, 06 Dec 2019 05:08:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=cVW3knpJz0qslluRG98HoYb0muEhNyhfjcTfVDLWKjM=; b=nD0JNe5Um4qFRv69N/cyNwdXx5uYjM6AdM9WMSjeluqBa4tpX8ExSrB728oU3c/5wB pqKiECrzZy5YQD6n/K7StHKHjlQMKNbX7e+xwh7wcZx4MOmTfPUbBvxvUuRiODonaTHC hulXuyRYO2kJKSJE5WfmTIMTRgpxLTOdhbQJL7FZseywOk4vCDCh/Ys2RSRbHYovDGzY IMP8fyLoso5VafoFjNA68ruyzZDpZYp7sAKlp/vv39hvxVwnzxq85NkaPmXy9qujO8yA 5JAv9++YzAGXT5JUSIH+Hy/ccGpAWjBDVypthuNiZ1gmvePmA58gCQ9W61cxwVM1Wgi+ hz9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=cVW3knpJz0qslluRG98HoYb0muEhNyhfjcTfVDLWKjM=; b=q6gxQ0l6RdhinPzZ4/sMM+Tun+z9SU3vVsMAfENnIFEGyPIKYIRzxf5MVLa6pvqu7y QqRa5qxXppp2BC9c0hv5wtwqnbchotn278HqH/rHtmSxeyLcnw/zI7IDQEYVfaOPfvU0 7nhoBzSfkbnoLo/MbotrutIFhW9tT8pA+ac0AX8sV/6jFwGkxLUliAKIuZM6GTgoWKvW mTYpLsi3CsZhuskT5YNssnHW5jIH2DZHZeXbv2wIo9goQXv0KwFTxfYj97aHciucQ6vD J1KEiBLN/4a7W2wlfXjTHJlRDtX3s0z8UXWH9k6G3xzKTKrWDuWhX2EMLLeQBxmcGW40 2PDw== X-Gm-Message-State: APjAAAWBM6EU2wybUeSOn5Eh0hl4rPEQ8+Z386RHi6NYybMWB4G6TCYE UIiiT5BfW12AEJ9YeKeU/HxD0LLo X-Google-Smtp-Source: APXvYqwwK+YD8AKLRhMpeqzahV9gZvGQ0euPs6cDxSKlYYzw97ZoXZGvSzhzQBMUPp9IOP81fFmeIg== X-Received: by 2002:a7b:c357:: with SMTP id l23mr10419581wmj.152.1575637711217; Fri, 06 Dec 2019 05:08:31 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a184sm3468905wmf.29.2019.12.06.05.08.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Dec 2019 05:08:30 -0800 (PST) Message-Id: <27c8ceeb1150dafeaf5b83831487f6bd66c04839.1575637705.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Johannes Schindelin via GitGitGadget" Date: Fri, 06 Dec 2019 13:08:24 +0000 Subject: [PATCH 6/7] git add -p: use non-zero exit code when the diff generation failed Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Junio C Hamano , Johannes Schindelin Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin The first thing `git add -p` does is to generate a diff. If this diff cannot be generated, `git add -p` should not continue as if nothing happened, but instead fail. What we *actually* do here is much broader: we now verify for *every* `run_cmd_pipe()` call that the spawned process actually succeeded. Note that we have to change two callers in this patch, as we need to store the spawned process' output in a local variable, which means that the callers can no longer decide whether to interpret the `return <$fh>` in array or in scalar context. This bug was noticed while writing a test case for the diff.algorithm feature, and we let that test case double as a regression test for this fixed bug, too. Signed-off-by: Johannes Schindelin --- git-add--interactive.perl | 8 +++++--- t/t3701-add-interactive.sh | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/git-add--interactive.perl b/git-add--interactive.perl index 52659bb74c..10fd30ae16 100755 --- a/git-add--interactive.perl +++ b/git-add--interactive.perl @@ -177,7 +177,9 @@ sub run_cmd_pipe { } else { my $fh = undef; open($fh, '-|', @_) or die; - return <$fh>; + my @out = <$fh>; + close $fh || die "Cannot close @_ ($!)"; + return @out; } } @@ -224,7 +226,7 @@ sub list_untracked { sub get_empty_tree { return $empty_tree if defined $empty_tree; - $empty_tree = run_cmd_pipe(qw(git hash-object -t tree /dev/null)); + ($empty_tree) = run_cmd_pipe(qw(git hash-object -t tree /dev/null)); chomp $empty_tree; return $empty_tree; } @@ -1127,7 +1129,7 @@ sub edit_hunk_manually { EOF2 close $fh; - chomp(my $editor = run_cmd_pipe(qw(git var GIT_EDITOR))); + chomp(my ($editor) = run_cmd_pipe(qw(git var GIT_EDITOR))); system('sh', '-c', $editor.' "$@"', $editor, $hunkfile); if ($? != 0) { diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index f43634102e..5db6432e33 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -530,7 +530,7 @@ test_expect_success 'diff.algorithm is passed to `git diff-files`' ' >file && git add file && echo changed >file && - git -c diff.algorithm=bogus add -p 2>err && + test_must_fail git -c diff.algorithm=bogus add -p 2>err && test_i18ngrep "error: option diff-algorithm accepts " err ' From patchwork Fri Dec 6 13:08:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11276119 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B4E69138C for ; Fri, 6 Dec 2019 13:08:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 93BC924673 for ; Fri, 6 Dec 2019 13:08:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="A3OaAkPJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726213AbfLFNIh (ORCPT ); Fri, 6 Dec 2019 08:08:37 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:37684 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726313AbfLFNId (ORCPT ); Fri, 6 Dec 2019 08:08:33 -0500 Received: by mail-wr1-f67.google.com with SMTP id w15so7734208wru.4 for ; Fri, 06 Dec 2019 05:08:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=eiKsWnXfCifGwtnKbfJ/FV46yMNv3C4tpeaajrVzSpE=; b=A3OaAkPJ4uQnr6pDzzkXQzxcYOeafCW9Yl/U9lTN8sUHumKVCxHFridNfEpk8SDId3 HuPsLftjA3bfs+Z1O5tdetEafQH9IHR7owmlQsSg1VEYSLycX4goWbqqQgV1jNCI1YGM 9M/Q0yfFc2AWpcJd8dFa0etPtc2CpC6yDULgEco3k//vQByeLbNqa8T5Y9J+JioBAbm6 0a7rd7uhO9nTvgi296Z06AbC/VT0SgIeyOfr5+OqFcsqtB7NiaM+5QIrdDDPn4cS9HIN 0wQX+jYKzFGOSjwsYkzvQ+TBkVkL+BIJdL/OMc6I99ld1Gyc6fxC3kw+vrcMm0ybhP1f llnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=eiKsWnXfCifGwtnKbfJ/FV46yMNv3C4tpeaajrVzSpE=; b=m7Kc5Wewu6zj5EDEnVhksFMiT7vi2j/MAnAN0UH8ckKbZbF9bsYglQbjADvQS8/DOl idjgAVBJttHpkZi+9binWe7hmCknNgmtWnCaWl/ZONQOK7vep/08Y6hBToJUDSHvE7Rq XaBXriX3nI8iwIbg47tYDpcY4nO4mvGA356wJeom6+/Cb9aL7+1jXNV+DlS8kmwq3LQH idVUmqxXj0rQpCkidRw1GH9YBZuAnK+LeS5ZEuVFZzeucbK2uWXJ1kgsUBrc4ZcMXi45 Sd7PIpxKYfElHr9umOa111ZqxXaRNOKZd4fStOrmUqQAdMTSDm1kc2heBWgi2kARD6zh Y3xA== X-Gm-Message-State: APjAAAWqstfTXSGgJWV2KrOPM5uMw1GSkGz+7UHdstsEmIPNnypM2Xr3 qHk9IJ+tZOvYLG/jK0Aeal7qIPMw X-Google-Smtp-Source: APXvYqzWwJvihIMaRwaGiQ/JcUBDUXLwDSWMkHiz2tTjiEjhupTb5wKuWO/whbsmYP7D26HPR//VBw== X-Received: by 2002:adf:fa0b:: with SMTP id m11mr15615361wrr.98.1575637711932; Fri, 06 Dec 2019 05:08:31 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l3sm16122502wrt.29.2019.12.06.05.08.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Dec 2019 05:08:31 -0800 (PST) Message-Id: <15c4cce5a027d56c7ddbe5523cf0f3beabd06ed7.1575637705.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Johannes Schindelin via GitGitGadget" Date: Fri, 06 Dec 2019 13:08:25 +0000 Subject: [PATCH 7/7] apply --allow-overlap: fix a corner case Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Junio C Hamano , Johannes Schindelin Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin Yes, yes, this is supposed to be only a band-aid option for `git add -p` not Doing The Right Thing. But as long as we carry the `--allow-overlap` option, we might just as well get it right. This fixes the case where one hunk inserts a line before the first line, and is followed by a hunk whose context overlaps with the first one's and which appends a line at the end. Signed-off-by: Johannes Schindelin --- apply.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/apply.c b/apply.c index f8a046a6a5..720a631eaa 100644 --- a/apply.c +++ b/apply.c @@ -2661,6 +2661,16 @@ static int find_pos(struct apply_state *state, unsigned long backwards, forwards, current; int backwards_lno, forwards_lno, current_lno; + /* + * When running with --allow-overlap, it is possible that a hunk is + * seen that pretends to start at the beginning (but no longer does), + * and that *still* needs to match the end. So trust `match_end` more + * than `match_beginning`. + */ + if (state->allow_overlap && match_beginning && match_end && + img->nr - preimage->nr != 0) + match_beginning = 0; + /* * If match_beginning or match_end is specified, there is no * point starting from a wrong line that will never match and