github icon indicating copy to clipboard operation
github copied to clipboard

Uncaught (in promise) GitError: git apply --cached - in **file path** exited with code 1

Open DeanmvSG opened this issue 7 years ago • 12 comments

Description

When trying to press the "Stage all" button in the top right of a file, sometimes it will looks like it does nothing, fail and the file will not get staged. This will throw an error into Atom's console of

Uncaught (in promise) GitError: git apply --cached - in **File Path** exited with code 1
stdout: 
stderr: error: patch failed: Site/Templates/Demo.html:8
error: Site/Templates/Demo.html: patch does not apply

    at new GitError (/Applications/Atom Beta.app/Contents/Resources/app/node_modules/github/lib/git-shell-out-strategy.js:134:1)
    at /Applications/Atom Beta.app/Contents/Resources/app/node_modules/github/lib/git-shell-out-strategy.js:342:1
    at next (<anonymous>)
    at step (/Applications/Atom Beta.app/Contents/Resources/app/node_modules/github/lib/git-shell-out-strategy.js:103:1)
    at /Applications/Atom Beta.app/Contents/Resources/app/node_modules/github/lib/git-shell-out-strategy.js:110:1

This is the button that fails. fails

Strangely, right clicking on the file in the "Unstaged Changes" pane and then click stage works correctly visually for the same file, but it seems that the error is still thrown in console.

This is the button that "works". working

Steps to Reproduce

  1. Make changes in a file
  2. Click file in "Unstaged Changes" list and then click "Stage All" in the top right
  3. File doesn't "close" as it usually does, and file doesn't move from "Unstaged Changes" to "Staged Changes" as it fails

Expected behavior:

File to be staged correctly as does other times and then be able to commit/push

Actual behavior:

File doesn't close or get staged, just stays where it is and then an error is thrown into Atom's console.

Reproduces how often:

Probably around 20% of times that I go to stage a file. It is linked to the file you are staging as sometimes it works perfectly. I haven't got down exactly what causes it to happen yet (it looks like something in the commit that is causing it), I'll update if I can find out more.

EDIT: Replicated it again, GIF of the issue below! may-17-2017 15-45-14

Versions

Atom    : 1.18.0-beta0
Electron: 1.3.15
Chrome  : 52.0.2743.82
Node    : 6.5.0

apm  1.18.1
npm  3.10.10
node 6.9.5 x64
python 2.7.10
git 2.11.0

DeanmvSG avatar May 17 '17 14:05 DeanmvSG

Closing as haven't been able to replicate this in a while now

DeanmvSG avatar Jul 20 '17 13:07 DeanmvSG

I am having the same error when trying to stage or unstage a file, hunk or selection from within the staged changes or unstaged changed view.

image

Uncaught (in promise) GitError: git apply --cached - in D:\SCWamp\Docs\Energy\vin exited with code 1
stdout: 
stderr: error: patch failed: app/Operations.php:476
error: app/Operations.php: patch does not apply

    at new GitError (C:\Users\SCrossan\AppData\Local\atom\app-1.18.0\resources\app\node_modules\github\lib\git-shell-out-strategy.js:90:24)
    at C:\Users\SCrossan\AppData\Local\atom\app-1.18.0\resources\app\node_modules\github\lib\git-shell-out-strategy.js:300:31
    at next (<anonymous>)
    at step (C:\Users\SCrossan\AppData\Local\atom\app-1.18.0\resources\app\node_modules\github\lib\git-shell-out-strategy.js:74:197)
    at C:\Users\SCrossan\AppData\Local\atom\app-1.18.0\resources\app\node_modules\github\lib\git-shell-out-strategy.js:74:367

scrossan-crown avatar Jul 26 '17 09:07 scrossan-crown

I suggest re-opening. I have this occur consistently with the latest beta:

Atom : 1.23.0-beta1 Electron: 1.6.15 Chrome : 56.0.2924.87 Node : 7.4.0

