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

Patch is not applied under windows (not a CRLF problem) #28

Closed
roman-spiridonov opened this issue Oct 29, 2017 · 13 comments
Closed

Patch is not applied under windows (not a CRLF problem) #28

roman-spiridonov opened this issue Oct 29, 2017 · 13 comments

Comments

@roman-spiridonov
Copy link

roman-spiridonov commented Oct 29, 2017

It seems that the latest patch-package has issues working under windows (I did not check the other versions). My patch file has LF endings, the file in node_modules/ also does.

$ patch-package
patch-package: Applying patches...
**ERROR** Failed to apply patch for package jison-lex
...

Note that the patch applied successfully through

$ patch -p1 -i patches/jison-lex+0.3.4.patch
patching file node_modules/jison-lex/regexp-lexer.js

Maybe just use patch in your package? :)
That patch that I am using is here: https://github.com/roman-spiridonov/sandbox/tree/master/%5BStanford%5D%20Compilers/cool-jison.

P.S. I do not know how to create and apply the patch through git diff/git apply manually, because node_modules/ folder is in my global .gitignore. Note that patch is created just fine but I cannot apply that.

@ds300
Copy link
Owner

ds300 commented Oct 29, 2017

Thanks for the report!

Unfortunately I can't reproduce the issue on windows server 2016. What's your setup? i.e. windows version, shell, git version, etc?

What output you do get for this command:

git apply --verbose --ignore-whitespace --whitespace=nowarn patches/jison-lex+0.3.4.patch

Is it any different if you use this:

git apply --verbose --unsafe-paths --ignore-whitespace --whitespace=nowarn patches/jison-lex+0.3.4.patch

?

@roman-spiridonov
Copy link
Author

Windows 10. I am using Cygwin, but same is reproduced under windows cmd.
However, I believe my git is from Cygwin installation (apt-cyg install git).

$ which git
/usr/bin/git
$ git --version
git version 2.7.0

The output of both commands is just empty. No changes are applied to the files as well.

@ds300
Copy link
Owner

ds300 commented Oct 29, 2017

Hmm that version of git is a couple of years old. Could be the issue. The one cygwin installed for me is 2.14 and it works fine:

image

@roman-spiridonov
Copy link
Author

roman-spiridonov commented Oct 29, 2017

Well I went through all the pain of updating my cygwin 😃 (after updating git through apt-cyg it did not work because it required me to update whole cygwin) Unfortunately, the problem did not disappear. I will check tomorrow on another Win10 machine at my office.

The only difference is that both commands now report the following instead of empty report:

$ git apply --verbose --unsafe-paths --ignore-whitespace --whitespace=nowarn patches/jison-lex+0.3.4.patch
Skipped patch 'node_modules/jison-lex/regexp-lexer.js'.

@ds300
Copy link
Owner

ds300 commented Oct 29, 2017

I've done some more testing and found that it works the first time, but I get the error if I run patch-package a second time on already-patched files. Might be related, still investigating.

It just occurred to me that the git commands I gave to you wouldn't work anyway because of the fact that your npm project is not at the git root. In that case, patch-package rewrites the patch file to make the file paths relative to the git root, but maybe it's possible to avoid that rewriting by generating patch files that aren't tied to a git index. I'll look in to that as well.

Maybe you could try renaming the [Stanford] Compilers folder to something that doesn't contain any 'special' characters, then regenerating the patch file. It might be the cause of the issue on your machine.

Sorry about the trouble, and thanks again for the report!

@roman-spiridonov
Copy link
Author

roman-spiridonov commented Oct 29, 2017

wouldn't work anyway because of the fact that your npm project is not at the git root

It looks like the fact that I have a .git root in parent directory is exactly the issue (also mentioned here in the last response).

If I move the directory to a different location, or even if I simply remove the .git folder from parent, it works fine.

This behavior is fine as far as I am concerned, certainly a minor thing if you know it. I can work around that. Thanks!

@ds300
Copy link
Owner

ds300 commented Oct 29, 2017

@roman-spiridonov I released a beta version with a slightly different way to handle these kinds of situations. It would be cool if you could try it: npm i --save-dev patch-package@beta

@ds300
Copy link
Owner

ds300 commented Oct 30, 2017

I just published it under 3.5.3 - If I don't hear back from you in a few days I'll close this issue. Thanks again!

@roman-spiridonov
Copy link
Author

roman-spiridonov commented Oct 30, 2017

Unfortunately still getting the same behavior.
I am not able to apply patch because .git folder (git root) is in upper directory.
If I remove the .git folder, it works just fine.

Also, notice that additional information about .gitattributes has disappeared in the new release (maybe this is fine, just noticing).

Here is the sequence of steps to reproduce:

$ patch-package
patch-package: Applying patches...
**ERROR** Failed to apply patch for package jison-lex
  This error was caused because Git cannot apply the following patch file:
    patches/jison-lex+0.3.4.patch
  This is usually caused by inconsistent whitespace in the patch file.

$ mv ../../.git ../../.git~
$ patch-package
patch-package: Applying patches...
jison-lex@0.3.4 ✔

@ds300
Copy link
Owner

ds300 commented Oct 30, 2017

Argh :(

Can you try deleting the first two lines of the patch file (beginning with diff and index) and running the git apply command again?

git apply --verbose --ignore-whitespace --whitespace=nowarn patches/jison-lex+0.3.4.patch

I removed the .gitattributes warning because whitespace inconsistencies should no longer prevent patches from being applied.

@roman-spiridonov
Copy link
Author

It worked!

$ git apply --verbose --ignore-whitespace --whitespace=nowarn patches/jison-lex+0.3.4.patch
Checking patch [Stanford] Compilers/cool-jison/node_modules/jison-lex/regexp-lexer.js...
Applied patch [Stanford] Compilers/cool-jison/node_modules/jison-lex/regexp-lexer.js cleanly.

@ds300
Copy link
Owner

ds300 commented Oct 31, 2017

Great! I should have a permanent fix for this later tonight.

@ds300
Copy link
Owner

ds300 commented Oct 31, 2017

Published in 3.6.0 🎉

@ds300 ds300 closed this as completed Oct 31, 2017
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

2 participants