Cli: No conflicting files after `apply` fails in `upgrade` command

Created on 13 Mar 2019  Â·  17Comments  Â·  Source: react-native-community/cli

Cross-posting from https://github.com/react-native-community/rn-diff-purge/issues/5

@Esemesek wrote:

After fail in applying diff to the repo, no conflicting files are dumped. I tried applying different patches, but none of them works. This situation happens only in some repositories, but I don't know what factor is causing the error. The repository is private, but I will try to make reproduction repository.

cc @thymikee @pvinis

bug

All 17 comments

Update: we've improved error handling in v1.4.2 to take this issue into account (see #232).

I can also consistently reproduce the the git apply failing on bigger diffs.
If anyone is interested in inspecting this – change this reference:
https://github.com/react-native-community/react-native-cli/blob/a20aad7d9a596301d9371a64e7785d67d04be9f7/packages/cli/src/commands/upgrade/upgrade.js#L18
to 'https://github.com/pvinis/rn-diff-purge' (which currently uses different diffing method resulting in a big diff). And then use the cli directly (see CONTRIBUTING.md) in a test project of your liking.

@thymikee I've tried npx @react-native-community/cli upgrade as suggested
Here is the result:

info No version passed. Fetching latest...
info Fetching diff between v0.57.4 and v0.59.0...
info Applying diff (excluding: package.json, .babelrc, .flowconfig, ios/myheartsigns.xcodeproj/project.pbxproj, ios/myheartsigns/AppDelegate.h, ios/myheartsigns/AppDelegate.m, ios/myheartsigns/main.m, ios/myheartsignsTests/myheartsignsTests.m)...
error: patch failed: android/app/build.gradle:103
Falling back to three-way merge...
error: patch failed: android/app/build.gradle:95
error: android/app/build.gradle: patch does not apply
error: patch failed: android/app/src/main/AndroidManifest.xml:1
Falling back to three-way merge...
error: patch failed: android/app/src/main/AndroidManifest.xml:1
error: android/app/src/main/AndroidManifest.xml: patch does not apply
error: patch failed: android/build.gradle:2
Falling back to three-way merge...
Applied patch to 'android/build.gradle' with conflicts.
error: patch failed: android/gradle/wrapper/gradle-wrapper.properties:2
Falling back to three-way merge...
Applied patch to 'android/gradle/wrapper/gradle-wrapper.properties' with conflicts.
Falling back to three-way merge...
Applied patch to 'babel.config.js' with conflicts.
error: patch failed: index.js:1
Falling back to three-way merge...
Applied patch to 'index.js' with conflicts.
error Automatically applying diff failed
info Here's the diff we tried to apply: https://github.com/react-native-community/rn-diff-purge/compare/version/0.57.4...version/0.59.0
info You may find release notes helpful: https://github.com/facebook/react-native/releases/tag/v0.59.0
warn Continuing after failure. Most of the files are upgraded but you will need to deal with some conflicts manually
info Installing [email protected] and its peer dependencies...
info Running "git status" to check what changed...
On branch ble-plx
Your branch is up-to-date with 'origin/ble-plx'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   package-lock.json
        modified:   package.json

warn Please run "git diff" to review the conflicts and resolve them
error Upgrade failed. Please see the messages above for details

@omatrot That is exactly the issue we are experiencing. Is your repo open sourced?

Also looks like you used version pre 1.4.2, where we improved the output To be more friendly about this scenario

Here is the new output:

info No version passed. Fetching latest...
info Fetching diff between v0.57.8 and v0.59.1...
info Applying diff (excluding: package.json, .babelrc, .flowconfig, ios/rnios23564Tests/rnios23564Tests.m)...
warning: android/app/BUCK has type 100755, expected 100644
warning: android/app/build.gradle has type 100755, expected 100644
error: patch failed: android/app/build.gradle:95
Falling back to three-way merge...
error: patch failed: android/app/build.gradle:95
error: android/app/build.gradle: patch does not apply
warning: android/app/src/main/AndroidManifest.xml has type 100755, expected 100644
error: patch failed: android/app/src/main/AndroidManifest.xml:1
Falling back to three-way merge...
error: patch failed: android/app/src/main/AndroidManifest.xml:1
error: android/app/src/main/AndroidManifest.xml: patch does not apply
warning: android/build.gradle has type 100755, expected 100644
error: patch failed: android/build.gradle:2
Falling back to three-way merge...
Applied patch to 'android/build.gradle' with conflicts.
warning: android/gradle/wrapper/gradle-wrapper.properties has type 100755, expected 100644
error: patch failed: android/gradle/wrapper/gradle-wrapper.properties:2
Falling back to three-way merge...
Applied patch to 'android/gradle/wrapper/gradle-wrapper.properties' with conflicts.
Falling back to three-way merge...
Applied patch to 'babel.config.js' with conflicts.
warning: index.js has type 100755, expected 100644
error: patch failed: index.js:1
Falling back to three-way merge...
Applied patch to 'index.js' with conflicts.
warning: ios/rnios23564.xcodeproj/project.pbxproj has type 100755, expected 100644
error: patch failed: ios/rnios23564.xcodeproj/project.pbxproj:38
Falling back to three-way merge...
Applied patch to 'ios/rnios23564.xcodeproj/project.pbxproj' with conflicts.
warning: ios/rnios23564/AppDelegate.h has type 100755, expected 100644
warning: ios/rnios23564/AppDelegate.m has type 100755, expected 100644
error: patch failed: ios/rnios23564/AppDelegate.m:14
Falling back to three-way merge...
error: patch failed: ios/rnios23564/AppDelegate.m:14
error: ios/rnios23564/AppDelegate.m: patch does not apply
warning: ios/rnios23564/main.m has type 100755, expected 100644
error Automatically applying diff failed
error Patch failed to apply for unknown reason. Please fall back to manual way of upgrading
info You may find these resources helpful:
• Release notes: https://github.com/facebook/react-native/releases/tag/v0.59.1
• Comparison between versions: https://github.com/react-native-community/rn-diff-purge/compare/version/0.57.8..version/0.59.1
• Git diff: https://github.com/react-native-community/rn-diff-purge/compare/version/0.57.8..version/0.59.1.diff
error Upgrade failed. Please see the messages above for details

Fixed in v2

I think this is happening again, with v2:

react-native upgrade --verbose
info No version passed. Fetching latest...
info Fetching diff between v0.59.8 and v0.60.3...
info Applying diff...
warn Excluding files that exist in the template, but not in your project:
  - rn/pose/.flowconfig
  - rn/pose/App.js
error Excluding files that failed to apply the diff:
  - rn/pose/.gitignore
  - rn/pose/android/app/build.gradle
  - rn/pose/android/app/src/main/java/com/pose/MainApplication.java
  - rn/pose/android/settings.gradle
  - rn/pose/ios/pose.xcodeproj/project.pbxproj
Please make sure to check the actual changes after the upgrade command is finished.
You can find them in our Upgrade Helper web app: https://react-native-community.github.io/upgrade-helper/?from=0.59.8&to=0.60.3
debug "git apply" failed. Error output:
rn/pose/tmp-upgrade-rn.patch:2470: trailing whitespace.
@rem
rn/pose/tmp-upgrade-rn.patch:2471: trailing whitespace.
@rem Copyright 2015 the original author or authors.
rn/pose/tmp-upgrade-rn.patch:2472: trailing whitespace.
@rem
rn/pose/tmp-upgrade-rn.patch:2473: trailing whitespace.
@rem Licensed under the Apache License, Version 2.0 (the "License");
rn/pose/tmp-upgrade-rn.patch:2474: trailing whitespace.
@rem you may not use this file except in compliance with the License.
error: rn/pose/.flowconfig: does not exist in index
error: patch failed: rn/pose/.gitignore:54
error: repository lacks the necessary blob to fall back on 3-way merge.
error: rn/pose/.gitignore: patch does not apply
error: rn/pose/App.js: does not exist in index
error: patch failed: rn/pose/android/app/build.gradle:126
error: repository lacks the necessary blob to fall back on 3-way merge.
error: rn/pose/android/app/build.gradle: patch does not apply
error: patch failed: rn/pose/android/app/src/main/java/com/pose/MainApplication.java:1
error: repository lacks the necessary blob to fall back on 3-way merge.
error: rn/pose/android/app/src/main/java/com/pose/MainApplication.java: patch does not apply
error: patch failed: rn/pose/android/build.gradle:13
Falling back to three-way merge...
Applied patch to 'rn/pose/android/build.gradle' with conflicts.
error: patch failed: rn/pose/android/gradle/wrapper/gradle-wrapper.properties:1
Falling back to three-way merge...
Applied patch to 'rn/pose/android/gradle/wrapper/gradle-wrapper.properties' with conflicts.
error: patch failed: rn/pose/android/settings.gradle:1
error: repository lacks the necessary blob to fall back on 3-way merge.
error: rn/pose/android/settings.gradle: patch does not apply
error: patch failed: rn/pose/ios/pose.xcodeproj/project.pbxproj:7
error: repository lacks the necessary blob to fall back on 3-way merge.
error: rn/pose/ios/pose.xcodeproj/project.pbxproj: patch does not apply