Uncaught (in promise) GitError: git apply --cached - in <project-dir> exited with code 1
stdout: 
stderr: error: patch failed: <file-path>:24
error: <file-path>: patch does not apply

    at new GitError (/Applications/Atom Beta.app/Contents/Resources/app/node_modules/github/lib/git-shell-out-strategy.js:104:24)
    at /Applications/Atom Beta.app/Contents/Resources/app/node_modules/github/lib/git-shell-out-strategy.js:353:33
    at Generator.next (<anonymous>)
    at step (/Applications/Atom Beta.app/Contents/Resources/app/node_modules/github/lib/git-shell-out-strategy.js:92:197)
    at /Applications/Atom Beta.app/Contents/Resources/app/node_modules/github/lib/git-shell-out-strategy.js:92:367

danielsharvey avatar Dec 03 '17 07:12 danielsharvey

I'm also hitting this when attempting to stage a specific line in a file.

Edit: After staging the parts I needed in a separate tool (GitKraken), it's interesting to note that Atom isn't updating the Staged Changes view. This may be an issue with the cache having an improper state that when it tries to apply to the real file on disk git rejects it?

Arcanemagus avatar Dec 04 '17 21:12 Arcanemagus

I get the same issue staging and discarding hunks in a PHP file with 1.23.3.

ericmason avatar Feb 12 '18 21:02 ericmason

It looks like the git command used has a few more arguments, but is still the same in essence:

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 Z:\the\project\path\folder exited with code 1
stdout: 
stderr: error: patch failed: sub/folder/script.pl:52
error: sub/folder/script.pl: patch does not apply

    at new GitError (C:\Users\abneyl\AppData\Local\atom\app-1.25.0-beta2\resources\app\node_modules\github\lib\git-shell-out-strategy.js:104:24)
    at C:\Users\abneyl\AppData\Local\atom\app-1.25.0-beta2\resources\app\node_modules\github\lib\git-shell-out-strategy.js:368:33
    at Generator.next (<anonymous>)
    at step (C:\Users\abneyl\AppData\Local\atom\app-1.25.0-beta2\resources\app\node_modules\github\lib\git-shell-out-strategy.js:92:197)
    at C:\Users\abneyl\AppData\Local\atom\app-1.25.0-beta2\resources\app\node_modules\github\lib\git-shell-out-strategy.js:92:367
    at <anonymous>

[email protected] in Atom v1.25.0-beta2.

Arcanemagus avatar Feb 26 '18 21:02 Arcanemagus

I've been getting this intermittently for a very long time - currently on 1.27.2 on Windows; github version 0.14.5. In my case, I can always stage whole files, but when I try to stage a hunk or a selection, I sometimes get

<embedded>:191381 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 C:\Users\<username>\Files\GithubWorkspace\<project> exited with code 1
stdout: 
stderr: error: patch failed: <project>/<file>:1
error: <project>/<file>: patch does not apply

I'm very interested to know if anyone has a workaround. It seems to "stick" for particular projects/repos.

cemulate avatar Jun 17 '18 23:06 cemulate

I just found atom/github#1450, which is the likely culprit for this. Indeed my files affected by this all have CRLF line endings.

cemulate avatar Jun 24 '18 04:06 cemulate

Same for me here. Has anyone been able to find a solution ?

dmenig avatar Apr 17 '19 08:04 dmenig

I'm seeing this issue too and am keen to know if there's a solution out there. Changing line ending format from CRLF to LF bypasses the issue, but not an ideal solution.

simonlayfield avatar Oct 02 '19 14:10 simonlayfield

Same error. In my case I had to change the line ending to LF, and commit the changes before being able to stage them line by line. The error seems to be caused by the ending line "\r\n"

emirhg avatar Nov 16 '20 22:11 emirhg

Still a problem in 2022. CRLF makes me unable to stage single lines.

ath88 avatar Jun 17 '22 08:06 ath88