|
| 1 | +## Upmerge.sh |
| 2 | + |
| 3 | +The upmerge script is helpful for upmerging branches in the frameworks by automatically merging some files that have conflicts. |
| 4 | + |
| 5 | +It works by using the git merge driver functionality. This allows us to automatically merge some files that normally result in conflicts because they changed on both branches, but we don't actually want to merge the changes. |
| 6 | + |
| 7 | +### Files covered: |
| 8 | + |
| 9 | +- **Podfile.lock**: We always want to take the current version and never want to merge in the one from the branch we are upmerging. The git merge driver here just always picks the current version. This site explains the git merge driver: [https://medium.com/@porteneuve/how-to-make-git-preserve-specific-files-while-merging-18c92343826b](https://medium.com/@porteneuve/how-to-make-git-preserve-specific-files-while-merging-18c92343826b) |
| 10 | +- **Podspec**: Here we only want to ignore changes to the version of the podspec. If any other changes were done to the podspec we are upmerging, we have to manually merge them. A custom python script (*podspec-merge-driver.py*) was created to handle detecting the version change. |
| 11 | + |
| 12 | +### Setup |
| 13 | +In order to have the merge drivers called for the Podfile.lock and Podspec, the following needs to be added to the *.gitattributes* of the repository. |
| 14 | + |
| 15 | +``` |
| 16 | +*.podspec merge=podspec-merge-driver |
| 17 | +Podfile.lock merge=ours-driver |
| 18 | +``` |
| 19 | + |
| 20 | +### Usage: |
| 21 | + |
| 22 | +The upmerge script takes two parameters, the branch you are upmerging and the destination branch. |
| 23 | + |
| 24 | +Example: `$ ./upmerge.sh 12.2 13.2` |
| 25 | + |
| 26 | +This upmerges *12.2/master* into *13.2/master*. The script automatically creates a *13.2/upmerge* branch, which you can then push up for a PR. |
| 27 | + |
| 28 | +## podspec-merge-driver.py |
| 29 | +This script handles when the podspec has been changed in the branch being upmerged. You don't use this script directly, it is automatically called by git during the merge. |
| 30 | + |
| 31 | +### How it works: |
| 32 | +The script takes three arguments as defined by custom merge drivers, see [https://git-scm.com/docs/gitattributes#_defining_a_custom_merge_driver](https://git-scm.com/docs/gitattributes#_defining_a_custom_merge_driver). These are the three files: ancestor, current, and other. These can be used to do a three-way merge. |
| 33 | + |
| 34 | +The script just looks at the changes done between the ancestor and other. This tells us what was done to the podspec on the branch being upmerged. |
| 35 | + |
| 36 | +Since we only want to ignore when the version number is changed in the podspec being upmerged, we create a unified diff and check the diff to make sure there are no other changes than the version number. |
| 37 | + |
| 38 | +If we detect any other changes, the script returns a non-zero code and this causes git to consider the file not merged. Manual merging of the podspec is then needed. |
0 commit comments