Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial staging does not work if patch contents contains end of a file with no newline #2327

Open
zivarah opened this issue Aug 7, 2024 · 0 comments

Comments

@zivarah
Copy link

zivarah commented Aug 7, 2024

This looks to be the same issue as #1609, but I'm opening a new one since that one is marked as completed.

Description

If a file contains no newline at the end of the file, selective staging of individual lines fails with patch does not apply so long as the end of the file appears in the patch.

It looks like this was also an issue in magit at some point, see magit/magit#1139. However, adding "--ignore-space-change" to cmd in StageApply does not seem to address this issue for me so it looks like there's more to the fix.

Steps to reproduce

  1. Init the test repo and set up the problematic file:

    git init
    
    echo -n 'line 1
    line 2
    line 3' > a
    git add a
    git commit -m a
    
    echo 'line 1
    line 2
    line 2.2
    line 3' > a
  2. Open the status buffer:

    Head: main
    
    Unstaged (1)
    M a
    @@ -1,3 +1,4 @@
     line 1
     line 2
    -line 3
    \ No newline at end of file
    +line 2.2
    +line 3
    
  3. Try to stage only the "line 2.2" line (visually select and press s):

    fugitive: error: patch failed: a:1
    error: a: patch does not apply

Details

The cmd being executed is:

['apply', '-p0', '--recount', '--cached', '--', '<patch file>']

The content of that patch file is:

diff --git a a
index 8cf2f17..58c1de1 100644
--- a
+++ a
@@ -1,3 +1,4 @@
 line 1
 line 2
 line 3
+line 2.2

Specs/setup

OS: MacOS Sonoma 14.5 (also reproduced in Windows 11)
Fugitive: 0444df6 (Use nvim vim.ui.open as a fallback, 2024-07-18)
Git: v2.45.2
Vim: Neovim v0.10.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant