|
| 1 | +# Using rn-diff-purge |
| 2 | + |
| 3 | +The git patches can be used as a replacement of `react-native-git-upgrade`. The procedure is |
| 4 | +straightforward and more trusted than using the upgrade command. |
| 5 | + |
| 6 | +## Recommended method |
| 7 | + |
| 8 | +#### 1 Check the diff |
| 9 | +Check the diff of your current version and the version you want to upgrade to. |
| 10 | + |
| 11 | +#### 2 Manually do the changes |
| 12 | +Do the changes from the diff in your project. |
| 13 | +They are usually no more than 10 lines, so it's pretty quick and easy. |
| 14 | +If it's more than that, you could try the alternative method below. |
| 15 | +:warning: In any case, make sure you pay attention to the changes made. It's always imporant to know what an upgrade actually changed. |
| 16 | + |
| 17 | +## Alternative method (using patch) |
| 18 | + |
| 19 | +#### 1 Download the git patch |
| 20 | + |
| 21 | +Download the patch for your version, for example: |
| 22 | + |
| 23 | +```shell |
| 24 | +curl https://github.com/pvinis/rn-diff-purge/compare/version/0.29.0...version/0.30.0.diff > upgrade-rn.patch |
| 25 | +``` |
| 26 | + |
| 27 | +#### 2 Prepare the patch |
| 28 | + |
| 29 | +The patch is made for the RnDiffApp located in the *RnDiffApp* folder of this repository. |
| 30 | +To use it in your own repository, some changes are needed. |
| 31 | + |
| 32 | +Don't worry about the root folder *RnDiffApp*, it can be ignored with the option `-p 2` |
| 33 | +(see https://git-scm.com/docs/git-apply) |
| 34 | + |
| 35 | +Then, some files include the name of the app in their path: |
| 36 | + |
| 37 | +- All files in the `ios` directory (example: `ios/RnDiffApp/AppDelegate.m`) |
| 38 | +- Some files in the `android` directory (example: |
| 39 | +`android/app/src/main/java/com/rndiffapp/MainActivity.java`) |
| 40 | + |
| 41 | +You have to edit the patch and replace all occurences of `ios/RnDiffApp` and `com/rndiffapp` |
| 42 | +by the name of your app. |
| 43 | + |
| 44 | +#### 3 Set up the 3-way merge |
| 45 | + |
| 46 | +By default in case of conflicts, the `git apply` command will fail and leave the files untouched. |
| 47 | +It could be interesting to fallback on a 3-way merge (option `--3way`) in order to resolve the |
| 48 | +conflicts with your favorite merge tool. |
| 49 | + |
| 50 | +To do this, git needs to know the blob referenced in the patch |
| 51 | +(line `index 4c88077..e49e881 100644` for example). So you have to add rn-diff as a remote |
| 52 | +repository and fetch it (see this [SO question](http://stackoverflow.com/questions/33577383/git-apply-3way-error-repository-lacks-the-necessary-blob-to-fall-back-on-3-way) |
| 53 | +for details). |
| 54 | + |
| 55 | +```shell |
| 56 | +git remote add rn-diff-purge https://github.com/pvinis/rn-diff-purge.git |
| 57 | +git fetch rn-diff-purge |
| 58 | +``` |
| 59 | + |
| 60 | +#### 4 Run the apply command |
| 61 | +```shell |
| 62 | +git apply upgrade-rn.patch --exclude=package.json -p 2 --3way |
| 63 | +``` |
| 64 | + |
| 65 | + |
| 66 | +### Wrap up |
| 67 | + |
| 68 | +```shell |
| 69 | +# Download the patch |
| 70 | +curl https://github.com/pvinis/rn-diff-purge/compare/version/0.29.0...version/0.30.0.diff > upgrade-rn.patch |
| 71 | + |
| 72 | +# Replace RnDiffApp occurences |
| 73 | +appNameCamelCase=MyApp |
| 74 | +appNameLowerCase=myapp |
| 75 | +sed -i "" "s-ios/RnDiffApp-ios/${appNameCamelCase}-" upgrade-rn.patch |
| 76 | +sed -i "" "s-java/com/rndiffapp-java/com/${appNameLowerCase}-" upgrade-rn.patch |
| 77 | + |
| 78 | +# Set up the 3-way merge |
| 79 | +git remote add rn-diff-purge https://github.com/pvinis/rn-diff-purge.git |
| 80 | +git fetch rn-diff-purge |
| 81 | + |
| 82 | +# Run the apply command |
| 83 | +git apply upgrade-rn.patch --exclude=package.json -p 2 --3way |
| 84 | +``` |
| 85 | + |
| 86 | +### :warning: Known issues |
| 87 | +Sometimes there are new files that reference the project's name. Whenever there is a new file, make sure to check for this, and replace it with your project's name. |
0 commit comments