Toby Huang | 5105f81 | 2019-08-08 23:47:57 | [diff] [blame] | 1 | # Commit Checklist for Chromium Workflow |
| 2 | |
Toby Huang | e43e5d68 | 2019-10-08 21:26:07 | [diff] [blame^] | 3 | Here is a helpful checklist to go through before uploading change lists (CLs) on |
| 4 | Gerrit, which is the code review platform for the Chromium project. This |
| 5 | checklist is designed to be streamlined. See |
| 6 | [contributing to Chromium][contributing] for a more thorough reference. The |
| 7 | intended audience is software engineers who are unfamiliar with contributing to |
| 8 | the Chromium project. |
Toby Huang | 5105f81 | 2019-08-08 23:47:57 | [diff] [blame] | 9 | |
| 10 | [TOC] |
| 11 | |
| 12 | ## 1. Create a new branch |
| 13 | |
| 14 | You should create a new branch before starting any development work. It's |
| 15 | helpful to branch early and to branch often in Git. |
| 16 | |
| 17 | git new-branch <branch_name> |
| 18 | |
| 19 | which is equivalent to |
| 20 | |
| 21 | git checkout -b <branch_name> --track origin/master |
| 22 | |
Toby Huang | ba5bbb4 | 2019-09-04 23:23:07 | [diff] [blame] | 23 | ## 2. Make your changes |
| 24 | |
| 25 | Do your thing. There's no further advice here about how to write or fix code. |
| 26 | |
| 27 | ## 3. Make sure the code builds correctly |
Toby Huang | 5105f81 | 2019-08-08 23:47:57 | [diff] [blame] | 28 | |
| 29 | After making your changes, check that common targets build correctly: |
| 30 | |
| 31 | * chrome (for Linux, ChromeOS, etc.) |
| 32 | * unit_tests |
| 33 | * browser_tests |
| 34 | |
| 35 | It's easy to inadvertently break one of the other builds you're not currently |
| 36 | working on without realizing it. Even though the Commit Queue should catch any |
| 37 | build errors, checking locally first can save you some time since the CQ Dry Run |
| 38 | can take a while. |
| 39 | |
Toby Huang | ba5bbb4 | 2019-09-04 23:23:07 | [diff] [blame] | 40 | ## 4. Test your changes |
Toby Huang | 5105f81 | 2019-08-08 23:47:57 | [diff] [blame] | 41 | |
| 42 | Make sure you hit every code path you changed. |
| 43 | |
Toby Huang | ba5bbb4 | 2019-09-04 23:23:07 | [diff] [blame] | 44 | ## 5. Write unit or browser tests for any new code |
Toby Huang | 5105f81 | 2019-08-08 23:47:57 | [diff] [blame] | 45 | |
| 46 | Consider automating any manual testing you did in the previous step. |
| 47 | |
Toby Huang | ba5bbb4 | 2019-09-04 23:23:07 | [diff] [blame] | 48 | ## 6. Ensure the code is formatted nicely |
Toby Huang | 5105f81 | 2019-08-08 23:47:57 | [diff] [blame] | 49 | |
| 50 | Run `git cl format --js`. The `--js` option also formats JavaScript changes. |
| 51 | |
Toby Huang | ba5bbb4 | 2019-09-04 23:23:07 | [diff] [blame] | 52 | ## 7. Check over your changes |
Toby Huang | 5105f81 | 2019-08-08 23:47:57 | [diff] [blame] | 53 | |
Toby Huang | e43e5d68 | 2019-10-08 21:26:07 | [diff] [blame^] | 54 | Run `git upstream-diff` to check over all of the changes you've made from the |
| 55 | most recent checkpoint on the remote repository. |
Toby Huang | 5105f81 | 2019-08-08 23:47:57 | [diff] [blame] | 56 | |
Toby Huang | ba5bbb4 | 2019-09-04 23:23:07 | [diff] [blame] | 57 | ## 8. Stage relevant files for commit |
Toby Huang | 5105f81 | 2019-08-08 23:47:57 | [diff] [blame] | 58 | |
| 59 | Run `git add <path_to_file>` for all of the relevant files you've modified. |
Toby Huang | e43e5d68 | 2019-10-08 21:26:07 | [diff] [blame^] | 60 | Unlike other version-control systems such as svn, you have to specifically `git |
| 61 | add` the files you want to commit before calling `git commit`. |
Toby Huang | 5105f81 | 2019-08-08 23:47:57 | [diff] [blame] | 62 | |
Toby Huang | ba5bbb4 | 2019-09-04 23:23:07 | [diff] [blame] | 63 | ## 9. Commit your changes |
Toby Huang | 5105f81 | 2019-08-08 23:47:57 | [diff] [blame] | 64 | |
| 65 | Run `git commit`. Here are some |
| 66 | [tips for writing good commit messages][uploading-a-change-for-review]. |
| 67 | |
Toby Huang | ba5bbb4 | 2019-09-04 23:23:07 | [diff] [blame] | 68 | ## 10. Squash your commits |
| 69 | |
| 70 | If you have many commits on your current branch, and you want to avoid some |
| 71 | nasty commit-by-commit merge conflicts in the next step, it is recommended to |
| 72 | squash your commits into a single commit. This is done by running `git rebase -i |
Toby Huang | e43e5d68 | 2019-10-08 21:26:07 | [diff] [blame^] | 73 | <upstream-branch>`. The upstream branch is usually origin/master, but check `git |
| 74 | branch -vv` to make sure. After running the git rebase command, you should see a |
| 75 | list of commits, each commit starting with the word "pick". Make sure the first |
| 76 | commit says "pick" and change the rest from "pick" to "squash". This will squash |
| 77 | each commit into the previous commit, which will continue until each commit is |
| 78 | squashed into the first commit. |
Toby Huang | ba5bbb4 | 2019-09-04 23:23:07 | [diff] [blame] | 79 | |
| 80 | ## 11. Rebase your local repository |
Toby Huang | 5105f81 | 2019-08-08 23:47:57 | [diff] [blame] | 81 | |
| 82 | Run `git rebase-update`. This command updates all of your local branches with |
| 83 | remote changes that have landed since you started development work, which |
| 84 | could've been a while ago. It also deletes any branches that match the remote |
Toby Huang | e43e5d68 | 2019-10-08 21:26:07 | [diff] [blame^] | 85 | repository, such as after the CL associated with that branch had merged. You may |
| 86 | run into rebase conflicts which should be manually fixed before proceeding with |
| 87 | `git rebase --continue`. Rebasing prevents unintended changes from creeping into |
| 88 | your CL. |
Toby Huang | 5105f81 | 2019-08-08 23:47:57 | [diff] [blame] | 89 | |
| 90 | Note that rebasing has the potential to break your build, so you might want to |
| 91 | try re-building afterwards. |
| 92 | |
Toby Huang | ba5bbb4 | 2019-09-04 23:23:07 | [diff] [blame] | 93 | ## 12. Upload the CL to Gerrit |
Toby Huang | 5105f81 | 2019-08-08 23:47:57 | [diff] [blame] | 94 | |
| 95 | Run `git cl upload`. Some useful options include: |
| 96 | |
Toby Huang | e43e5d68 | 2019-10-08 21:26:07 | [diff] [blame^] | 97 | * `--cq-dry-run` (or `-d`) will set the patchset to do a CQ Dry Run. |
| 98 | * `-r <chromium_username>` will add reviewers. |
| 99 | * `-b <bug_number>` automatically populates the bug reference line of the |
| 100 | commit message. |
Toby Huang | 5105f81 | 2019-08-08 23:47:57 | [diff] [blame] | 101 | |
Toby Huang | ba5bbb4 | 2019-09-04 23:23:07 | [diff] [blame] | 102 | ## 13. Check the CL again in Gerrit |
Toby Huang | 5105f81 | 2019-08-08 23:47:57 | [diff] [blame] | 103 | |
| 104 | Run `git cl web` to go to the Gerrit URL associated with the current branch. |
Toby Huang | e43e5d68 | 2019-10-08 21:26:07 | [diff] [blame^] | 105 | Open the latest patch set and verify that all of the uploaded files are correct. |
| 106 | Click `Expand All` to check over all of the individual line-by-line changes |
| 107 | again. |
Toby Huang | 5105f81 | 2019-08-08 23:47:57 | [diff] [blame] | 108 | |
Toby Huang | ba5bbb4 | 2019-09-04 23:23:07 | [diff] [blame] | 109 | ## 14. Make sure all auto-regression tests pass |
Toby Huang | 5105f81 | 2019-08-08 23:47:57 | [diff] [blame] | 110 | |
| 111 | Click `CQ Dry Run`. Fix any errors because otherwise the CL won't pass the |
| 112 | commit queue (CQ) checks. Consider waiting for the CQ Dry Run to pass before |
| 113 | notifying your reviewers, in case the results require major changes in your CL. |
| 114 | |
Toby Huang | ba5bbb4 | 2019-09-04 23:23:07 | [diff] [blame] | 115 | ## 15. Add reviewers to review your code |
Toby Huang | 5105f81 | 2019-08-08 23:47:57 | [diff] [blame] | 116 | |
| 117 | Click `Find Owners` or run `git cl owners` to find file owners to review your |
| 118 | code and instruct them about which parts you want them to focus on. Add anyone |
Toby Huang | e43e5d68 | 2019-10-08 21:26:07 | [diff] [blame^] | 119 | else you think should review your code. The blame functionality in Code Search |
| 120 | is a good way to identify reviewers who may be familiar with the parts of code |
| 121 | your CL touches. For your CL to land, you need an approval from an owner for |
| 122 | each file you've changed, unless you are an owner of some files, in which case |
| 123 | you don't need separate owner approval for those files. |
Toby Huang | 5105f81 | 2019-08-08 23:47:57 | [diff] [blame] | 124 | |
Toby Huang | ba5bbb4 | 2019-09-04 23:23:07 | [diff] [blame] | 125 | ## 16. Implement feedback from your reviewers |
Toby Huang | 5105f81 | 2019-08-08 23:47:57 | [diff] [blame] | 126 | |
| 127 | Then go through this commit checklist again. Reply to all comments from the |
| 128 | reviewers on Gerrit and mark all resolved issues as resolved (clicking `Done` or |
| 129 | `Ack` will do this automatically). Click `Reply` to ensure that your reviewers |
| 130 | receive a notification. Doing this signals that your CL is ready for review |
| 131 | again, since the assumption is that your CL is not ready for review until you |
| 132 | hit reply. |
| 133 | |
Toby Huang | ba5bbb4 | 2019-09-04 23:23:07 | [diff] [blame] | 134 | ## 17. Land your CL |
Toby Huang | 5105f81 | 2019-08-08 23:47:57 | [diff] [blame] | 135 | |
| 136 | Once you have obtained a Looks Good To Me (LGTM), which is reflected by a |
| 137 | Code-Review+1 in Gerrit, from at least one owner for each file, then you have |
| 138 | the minimum prerequisite to land your changes. It may be helpful to wait for all |
| 139 | of your reviewers to approve your changes as well, even if they're not owners. |
| 140 | Click `Submit to CQ` to try your change in the commit queue (CQ), which will |
| 141 | land it if successful. |
| 142 | |
| 143 | After your CL is landed, you can use `git rebase-update` or `git cl archive` to |
| 144 | clean up your local branches. |
| 145 | |
| 146 | [//]: # (the reference link section should be alphabetically sorted) |
| 147 | [contributing]: contributing.md |
| 148 | [uploading-a-change-for-review]: contributing.md#Uploading-a-change-for-review |