Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Uncaught Error: Patch does not apply in files with DOS line endings on Linux #1450

Open
@ghost

Description

@Kryten0807 commented on May 7, 2018, 7:40 PM UTC:

Description

As discussed in this comment on #15827...
The issue is an uncaught GitError when attempting to stage a hunk in a file. In particular, I have narrowed the issue down to a problem with DOS line endings in an Linux environment.

Steps to Reproduce

Start by setting up a git repository:

mkdir testproject && cd testproject && git init

Add a file with multiple lines & commit it:

echo -e "The first line\nAnother line\nAnd one more line\n" >README.md && git add README.md  && git commit -m "initial commit"

Open atom and open the testproject folder, then open the README.md file.

First, we'll show the correct behaviour:

Insert a new line somewhere in the middle of the file.
Open the Git Tab and click on README.md in the "Unstaged Changes" window.
Click "Stage Hunk" for the hunk containing the new line.
The change is staged and README.md moves to the "Staged Changes" tab, ready to be committed. This is the expected behaviour.

Reset the repository with

git reset --hard HEAD

Now for the incorrect behaviour:
Convert the line endings in README.md to DOS line endings & commit the change:

sed -i "s/$/\r/" README.md && git commit -am "change to DOS line endings"

Insert a new line somewhere in the middle of the README.md.
Open the Git Tab and click on README.md in the "Unstaged Changes" window.
Click "Stage Hunk" for the hunk containing the new line.
The change is not staged and the console displays an uncaught GitError with the following message:

Uncaught (in promise) GitError: git -c color.ui=false -c color.status=false -c color.showBranch=false -c color.diff=false -c color.branch=false apply --cached - in /home/kryten/dev/testproject exited with code 1
stdout: 
stderr: error: patch failed: README.md:1
error: README.md: patch does not apply

    at new GitError (/usr/share/atom/resources/app/node_modules/github/lib/git-shell-out-strategy.js:104:24)
    at /usr/share/atom/resources/app/node_modules/github/lib/git-shell-out-strategy.js:372:33
    at Generator.next (<anonymous>)
    at step (/usr/share/atom/resources/app/node_modules/github/lib/git-shell-out-strategy.js:92:197)
    at /usr/share/atom/resources/app/node_modules/github/lib/git-shell-out-strategy.js:92:367
    at <anonymous>

This problem occurs every time when attempting to edit a file with DOS line endings in a Linux environment. It also occurs when running atom --safe, which suggests that it's a core package causing the problem.

This comment suggests that the issue is related to a package which "modifies the editor text outside of 'the normal flow' (keystrokes)" (which seems like a plausible explanation).

Versions

Ubuntu 18.04 (a fresh install, just done last week)
Atom --version

Atom    : 1.26.1
Electron: 1.7.11
Chrome  : 58.0.3029.110
Node    : 7.9.0

apm --version

apm  1.19.0
npm  3.10.10
node 6.9.5 x64
atom 1.26.1
python 2.7.15rc1
git 2.17.0

The following community packages are installed:

This issue was moved by rsese from atom/atom/issues/17290.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions