lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 1 | # GitHub Notes |
| 2 | |
| 3 | The OpenTitan source tree is maintained on GitHub in a [monolithic repository](https://github.com/lowRISC/opentitan) called opentitan. |
| 4 | |
Greg Chadwick | 567cfd6 | 2019-10-31 16:15:33 +0000 | [diff] [blame] | 5 | These notes are for people who intend to contribute back to OpenTitan (based on |
| 6 | notes taken by a relatively inexperienced git user). If you don't intend to do |
| 7 | this you can simply clone the main repository, instructions are in [install |
| 8 | instructions]({{< relref "install_instructions" >}}) and this document can be ignored.There |
| 9 | is much more to using git, a possible next step is to reference [Resources to |
| 10 | learn Git](https://try.github.io/). |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 11 | |
| 12 | ## Getting a working repository |
| 13 | |
Philipp Wagner | 14a3fee | 2019-11-21 10:07:02 +0000 | [diff] [blame] | 14 | To develop in the repository you will need to get a copy on your local |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 15 | machine. To allow contributions to be made back to the main repo |
| 16 | (through a process called a Pull Request) you need to first make your |
Philipp Wagner | 14a3fee | 2019-11-21 10:07:02 +0000 | [diff] [blame] | 17 | own copy of the repository on GitHub then transfer that to your local |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 18 | machine. |
| 19 | |
| 20 | You will need to log in to GitHub, go to the [opentitan repository](https://github.com/lowRISC/opentitan) and click on |
| 21 | "Fork". This will generate a copy in your GitHub area that you can |
| 22 | use. |
| 23 | |
| 24 | Then setup git on your local machine and set some standard parameters |
| 25 | to ensure your name and email are correctly inserted. These commands |
| 26 | set them globally for all your use of git on the local machine so you |
| 27 | may have done this step already, there is no need to repeat it. (See |
| 28 | below if you want to use a different email address for this repo.) |
| 29 | |
| 30 | Check the parameters: |
| 31 | ```console |
| 32 | $ git config -l |
| 33 | ``` |
| 34 | |
| 35 | And if they do not exist then set them: |
| 36 | |
| 37 | ```console |
| 38 | $ git config --global user.name "My Name" |
| 39 | $ git config --global user.email "my_name@email.com" |
| 40 | ``` |
| 41 | |
| 42 | `git` will take care of prompting for your GitHub user name and |
| 43 | password when it is required, but it can be useful to allow it to |
| 44 | cache these credentials (set here to an hour using the timeout in |
| 45 | seconds) so you don't have to enter every time: |
| 46 | |
| 47 | ```console |
| 48 | $ git config --global credential.helper 'cache --timeout=3600' |
| 49 | ``` |
| 50 | |
Philipp Wagner | 14a3fee | 2019-11-21 10:07:02 +0000 | [diff] [blame] | 51 | Now make a local copy of your GitHub copy of the repository and let git know |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 52 | that it is derived from the **upstream** lowRISC repo: |
| 53 | |
| 54 | ```console |
Philipp Wagner | 14a3fee | 2019-11-21 10:07:02 +0000 | [diff] [blame] | 55 | $ cd <where the repository should go> |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 56 | $ git clone https://github.com/$GITHUB_USER/opentitan.git |
| 57 | $ cd opentitan |
| 58 | $ git remote add upstream https://github.com/lowRISC/opentitan.git |
Philipp Wagner | 9614a83 | 2019-08-31 13:18:08 +0100 | [diff] [blame] | 59 | $ git fetch upstream |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 60 | $ git remote -v |
| 61 | ``` |
| 62 | |
| 63 | The `git remote -v` should give your GitHub copy as **origin** and the |
| 64 | lowRISC one as **upstream**. Making this link will allow you to keep your |
| 65 | local and GitHub repos up to date with the lowRISC one. |
| 66 | |
Philipp Wagner | 14a3fee | 2019-11-21 10:07:02 +0000 | [diff] [blame] | 67 | If you want a different email address (or name) for the lowRISC repository then |
| 68 | you can set it locally in the repository (similar to above but without the |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 69 | --global flag). This command must be executed from a directory inside |
| 70 | the local copy of the repo. (There is no need for the first `cd` if |
| 71 | you are following the previous step.) |
| 72 | |
| 73 | |
| 74 | ```console |
| 75 | $ cd opentitan |
| 76 | $ git config user.email "my_name@lowrisc.org" |
| 77 | ``` |
| 78 | |
| 79 | ## Working in your local repo |
| 80 | |
Philipp Wagner | 14a3fee | 2019-11-21 10:07:02 +0000 | [diff] [blame] | 81 | The repository that you have created locally will initially be on the |
Scott Johnson | fe79c4b | 2020-07-08 10:31:08 -0700 | [diff] [blame] | 82 | `master` branch. In general you should not make changes on this |
Philipp Wagner | 14a3fee | 2019-11-21 10:07:02 +0000 | [diff] [blame] | 83 | branch, just use it to track your GitHub repository and synchronize with the |
Scott Johnson | fe79c4b | 2020-07-08 10:31:08 -0700 | [diff] [blame] | 84 | main lowRISC repository. |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 85 | |
| 86 | The typical workflow is to make your own branch which it is |
| 87 | conventional to name based on the change you are making: |
| 88 | |
| 89 | ```console |
| 90 | $ git checkout -b forchange |
| 91 | $ git status |
| 92 | ``` |
| 93 | |
| 94 | The status will initially indicate there are no changes, but as you |
| 95 | add, delete or edit files it will let you know the state of things. |
| 96 | |
Philipp Wagner | 14a3fee | 2019-11-21 10:07:02 +0000 | [diff] [blame] | 97 | Once you are happy with your changes, commit them to the local repository by adding the files to the changes (if things are clean you can add using `git commit -a -s` instead of a number of `add` commands): |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 98 | |
| 99 | ```console |
| 100 | $ git add... |
Alex Bradbury | 8d5327e | 2019-11-05 10:50:00 +0000 | [diff] [blame] | 101 | $ git commit -s |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 102 | ``` |
| 103 | |
| 104 | The commit will make you add a message. The first line of this is a |
| 105 | short summary of the change. It should be prefixed with a word in |
| 106 | square brackets indicating the area being changed, typically the IP or |
| 107 | Tool name. For example: |
| 108 | |
Eunchan Kim | 7b6891a | 2019-11-06 12:11:52 -0800 | [diff] [blame] | 109 | ```console |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 110 | [doc/um] Add notes on using GitHub and the repo |
| 111 | ``` |
| 112 | |
| 113 | After this there should be a blank line and the main description of |
| 114 | the change. If you are fixing an issue then add a line at the end of |
| 115 | the message `Fixes #nn` where `nn` is the issue number. This will link |
| 116 | the fix and close out the issue when it is added to the lowRISC repo. |
Eunchan Kim | dae614b | 2019-10-09 10:36:40 -0700 | [diff] [blame] | 117 | If the change is an attempted fix that has not yet had confirmation from |
| 118 | verification engineers, it should not close the related issue. In this case, |
| 119 | write `Related to #nn` in the commit message rather than `Fixes #nn`. |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 120 | |
Alex Bradbury | 8d5327e | 2019-11-05 10:50:00 +0000 | [diff] [blame] | 121 | The commit message will end with a "Signed-off-by" line inserted by `git` due to using the `-s` option to `git commit`. |
| 122 | Adding this line certifies you agree to the statement in [CONTRIBUTING.md](https://github.com/lowRISC/opentitan/blob/master/CONTRIBUTING.md), indicating your contribution is made under our Contributor License Agreement. |
| 123 | |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 124 | When you have finished everything locally (it is good practice to do a |
| 125 | status check to ensure things are clean) you can push your branch (eg |
Philipp Wagner | 14a3fee | 2019-11-21 10:07:02 +0000 | [diff] [blame] | 126 | forchange) to **your** GitHub repository (the **origin**): |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 127 | |
| 128 | ```console |
| 129 | $ git status |
| 130 | $ git push origin forchange |
| 131 | ``` |
| 132 | |
Philipp Wagner | 14a3fee | 2019-11-21 10:07:02 +0000 | [diff] [blame] | 133 | Then you need to go to your repository in GitHub and either select branch |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 134 | from the pulldown or often there is a status message that you can |
| 135 | click on, review the changes and make a Pull Request. You can add |
| 136 | reviewers and get your change reviewed. |
| 137 | |
| 138 | If you need to make changes to satisfy the reviews then you do that in |
Philipp Wagner | 14a3fee | 2019-11-21 10:07:02 +0000 | [diff] [blame] | 139 | your local repository on the same branch. You will need to `add` files and |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 140 | commit again. It is normally best to squash your changes into a single |
| 141 | commit by doing it with `--amend` which will give you a chance to edit |
| 142 | the message. If you do this you need to force `-f` the push back to |
| 143 | your repo. |
| 144 | |
| 145 | ```console |
| 146 | $ git add... |
| 147 | $ git commit --amend |
| 148 | $ git status |
| 149 | $ git push -f origin forchange |
| 150 | ``` |
| 151 | |
Eunchan Kim | dae614b | 2019-10-09 10:36:40 -0700 | [diff] [blame] | 152 | Once the reviewers are happy you can "Rebase and Merge" the Pull |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 153 | Request on GitHub, delete the branch there (it offers to do this when |
Philipp Wagner | 14a3fee | 2019-11-21 10:07:02 +0000 | [diff] [blame] | 154 | you do the merge). You can delete the branch in your local repository with: |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 155 | |
| 156 | ```console |
| 157 | $ git checkout master |
| 158 | $ git branch -D forchange |
| 159 | ``` |
| 160 | |
Eunchan Kim | dae614b | 2019-10-09 10:36:40 -0700 | [diff] [blame] | 161 | When a Pull Request contain multiple commits, those commits should be logically |
| 162 | independent. Interactive rebase can be used to manipulate commits in a pull |
| 163 | request to achieve that goal. Commonly, it might be used to squash commits that |
| 164 | fix up issues reported during review back into the relevant commit. |
| 165 | |
| 166 | ```console |
| 167 | $ git rebase -i `git merge-base {current_branch} master` |
| 168 | ``` |
| 169 | |
| 170 | Then, an editor will open. Follow the instructions given there, to reorder and |
| 171 | combine commits, or to change the commit message. Then update the PR branch in |
Philipp Wagner | 14a3fee | 2019-11-21 10:07:02 +0000 | [diff] [blame] | 172 | the GitHub remote repository. |
Eunchan Kim | dae614b | 2019-10-09 10:36:40 -0700 | [diff] [blame] | 173 | |
| 174 | ```console |
| 175 | $ git push -f origin HEAD |
| 176 | ``` |
| 177 | |
Alex Bradbury | 8d5327e | 2019-11-05 10:50:00 +0000 | [diff] [blame] | 178 | ## Automatically adding a Signed-off-by line for your commits |
| 179 | |
| 180 | One option to avoid having to remember to add `-s` to `git commit` is to configure `git` to append it to your commit messages for you. |
| 181 | This can be done using an executable hook. |
| 182 | An appropriate hook can be installed by executing this from the root of your repository checkout: |
| 183 | |
| 184 | ```console |
| 185 | $ cat <<"EOF" > .git/hooks/prepare-commit-msg |
| 186 | #!/bin/sh |
| 187 | |
| 188 | # Add a Signed-off-by line to the commit message if not already present. |
| 189 | git interpret-trailers --if-exists doNothing --trailer \ |
| 190 | "Signed-off-by: $(git config user.name) <$(git config user.email)>" \ |
| 191 | --in-place "$1" |
| 192 | EOF |
| 193 | $ chmod +x .git/hooks/prepare-commit-msg |
| 194 | ``` |
| 195 | |
Philipp Wagner | 14a3fee | 2019-11-21 10:07:02 +0000 | [diff] [blame] | 196 | ## Update your repository with changes in the lowRISC repo |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 197 | |
| 198 | There is a little work to do to keep everything in sync. Normally you |
Scott Johnson | fe79c4b | 2020-07-08 10:31:08 -0700 | [diff] [blame] | 199 | want to first get your local repository `master` branch up to date with the |
Philipp Wagner | 14a3fee | 2019-11-21 10:07:02 +0000 | [diff] [blame] | 200 | lowRISC repository (**upstream**) and then you use that to update your GitHub |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 201 | copy (**origin**). |
| 202 | |
| 203 | ```console |
| 204 | $ git checkout master |
| 205 | $ git pull upstream master |
| 206 | $ git push origin |
| 207 | ``` |
| 208 | |
| 209 | If you do this while you have changes on some other branch then before |
| 210 | a Pull Request will work you need to be sure your branch merges |
Scott Johnson | fe79c4b | 2020-07-08 10:31:08 -0700 | [diff] [blame] | 211 | cleanly into the new lowRISC repo. Assuming you got the local `master` |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 212 | branch up to date with the procedure above you can now **rebase** your |
Scott Johnson | fe79c4b | 2020-07-08 10:31:08 -0700 | [diff] [blame] | 213 | changes on the new `master`. Assuming you have your changes on the local |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 214 | branch `forchange`: |
| 215 | |
| 216 | ```console |
| 217 | $ git checkout forchange |
| 218 | $ git rebase master |
| 219 | ``` |
| 220 | |
| 221 | If you are lucky this will just work, it unwinds your changes, gets |
Scott Johnson | fe79c4b | 2020-07-08 10:31:08 -0700 | [diff] [blame] | 222 | the updated `master` and replays your changes. If there are conflicts |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 223 | then you need a big pot of coffee and patience (see next section). |
| 224 | |
| 225 | Once everything has rebased properly you can do |
| 226 | |
| 227 | |
| 228 | ```console |
| 229 | $ git log |
| 230 | ``` |
| 231 | |
| 232 | And see that the changes you commited on the branch are at the top of |
Scott Johnson | fe79c4b | 2020-07-08 10:31:08 -0700 | [diff] [blame] | 233 | the log followed by the latest changes on the `master` branch. |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 234 | |
| 235 | ## Dealing with conflicts after a rebase |
| 236 | |
| 237 | If a rebase fails because of conflicts between your changes and the |
| 238 | code you are rebasing to then git will leave your working directories |
| 239 | in a bit of a mess and expect you to fix it. Often the conflict is |
| 240 | simple (eg you and someone else added a new routine at the same place |
| 241 | in the file) and resolution is simple (have both in the new |
| 242 | output). Sometimes there is more to untangle if different changes were |
| 243 | done to the same routine. In either case git has marked that you are |
| 244 | in a conflict state and work is needed before you can go back to using |
| 245 | your local git tree as usual. |
| 246 | |
| 247 | The git output actually describes what to do (once you are used to how |
| 248 | to read it). For example: |
| 249 | |
Eunchan Kim | 7b6891a | 2019-11-06 12:11:52 -0800 | [diff] [blame] | 250 | ```console |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 251 | $ git rebase master |
| 252 | First, rewinding head to replay your work on top of it... |
Philipp Wagner | 14a3fee | 2019-11-21 10:07:02 +0000 | [diff] [blame] | 253 | Applying: [util][pystyle] Clean Python style in single file tools |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 254 | Using index info to reconstruct a base tree... |
| 255 | M util/diff_generated_util_output.py |
| 256 | M util/build_docs.py |
| 257 | Falling back to patching base and 3-way merge... |
| 258 | Auto-merging util/build_docs.py |
| 259 | CONFLICT (content): Merge conflict in util/build_docs.py |
| 260 | Auto-merging util/diff_generated_util_output.py |
| 261 | error: Failed to merge in the changes. |
Philipp Wagner | 14a3fee | 2019-11-21 10:07:02 +0000 | [diff] [blame] | 262 | Patch failed at 0001 [util][pystyle] Clean Python style in single file tools |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 263 | Use 'git am --show-current-patch' to see the failed patch |
| 264 | |
| 265 | Resolve all conflicts manually, mark them as resolved with |
| 266 | "git add/rm <conflicted_files>", then run "git rebase --continue". |
| 267 | You can instead skip this commit: run "git rebase --skip". |
| 268 | To abort and get back to the state before "git rebase", run "git rebase --abort". |
| 269 | ``` |
| 270 | |
| 271 | The last line of this gives the ultimate out. You can abort the rebase |
| 272 | and figure some other way to proceed. As it says, this is done with: |
| 273 | |
| 274 | ```console |
| 275 | $ git rebase --abort |
| 276 | ``` |
| 277 | |
| 278 | After executing this command you are back to a clean tree with your |
| 279 | changes intact, but they are still based on whatever the earlier state |
Philipp Wagner | 14a3fee | 2019-11-21 10:07:02 +0000 | [diff] [blame] | 280 | of the repository was. Normally you will have to resolve the conflict |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 281 | sometime, but the escape hatch can be useful if you don't have time |
| 282 | immediately! |
| 283 | |
| 284 | In the normal case, read the output to find the file with the |
| 285 | problem. In this case `Merge conflict in util/build_docs.py` (The merge |
| 286 | of `util/diff_generated_util_output.py` was successful even though it |
| 287 | is mentioned in the middle of what looks like error output.) |
| 288 | |
| 289 | If the file is opened with an editor the points at which there are |
| 290 | conflicts will have diff-style change information embedded in to them. For example: |
| 291 | |
Eunchan Kim | 7b6891a | 2019-11-06 12:11:52 -0800 | [diff] [blame] | 292 | ```console |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 293 | <<<<<<< HEAD |
| 294 | import livereload |
| 295 | |
| 296 | import docgen.generate |
| 297 | ======= |
| 298 | import docgen |
| 299 | import livereload |
Philipp Wagner | 14a3fee | 2019-11-21 10:07:02 +0000 | [diff] [blame] | 300 | >>>>>>> [util][pystyle] Clean Python style in single file tools |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 301 | |
| 302 | ``` |
| 303 | |
Scott Johnson | fe79c4b | 2020-07-08 10:31:08 -0700 | [diff] [blame] | 304 | In this case, the upstream repository's copy of `util/build_docs.py` |
| 305 | was modified to import `docgen.generate` rather than just `docgen`. |
| 306 | Because git couldn't automatically merge that change with the one |
| 307 | we made, it gave up. The code between `<<<<<<< HEAD` and `=======` |
| 308 | represents the change in the upstream repository and the code between |
| 309 | `=======` and `>>>>>>>` represents the change in our copy. |
| 310 | |
| 311 | These lines have to be edited to get the correct merged |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 312 | result and the diff markers removed. There may be multiple points in |
| 313 | the file where fixes are needed. Once all conflicts have been |
| 314 | addressed the file can be `git add`ed and once all files addressed the |
| 315 | rebase continued. |
| 316 | |
Scott Johnson | fe79c4b | 2020-07-08 10:31:08 -0700 | [diff] [blame] | 317 | |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 318 | After the fix a status report will remind you where you are. |
Eunchan Kim | 7b6891a | 2019-11-06 12:11:52 -0800 | [diff] [blame] | 319 | |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 320 | ```console |
| 321 | $ git status |
| 322 | rebase in progress; onto cb85dc4 |
| 323 | You are currently rebasing branch 'sastyle' on 'cb85dc4'. |
| 324 | (all conflicts fixed: run "git rebase --continue") |
| 325 | |
| 326 | Changes to be committed: |
| 327 | (use "git reset HEAD <file>..." to unstage) |
| 328 | |
| 329 | modified: diff_generated_util_output.py |
| 330 | modified: build_docs.py |
| 331 | |
| 332 | Changes not staged for commit: |
| 333 | (use "git add <file>..." to update what will be committed) |
| 334 | (use "git checkout -- <file>..." to discard changes in working directory) |
| 335 | |
| 336 | modified: build_docs.py |
| 337 | |
| 338 | ``` |
| 339 | |
| 340 | This gives the same instructions as the original merge failure message |
| 341 | and gives the comfort that all conflicts were fixed. To finish up you |
| 342 | need to follow the instructions. |
| 343 | |
| 344 | ```console |
| 345 | $ git add build_docs.py |
| 346 | $ git rebase --continue |
Philipp Wagner | 14a3fee | 2019-11-21 10:07:02 +0000 | [diff] [blame] | 347 | Applying: [util][pystyle] Clean Python style in single file tools |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 348 | ``` |
| 349 | |
| 350 | If there were more than one patch outstanding (which isn't usual if |
| 351 | you use the `commit --amend` flow) then you may get subsequent |
| 352 | conflicts following the `rebase --continue` as other patches are |
| 353 | replayed. |
| 354 | |
| 355 | You can check the rebase worked as expected by looking at the log to |
| 356 | see your branch is one commit (or more if there were more) ahead of |
Scott Johnson | fe79c4b | 2020-07-08 10:31:08 -0700 | [diff] [blame] | 357 | the `master` branch. |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 358 | |
| 359 | ```console |
| 360 | $ git log |
| 361 | |
| 362 | commit dd8721d2b1529c575c4aef988219fbf2ecd3fd1b (HEAD -> sastyle) |
| 363 | Author: Mark Hayter <mark.hayter@gmail.com> |
| 364 | Date: Thu Jan 10 09:41:20 2019 +0000 |
| 365 | |
Philipp Wagner | 14a3fee | 2019-11-21 10:07:02 +0000 | [diff] [blame] | 366 | [util][pystyle] Clean Python style in single file tools |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 367 | |
| 368 | Result of lintpy.py --fix on the diff and build_docs tools |
| 369 | |
| 370 | Tested with ./diff_generated_util_output.py master |
| 371 | |
| 372 | commit cb85dc42199e925ad09c45d33f6483a14764b93e (upstream/master, origin/master, origin/HEAD, master) |
| 373 | |
| 374 | ``` |
| 375 | |
| 376 | This shows the new commit (`HEAD` of the branch `sastyle`) and the |
| 377 | preceding commit is at the `master` branch (and at the same point as |
| 378 | `master` on both `origin` and `upstream` so everything is in sync at |
Scott Johnson | fe79c4b | 2020-07-08 10:31:08 -0700 | [diff] [blame] | 379 | `master`). |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 380 | |
Philipp Wagner | 14a3fee | 2019-11-21 10:07:02 +0000 | [diff] [blame] | 381 | At this point the conflicts have been cleared and the local repository can |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 382 | be used as expected. |
| 383 | |
| 384 | You may find it useful to change the default for the way git reports conflicts in a file. See [Take the pain out of git conflict resolution: use diff3](https://blog.nilbus.com/take-the-pain-out-of-git-conflict-resolution-use-diff3/) |
Cindy Chen | b52637c | 2019-10-29 17:12:32 -0700 | [diff] [blame] | 385 | |
| 386 | ## Downloading a pull request to our local repo |
| 387 | |
Philipp Wagner | 14a3fee | 2019-11-21 10:07:02 +0000 | [diff] [blame] | 388 | With the commands below, you can checkout a pull request from the upstream repository to |
Cindy Chen | b52637c | 2019-10-29 17:12:32 -0700 | [diff] [blame] | 389 | your local repo. |
Eunchan Kim | 7b6891a | 2019-11-06 12:11:52 -0800 | [diff] [blame] | 390 | |
Cindy Chen | b52637c | 2019-10-29 17:12:32 -0700 | [diff] [blame] | 391 | ```console |
| 392 | $ git fetch upstream pull/{ID}/head:{BRANCH_NAME} |
| 393 | $ # e.g. git fetch upstream pull/5/head:docgen_review |
| 394 | $ git checkout {BRANCH_NAME} |
| 395 | ``` |
| 396 | |
| 397 | ### Applying the pull request to the local commit |
| 398 | |
| 399 | In some cases, you might need to apply a pull request on top of your local commits. |
| 400 | For instance, if one user prepares a verification test case and finds a bug. |
| 401 | Another user fixed it and created a pull request. The first user needs |
| 402 | to test if the fix works on the new verification environment. |
| 403 | |
| 404 | In this case, it is recommanded to create a new branch on top of the local |
| 405 | commit and `rebase`, `cherry-pick`, or `merge` the pull request. Assume you have a branch |
| 406 | name 'br_localfix' which has an update for the verification environment. If the |
| 407 | other user created a pull request with ID #345, which has a fix for the |
| 408 | design bug, then you can apply the pull request into new branch |
| 409 | 'br_localandremote' with the following three methods: |
Eunchan Kim | 7b6891a | 2019-11-06 12:11:52 -0800 | [diff] [blame] | 410 | |
Cindy Chen | b52637c | 2019-10-29 17:12:32 -0700 | [diff] [blame] | 411 | * The `rebase` method: |
Eunchan Kim | 7b6891a | 2019-11-06 12:11:52 -0800 | [diff] [blame] | 412 | |
| 413 | ```console |
| 414 | $ git checkout -b br_localandremote br_localfix |
| 415 | $ git fetch upstream pull/345/head:pr_345 |
| 416 | $ git rebase pr_345 |
| 417 | ``` |
| 418 | |
Cindy Chen | b52637c | 2019-10-29 17:12:32 -0700 | [diff] [blame] | 419 | * The `cherry-pick` method: |
Eunchan Kim | 7b6891a | 2019-11-06 12:11:52 -0800 | [diff] [blame] | 420 | |
| 421 | ```console |
| 422 | $ git checkout -b br_localandremote br_localfix |
| 423 | $ git fetch upstream pull/345/head:pr_345 |
| 424 | $ # find the commit ID from pr_345 that you want to merge: b345232342ff |
| 425 | $ git cherry-pick b345232342ff |
| 426 | ``` |
Cindy Chen | b52637c | 2019-10-29 17:12:32 -0700 | [diff] [blame] | 427 | * The `merge` method: |
Eunchan Kim | 7b6891a | 2019-11-06 12:11:52 -0800 | [diff] [blame] | 428 | |
| 429 | ```console |
| 430 | $ git fetch upstream pull/345/head:pr_345 |
| 431 | $ git checkout -b br_localandremote br_localfix |
| 432 | $ git merge pr_345 |
| 433 | ``` |
| 434 | |
Cindy Chen | b52637c | 2019-10-29 17:12:32 -0700 | [diff] [blame] | 435 | The `rebase` method is more convenient than `cherry-pick` if you have more |
| 436 | than one commit ID to merge. The `merge` method can only be used for local |
| 437 | testing as the upstream lowRISC repository does not allow merge commits. |
| 438 | Sometimes, applying other contributor's pull request can result in conflicts |
| 439 | if both commits have the same change. In that case, you should resolve the conflicts |
| 440 | and continue the merge. Section [Dealing with conflicts after a rebase](#dealing-with-conflicts-after-a-rebase) |
| 441 | has detailed guidance on how to solve conflicts. |
| 442 | |
| 443 | ## Creating updates on top of a pending pull request |
| 444 | |
| 445 | In some cases, you might want to directly change other contributor's pull |
| 446 | request. The process is quite complicated so please follow the instruction below |
| 447 | step-by-step with caution: |
| 448 | |
| 449 | * Step 1: Checkout the other pull request branch |
Eunchan Kim | 7b6891a | 2019-11-06 12:11:52 -0800 | [diff] [blame] | 450 | |
| 451 | ```console |
| 452 | $ git fetch upstream pull/{ID}/head:{BRANCH_NAME} |
| 453 | $ git checkout {BRANCH_NAME} |
| 454 | ``` |
| 455 | |
Cindy Chen | b52637c | 2019-10-29 17:12:32 -0700 | [diff] [blame] | 456 | * Step 2: Make necessary changes |
Eunchan Kim | 7b6891a | 2019-11-06 12:11:52 -0800 | [diff] [blame] | 457 | |
| 458 | ```console |
| 459 | $ git add... |
Philipp Wagner | ff5f23c | 2019-11-14 13:58:25 +0000 | [diff] [blame] | 460 | $ git commit -m "Add CFG examples to UART specification" |
Eunchan Kim | 7b6891a | 2019-11-06 12:11:52 -0800 | [diff] [blame] | 461 | ``` |
| 462 | |
Philipp Wagner | 14a3fee | 2019-11-21 10:07:02 +0000 | [diff] [blame] | 463 | * Step 3: Create your GitHub branch for the pull request |
Eunchan Kim | 7b6891a | 2019-11-06 12:11:52 -0800 | [diff] [blame] | 464 | |
| 465 | ```console |
| 466 | $ git push -u origin {BRANCH_NAME}:<remote_branch_name> |
| 467 | ``` |
| 468 | |
| 469 | You can use any branch name for the pull request. |
| 470 | If you want to the created branch name same as local branch name, this can |
| 471 | simply be: |
| 472 | |
| 473 | ```console |
| 474 | $ git push -u origin HEAD |
| 475 | ``` |
| 476 | |
Cindy Chen | b52637c | 2019-10-29 17:12:32 -0700 | [diff] [blame] | 477 | * Step 4: Create a pull request into the other contributor's forked repository |
| 478 | |
Eunchan Kim | 7b6891a | 2019-11-06 12:11:52 -0800 | [diff] [blame] | 479 | To create a pull request in other's forked repository, you can follow the same method |
| 480 | as creating a pull request as section [Working in your local |
| 481 | repo](#working-in-your-local-repo) explained in details. |
| 482 | Once the other contributor's pull request is merged into the upstream |
| 483 | repository, you will need to create a pull request in that upstream repository |
| 484 | instead. |
Cindy Chen | b52637c | 2019-10-29 17:12:32 -0700 | [diff] [blame] | 485 | |
| 486 | These are all the steps needed. Once your pull request is reviewed and merged, you will |
| 487 | be able to see that the commit is also visible in the original pull request. |