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 cannot be applied when it simultaneously renames and modifies the file #518

Open
j-piasecki opened this issue Mar 14, 2024 · 5 comments

Comments

@j-piasecki
Copy link

j-piasecki commented Mar 14, 2024

Description

Patches are successfully applied when they either only modify a specific file or change its name, but fail when doing both at the same time.

Steps to reproduce

patch-package version: 8.0.0

  1. Initialize npm project
  2. Install any package (for example react-native-wiejskie-ziemniaczki)
  3. Select any file in the installed package, rename it and modify its content (in case of the aforementioned package rename README.md to not-readme.txt and add A letter at the end of the file)
  4. Generate the patch file
  5. Reinstall node_modules
  6. Try to apply the patch
  7. The patch should get applied, but the error is shown

Interestingly, the patch is applied correctly when running npx patch-package --partial

Here is the patch file that generated error for me:

diff --git a/node_modules/react-native-wiejskie-ziemniaczki/README.md b/node_modules/react-native-wiejskie-ziemniaczki/not-readme.txt
similarity index 97%
rename from node_modules/react-native-wiejskie-ziemniaczki/README.md
rename to node_modules/react-native-wiejskie-ziemniaczki/not-readme.txt
index 7ff824b..b5b7bf7 100644
--- a/node_modules/react-native-wiejskie-ziemniaczki/README.md
+++ b/node_modules/react-native-wiejskie-ziemniaczki/not-readme.txt
@@ -1,3 +1,5 @@
 # react-native-wiejskie-ziemniaczki
 
 Documentation available on: https://wiejskieziemniaczki.pl/
+
+A
\ No newline at end of file

Workaround

Splitting the patch into two parts seems to be working well, i.e.: one patch just to rename the file and the other to modify the content.

@mdentremont
Copy link

+1 to this - I noticed the same with --partial

@mattkindy
Copy link

I ran into this, and it seems to work fine in v7.0.0

@chrispader
Copy link

chrispader commented Sep 3, 2024

I also had the same problem with v8.0.0. I tried to patch react-native-screens@3.34.0 and it fails when files are renamed. For reproduction here are two two patch files, one which is failing and the other one without renames:

rns-3.34.0-failing.patch
rns-3.34.0-succeeding.patch

@chrispader
Copy link

chrispader commented Sep 3, 2024

This can technically be fixed by adding the --no-rename option to the diff command in

const diffResult = git(
"diff",
"--cached",
"--no-color",
"--ignore-space-at-eol",
"--no-ext-diff",
"--src-prefix=a/",
"--dst-prefix=b/",

(This is how i created my succeeding patch file btw)

Is there any benefit in keeping "renames", e.g. performance? Or could we simply add this option to fix this bug?

@ucheNkadiCode
Copy link

For issues to do with makePatch -> this solution worked for me. It's been a problem since 2021

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

5 participants