|
| 1 | +# How to merge `tree-sitter-fortran` |
| 2 | + |
| 3 | +This document explains the process for updating our downstream copy of |
| 4 | +`tree-sitter-fortran` repository with the latest changes from the upstream |
| 5 | +repository, ensuring Codee remains up-to-date with new features, fixes, and |
| 6 | +improvements. |
| 7 | + |
| 8 | +## 0. Prerequisites |
| 9 | + |
| 10 | +Before merging upstream changes, ensure that the official `tree-sitter-fortran` |
| 11 | +repository is added as a Git remote and updated. If it is not already |
| 12 | +configured, you can set it up with the following commands: |
| 13 | + |
| 14 | +```bash |
| 15 | +$ git remote add tree-sitter-fortran [email protected]:stadelmanma/tree-sitter-fortran.git |
| 16 | +$ git fetch tree-sitter-fortran master |
| 17 | +``` |
| 18 | + |
| 19 | +Additionally, confirm that your local working directory is clean, with no |
| 20 | +uncommitted changes, to avoid conflicts during the merge process. |
| 21 | + |
| 22 | +## 1. Run the update script |
| 23 | + |
| 24 | +Run the [`codee/merge-upstream.sh`](/codee/merge-upstream.bash) script to check |
| 25 | +whether our [`codee/patches`](/codee/patches) are synchronized with our |
| 26 | +downstream repository. If the patches are outdated, you must update and merge |
| 27 | +them to ensure compatibility before proceeding with the main merge process. |
| 28 | + |
| 29 | +Once the patches are verified and up-to-date, the script transitions to a second |
| 30 | +stage. In this stage, the script applies the patches to our downstream project, |
| 31 | +incorporating the latest upstream changes. This process involves using `git am` |
| 32 | +to apply each patch from the `codee/patches` directory. During this step, |
| 33 | +conflicts may arise that you will need to resolve manually. |
| 34 | + |
| 35 | +To identify the source of conflicts, use `git am --show-current-patch=diff`. |
| 36 | +This command highlights the specific patch causing the issue, helping you assess |
| 37 | +and resolve the conflict efficiently. After addressing the conflict, continue |
| 38 | +applying the remaining patches until all patches have been successfully applied. |
| 39 | + |
| 40 | +After all patches are applied, your current branch should resemble the |
| 41 | +following: |
| 42 | + |
| 43 | +```bash |
| 44 | +$ git log --oneline |
| 45 | +92081e66c3b5 Baz |
| 46 | +4b5ccc6f50e4 Bar |
| 47 | +6858ad4b7960 Foo |
| 48 | +# ... |
| 49 | +dbdb4564d47c Merge tree-sitter-fortran/master |
| 50 | +# ... |
| 51 | +``` |
| 52 | + |
| 53 | +The commits following `Merge tree-sitter-fortran/master` represent the updated |
| 54 | +versions of the patches with conflicts resolved and context synchronized with |
| 55 | +the latest upstream changes. |
| 56 | + |
| 57 | +At this point, regenerate the patches to reflect the latest changes by running |
| 58 | +the appropriate script. Once regenerated, commit these changes as a fixup commit |
| 59 | +to keep the process organized. After updating the patches, you can squash all |
| 60 | +the commits created by `git am`, as the relevant changes are now captured within |
| 61 | +the patches themselves. There is no need to revisit all the upstream changes; |
| 62 | +instead, focus the review on the updates made to the patches in the fixup |
| 63 | +commit, ensuring that only the necessary adjustments are highlighted. |
| 64 | + |
| 65 | +## 2. Prepare the changes for review |
| 66 | + |
| 67 | +At this stage, it is time to prepare your branch for review. Take into |
| 68 | +consideration that a clean and well-organized commit history will significantly |
| 69 | +improve the review process and make it easier to identify meaningful changes. |
| 70 | + |
| 71 | +For example, the commit that updates the conflicting patches can be separated. |
| 72 | +This commit often contains updates to the context of the patches, but we are |
| 73 | +only interested in those where conflicts actually occurred. You can either |
| 74 | +squash these updates into the merge commit or leave them as a separate fixup |
| 75 | +commit. If you choose the latter, make sure to clearly label these commits with |
| 76 | +a message like "Do not review" so reviewers can easily skip them. |
| 77 | + |
| 78 | +Additionally, ensure that each commit has a clear and concise message, ideally |
| 79 | +with references to relevant upstream changes. Once you have organized and |
| 80 | +squashed any unnecessary commits, your branch should be ready for review. |
| 81 | +Reviewers can then focus solely on the key changes that align with the upstream |
| 82 | +updates, without being bogged down by irrelevant or redundant commits. |
| 83 | + |
| 84 | +Furthermore, during the process, you may identify commits that can be merged |
| 85 | +into the downstream project prior to the actual upstream merge. These commits |
| 86 | +could include improvements that help streamline the review process, such as |
| 87 | +migrating away from deprecated APIs that will be removed in the merge. In such |
| 88 | +cases, it is best to separate these changes and submit them as a distinct |
| 89 | +pull request, to be merged before the main upstream merge. This approach keeps |
| 90 | +the integration process clean, ensures clarity, and avoids potential |
| 91 | +complications by addressing non-merge-related improvements ahead of time. |
| 92 | + |
| 93 | +To further ease the review process, consider submitting a branch with just the |
| 94 | +merge commit. Then, create a separate branch that targets this merge branch, |
| 95 | +containing only the fixup commits. This will allow reviewers to focus |
| 96 | +exclusively on the necessary adjustments, without having to look through the |
| 97 | +upstream commit history. |
| 98 | + |
| 99 | +## 3. Cleanup and pushing the final changes |
| 100 | + |
| 101 | +Once the pull request has been fully reviewed and you have addressed all the |
| 102 | +review comments, it is time to finalize the changes and prepare them for |
| 103 | +merging. The goal here is to ensure that all necessary changes are |
| 104 | +well-organized and that the commit history is clean and concise. |
| 105 | + |
| 106 | +First, take a look at any post-merge commits and decide how to handle them. You |
| 107 | +may place them before the merge commit if applicable, or squash them into the |
| 108 | +merge commit, making sure to retain the squashed commit's message in the merge |
| 109 | +commit's message. |
| 110 | + |
| 111 | +Assuming the merge is already passing tests in the |
| 112 | +`feature/UpgradeTreeSitterFortranAuto` branch, the workflow for this step should |
| 113 | +look something like this: |
| 114 | + |
| 115 | +```bash |
| 116 | +# Branch off feature/UpgradeTreeSitterFortranAuto to update it |
| 117 | +$ git switch -c feature/UpdatedUpgradeTreeSitterFortranAuto feature/UpgradeTreeSitterFortranAuto |
| 118 | +# Merge changes from origin/codee and solve any potential conflicts with newer |
| 119 | +# codee changes |
| 120 | +$ git merge origin/codee |
| 121 | +# Create a final branch to clean things up |
| 122 | +$ git switch -c feature/FinalUpgradeTreeSitterFortranAuto origin/codee |
| 123 | +# Cherry-pick commits to place before the merge commit |
| 124 | +$ git cherry-pick <commit to place before merge> |
| 125 | +# Re-run the intended merge |
| 126 | +$ git merge --no-commit <merge commit> |
| 127 | +# If merging unrelated histories, you may need to remove deleted files |
| 128 | +$ for f in $(git status --porcelain | grep "UD" | cut -d " " -f 2); do git rm $f; done |
| 129 | +# Don't worry about conflicts; simply restore the original branch |
| 130 | +$ git restore --source feature/UpgradeTreeSitterFortranAuto . |
| 131 | +# Stage everything |
| 132 | +$ git add . |
| 133 | +# Commit to finish the merge, including messages for the remaining post-merge |
| 134 | +# commits that were not moved |
| 135 | +$ git commit |
| 136 | +# Optionally add commits that need to be placed after the merge |
| 137 | +$ git cherry-pick <commit to place after merge> |
| 138 | +# Optionally check that the new branch matches the updated branch |
| 139 | +$ git diff feature/FinalUpgradeTreeSitterFortranAuto feature/UpdatedUpgradeTreeSitterFortranAuto |
| 140 | +# Push the final branch |
| 141 | +$ git push feature/FinalUpgradeTreeSitterFortranAuto origin/feature/FinalUpgradeTreeSitterFortranAuto |
| 142 | +``` |
| 143 | + |
| 144 | +Once you have pushed your final branch, open a pull request targeting `codee` |
| 145 | +with `feature/FinalUpgradeTreeSitterFortranAuto` and request any necessary |
| 146 | +approvals. This step should be a formality as everything has already been |
| 147 | +reviewed in the previous pull request. |
| 148 | + |
| 149 | +After the pull request is approved and tests pass, push it to `codee`: |
| 150 | + |
| 151 | +```bash |
| 152 | +$ git push origin feature/FinalUpgradeTreeSitterFortranAuto:codee |
| 153 | +``` |
0 commit comments