error Automatically applying diff failed. We did our best to automatically upgrade as many files as possible
error Patch failed to apply for unknown reason. Please fall back to manual way of upgrading
info You may find these resources helpful:
• Release notes: https://github.com/facebook/react-native/releases/tag/v0.60.3
• Manual Upgrade Helper: https://react-native-community.github.io/upgrade-helper/?from=0.59.8&to=0.60.3
• Git diff: https://raw.githubusercontent.com/react-native-community/rn-diff-purge/diffs/diffs/0.59.8..0.60.3.diff
error Upgrade failed. Please see the messages above for details

Had the same problem.

My assumptions:

Looks like it uses git apply behind the scene which relies on commit indexes in order to be able to deliver 3way merges (3 ways as local, patch and remote). Thus it needs the commit indexes that are referenced from the patch to be available from inside the current repo in order to generate that 3way merge (cf. https://stackoverflow.com/a/33577782/939741).

Unfortunately, those commits aren't available in the current git repository because they are from the https://github.com/react-native-community/rn-diff-purge/ repository. Indeed, the patch has been generated from there.

Therefore, in order to apply the patch, one have to find a way to substitute the git apply command with the patch command. The latter doesn't take commit indexes into account.

Here is a way to do so:

  1. During npx react-native upgrade you get a link to the raw diff in the log. ie. https://raw.githubusercontent.com/react-native-community/rn-diff-purge/diffs/diffs/0.60.0-rc.2..0.61.2.diff
    Note the usage of npx to ensure you use the latest version of react-native-cli.
  2. Download that patch. ie. curl https://raw.githubusercontent.com/react-native-community/rn-diff-purge/diffs/diffs/0.60.0-rc.2..0.61.2.diff > mypatch.patch
  3. Replace patch idiosyncraties with your projects' one ie. sed -i -- 's;com/rndiffapp;org/pnplab/flux;g' mypatch.patch ; sed -i -- 's;RnDiffApp;Flux;g' mypatch.patch (replace with your android app path).
  4. Apply it with apply cf. patch -p2 < mypatch.patch
  5. Do your manual chore from here:

    • Check all the new files that finish by .rej, open them and apply the changes manually.

    • Remove all the .rej and .orig files

    • Patching is done! You can yarn or npm install.

For copy-past addicts (lines have to be adapted though):

# Apply patch manually
curl https://raw.githubusercontent.com/react-native-community/rn-diff-purge/diffs/diffs/0.60.0-rc.2..0.61.2.diff > mypatch.patch
sed -i -- 's;com/rndiffapp;org/pnplab/flux;g' mypatch.patch
sed -i -- 's;RnDiffApp;Flux;g' mypatch.patch
patch -p2 < mypatch.patch

# Do the manual chores
# ...see comment.

@nuKs that's interesting. Would you be interested in sending a PR fixing this?

Big deadline ongoing.

I'll gladly do that once I have a bit of free time though (from november 6th and on hopefully) :)

I got this error when trying to upgrade react native from 0.59.1 to 0.61.5. Any estimation on when it is going to be solved?

@JoaoLSA RN 0.59 uses an old version of CLI, where it's not fixed and we're not planning to touch it anymore. You can use the newest CLI directly:

npx @react-native-community/cli upgrade

Also @JoaoLSA try to go to 0.61 in two steps. Go to 0.60 first.

I got the same error when using npx @react-native-community/cli upgrade to migrate from 0.57.1 to 0.61.5

57?! I hope you mean 59. In any case, I would also suggest to use https://react-native-community.github.io/upgrade-helper/ and try to go one minor at a time. 57->58, then 59, then 60, then 61.

I'm now upgrading from 0.57 because I have two apps. I will upgrade it manually as the cli didn't work

Was this page helpful?
0 / 5 - 0 ratings