Dan Morrill | a9788cd | 2009-11-15 11:49:30 -0800 | [diff] [blame] | 1 | page.title=Android Contributors' Workflow |
Dan Morrill | 3cd199f | 2009-11-06 14:04:16 -0800 | [diff] [blame] | 2 | doc.type=source |
| 3 | @jd:body |
Dan Morrill | 3cd199f | 2009-11-06 14:04:16 -0800 | [diff] [blame] | 4 | <br>This page describes how to record changes to the Android files on your local client, upload those changes to the code-review server, and use Gerrit to track changes.<br><h2> |
| 5 | Prerequisites</h2> |
Dan Morrill | a9788cd | 2009-11-15 11:49:30 -0800 | [diff] [blame] | 6 | Before you follow the instructions on this page, you will need to set up your |
| 7 | local working environment and get the Android source files. For instructions, |
| 8 | see <a href="{@docRoot}source/download.html">Get source</a> |
| 9 | .<br><br>Other recommended reading:<br><ul><li>For an overview of the code |
| 10 | contribution and review process, see <a |
Dan Morrill | 55de681 | 2009-11-15 15:46:36 -0800 | [diff] [blame] | 11 | href="{@docRoot}source/life-of-a-patch.html">Life of a Patch</a>.</li> |
| 12 | <li>For details about Repo, see <a href="{@docRoot}source/git-repo.html">Using Repo and Git</a>.<br></li> |
Dan Morrill | a9788cd | 2009-11-15 11:49:30 -0800 | [diff] [blame] | 13 | <li>For information about the different roles you can play within the Android |
Dan Morrill | 55de681 | 2009-11-15 15:46:36 -0800 | [diff] [blame] | 14 | Open Source community, see <a href="{@docRoot}source/roles.html">Project roles</a>.</li> |
Dan Morrill | a9788cd | 2009-11-15 11:49:30 -0800 | [diff] [blame] | 15 | <li>If you plan to contribute code to the Android platform, be sure to read |
| 16 | the <a href="{@docRoot}source/licenses.html">AOSP's licensing information</a>.</li> |
Dan Morrill | 3cd199f | 2009-11-06 14:04:16 -0800 | [diff] [blame] | 17 | </ul> |
| 18 | <h2> |
| 19 | Working with the code</h2> |
Dan Morrill | a9788cd | 2009-11-15 11:49:30 -0800 | [diff] [blame] | 20 | First, download the source into your working directory, as described in <a |
| 21 | href="{@docRoot}source/download.html">Get source</a> |
| 22 | . For information about how to choose which branch to use, see <a |
| 23 | href="{@docRoot}source/code-lines.html">Android Code-Lines</a>.<br><br>To work on a particular change to the code, follow these steps:<br> |
Dan Morrill | 3cd199f | 2009-11-06 14:04:16 -0800 | [diff] [blame] | 24 | <div><img src="{@docRoot}images/submit-patches-0.png"> |
| 25 | </div> |
Dan Morrill | a9788cd | 2009-11-15 11:49:30 -0800 | [diff] [blame] | 26 | <ol><li>Use repo start <i>branchname</i> |
Dan Morrill | 3cd199f | 2009-11-06 14:04:16 -0800 | [diff] [blame] | 27 | to start a new topic branch.</li> |
| 28 | <li>Edit the files.<br></li> |
| 29 | <li><span>Use git add to stage changes.</span> |
| 30 | <span>(Sometimes optional.)</span> |
| 31 | <br></li> |
| 32 | <li>Use repo status and git diff to view the status of your files.<i><br></i> |
| 33 | </li> |
| 34 | <li>Use git commit to commit changes.<br></li> |
| 35 | <li><span>Use repo upload to upload changes to the review server</span> |
| 36 | .<br></li> |
| 37 | </ol> |
| 38 | You can track your uploaded changes using the Gerrit code-review tool. When it's time to work on the code again, run repo sync, then go back to step 1 above and start another topic branch.<br><br>The steps will not always come in the order shown--for example, you might run git diff at several points in the process.<br><br><h3> |
| 39 | Starting a topic branch</h3> |
Dan Morrill | 55de681 | 2009-11-15 15:46:36 -0800 | [diff] [blame] | 40 | Start a topic branch called default in your local work environment:<br><br>$ repo start default <br><br>For more about topic branches, see <a href="{@docRoot}source/git-repo.html">Using Repo and Git</a>.<br><h3> |
Dan Morrill | 3cd199f | 2009-11-06 14:04:16 -0800 | [diff] [blame] | 41 | Editing the files</h3> |
| 42 | You do not need to check files out before working on them. Edit the files using vim, emacs, or any other editor.<br><br><h3> |
| 43 | Staging changes</h3> |
| 44 | To indicate that every new and modified file in your working directory should be "staged" for inclusion in the next commit, run git add without any arguments. You can also specify files or filetypes. For example, the following command would stage all the new and modified files under the bionic directory and its subdirectories:<br><br>$ git add bionic/*<br><br>Run git help add to see more ways to use git add.<br><br><b>When is git add optional?<br></b> |
| 45 | <br>If you add new files, you must stage them using git add before you run git commit. However, if you are only modifying or deleting files, you can skip git add if you use the -a option with git commit. For more details, see the "Committing changes" section further down.<br><br><h3> |
Dan Morrill | a9788cd | 2009-11-15 11:49:30 -0800 | [diff] [blame] | 46 | Using repo status <br></h3> |
Dan Morrill | 55de681 | 2009-11-15 15:46:36 -0800 | [diff] [blame] | 47 | To see the status of the current branch, run <br><br>$ repo status .<br><br>For information about how to interpret the results of repo status, see <a href="{@docRoot}source/git-repo.html#TOC-status">Using Repo and Git</a>.<br><br><h3> |
Dan Morrill | 3cd199f | 2009-11-06 14:04:16 -0800 | [diff] [blame] | 48 | Using git diff</h3> |
Dan Morrill | a9788cd | 2009-11-15 11:49:30 -0800 | [diff] [blame] | 49 | To see uncommitted changes, cd into the project directory and run <br><br>$ git |
| 50 | diff <br><br>Without any arguments, git diff will show you the differences |
Dan Morrill | 3cd199f | 2009-11-06 14:04:16 -0800 | [diff] [blame] | 51 | between the files in your working directory and the committed |
| 52 | files.<br><div><br><div><img src="{@docRoot}images/submit-patches-1.png"> |
| 53 | </div> |
| 54 | <br></div> |
| 55 | <div>If you add the --cached option, git diff will show you the differences between the files in your working directory and the staged files.<br><br></div> |
Dan Morrill | a9788cd | 2009-11-15 11:49:30 -0800 | [diff] [blame] | 56 | To see every edit that would go into the commit if you were to commit right now, make sure you are in the project directory and then run <br><br>$ git diff --cached <br><br><h3> |
Dan Morrill | 3cd199f | 2009-11-06 14:04:16 -0800 | [diff] [blame] | 57 | Committing changes</h3> |
| 58 | At intervals while you are working, commit your edits by using git commit from within the project directory:<br><span>$ cd ~/mydroid/<i>project-name</i> |
| 59 | </span> |
| 60 | <span><br>$ git commit</span> |
Dan Morrill | a9788cd | 2009-11-15 11:49:30 -0800 | [diff] [blame] | 61 | <br><br>Every file that you staged using git add will be included in this commit.<br><br>If you have not added any new files that you want to commit, you can skip git add and simply run <br><br>$ git commit -a <br><br>The -a option will stage all the files you have modified or deleted and include them in this commit. (If you have added new files and want them included in the commit, you will need to use git add before you run git commit.)<br><br>If commit <span></span> |
Dan Morrill | 3cd199f | 2009-11-06 14:04:16 -0800 | [diff] [blame] | 62 | does not find changes to be committed, it will report "nothing to commit (working directory clean)". If commit finds changes to be committed, a file will open in which you can create a log message:<br><br><div><i>Your comments about this commit go here....</i> |
Dan Morrill | a9788cd | 2009-11-15 11:49:30 -0800 | [diff] [blame] | 63 | <br># Please enter the commit message for your changes. Lines starting <br># with '#' will be ignored, and an empty message aborts the commit.<br># On branch master <br># Changes to be committed:<br>#(use "git reset HEADfile..." to unstage)<br>#<br>#new file:.repo/projects/gerrit-manifests.git/FETCH_HEAD <br>#new file:.repo/projects/gerrit-manifests.git/HEAD <br>#new file:.repo/projects/gerrit-manifests.git/config <br>.<br>.<br>.<br></div> |
Dan Morrill | 3cd199f | 2009-11-06 14:04:16 -0800 | [diff] [blame] | 64 | <br>If you do not add a log message, the commit will be aborted. Add a message and save the file.<br><br><h3> |
| 65 | Committing changes during code review</h3> |
| 66 | If you previously uploaded a change to Gerrit and the Approver has asked for changes, follow these steps:<br><ol><li>Edit the files to make the changes the Approver has requested.</li> |
| 67 | <li>Recommit your edits using the --amend flag, for example:<br><span>$ git commit -a --amend</span> |
| 68 | <br></li> |
| 69 | <li>See below to upload the changes to Gerrit again for another review cycle.</li> |
| 70 | </ol> |
| 71 | <h3> |
| 72 | Editing uploaded changes</h3> |
| 73 | To update an existing change with a new patch set:<br><ol><li>Make sure the updated branch is the currently checked out branch.</li> |
Dan Morrill | a9788cd | 2009-11-15 11:49:30 -0800 | [diff] [blame] | 74 | <li>Use repo upload --replace <i>proj1</i> |
Dan Morrill | 3cd199f | 2009-11-06 14:04:16 -0800 | [diff] [blame] | 75 | to open the change matching editor.</li> |
| 76 | <li>For each commit in the series, enter the Gerrit change Id inside the brackets.</li> |
| 77 | </ol> |
Dan Morrill | a9788cd | 2009-11-15 11:49:30 -0800 | [diff] [blame] | 78 | For more details, see <a href="{@docRoot}source/git-repo.html#TOC-upload">Using Repo and Git</a> |
Dan Morrill | 3cd199f | 2009-11-06 14:04:16 -0800 | [diff] [blame] | 79 | .<br><h3> |
| 80 | Uploading changes to Gerrit</h3> |
Dan Morrill | a9788cd | 2009-11-15 11:49:30 -0800 | [diff] [blame] | 81 | To upload your committed changes to the review server:<br><ol><li>Complete the appropriate <a href="https://review.source.android.com/#settings,new-agreement">Contributor Agreement</a> |
Dan Morrill | 3cd199f | 2009-11-06 14:04:16 -0800 | [diff] [blame] | 82 | in Gerrit, granting the Android Open Source Project permission to distribute your changes to others.</li> |
Dan Morrill | a9788cd | 2009-11-15 11:49:30 -0800 | [diff] [blame] | 83 | <li>Select an <a href="https://review.source.android.com/#settings,ssh-keys">SSH Username</a> |
| 84 | and upload your <a href="https://review.source.android.com/#settings,ssh-keys">public SSH key</a> |
Dan Morrill | 3cd199f | 2009-11-06 14:04:16 -0800 | [diff] [blame] | 85 | , so that Gerrit can identify you when you upload changes.Please note that due to a bug in repo, repo upload requires your SSH Username be the local part of your email address (the text on the left of the @ sign).<br><br>These first two steps are only necessary prior to your first change.Gerrit will remember your agreement and SSH key for subsequent changes.<br><br></li> |
| 86 | <li>Update to the latest revisions:<span><br></span> |
| 87 | <span>$</span> |
| 88 | <span>repo sync</span> |
Dan Morrill | a9788cd | 2009-11-15 11:49:30 -0800 | [diff] [blame] | 89 | <br><br>For information about how to handle sync conflicts and how Repo synchronization works, see <a href="{@docRoot}source/git-repo.html#TOC-sync">Using Repo and Git</a> |
Dan Morrill | 3cd199f | 2009-11-06 14:04:16 -0800 | [diff] [blame] | 90 | .<br><br></li> |
| 91 | <li>Run repo upload to examine the list of all available changes and select which topic branches will be uploaded to the review server:<br><span>$</span> |
| 92 | <span>repo upload</span> |
| 93 | <br><br>This will open an editor window that will let you choose which topic branch to upload.If there is only one branch available, a simple y/n prompt is instead of an editor.<br></li> |
| 94 | </ol> |
| 95 | After a change is uploaded successfully:<br><ul><li>Repo will give you a URL where you can view your submission.</li> |
| 96 | <li>The code-review system will automatically notify the project owner about your submission.</li> |
| 97 | </ul> |
Dan Morrill | a9788cd | 2009-11-15 11:49:30 -0800 | [diff] [blame] | 98 | For information about specifying particular projects with repo sync and repo upload, see <a href="{@docRoot}source/git-repo.html">Using Repo and Git</a> |
Dan Morrill | 3cd199f | 2009-11-06 14:04:16 -0800 | [diff] [blame] | 99 | .<br><br><h3> |
Dan Morrill | a9788cd | 2009-11-15 11:49:30 -0800 | [diff] [blame] | 100 | Summary example <br></h3> |
| 101 | Here is a simple example that shows how you might work with the bionic/Android.mk file:<br><br>$ cd ~/mydroid/bionic <br>$ repo start default <br>$ vi Android.mk <br><i>...edit and save the file...</i> |
| 102 | <br>$ git commit -a <br>$ repo sync <br>$ repo upload <br><i>...close the editable window that opens...</i> |
Dan Morrill | 3cd199f | 2009-11-06 14:04:16 -0800 | [diff] [blame] | 103 | <br><i>...visit the provided URL to open Gerrit and track your change...</i> |
| 104 | <br><br><h3> |
| 105 | Downloading changes from Gerrit</h3> |
Dan Morrill | a9788cd | 2009-11-15 11:49:30 -0800 | [diff] [blame] | 106 | To download a specific change from Gerrit, run <br><br>$ repo download <i>target change</i> |
| 107 | <br><br>where target is the local directory into which the change should be downloaded andchange is the change number as listed in <a href="https://review.source.android.com/">Gerrit</a> |
| 108 | . For more information, see <a href="{@docRoot}source/git-repo.html#TOC-download">Using Repo and Git</a> |
Dan Morrill | 3cd199f | 2009-11-06 14:04:16 -0800 | [diff] [blame] | 109 | .<br><br><h2> |
Dan Morrill | a9788cd | 2009-11-15 11:49:30 -0800 | [diff] [blame] | 110 | Using the Gerrit code-review tool <br></h2> |
Dan Morrill | 55de681 | 2009-11-15 15:46:36 -0800 | [diff] [blame] | 111 | You can open Gerrit by visiting whatever URL is returned to you from the repo upload command, or by visiting <a href="https://review.source.android.com/">https://review.source.android.com</a>.<br><br><h3> |
Dan Morrill | a9788cd | 2009-11-15 11:49:30 -0800 | [diff] [blame] | 112 | Viewing the status of uploaded changes <br></h3> |
| 113 | To check the status of a change that you uploaded, open <a href="https://review.source.android.com/mine">Gerrit</a> |
Dan Morrill | 3cd199f | 2009-11-06 14:04:16 -0800 | [diff] [blame] | 114 | , sign in, and click MyChanges.<br><b><br></b> |
| 115 | <h3> |
Dan Morrill | a9788cd | 2009-11-15 11:49:30 -0800 | [diff] [blame] | 116 | Reviewing a change <br></h3> |
| 117 | If you are assigned to be the Approver for a change, you need to determine the following:<br><ul><li>Does this change fit within this project's stated purpose?<br></li> |
Dan Morrill | 3cd199f | 2009-11-06 14:04:16 -0800 | [diff] [blame] | 118 | <li>Is this change valid within the project's existing architecture?</li> |
| 119 | <li>Does this change introduce design flaws that will cause problems in the future?</li> |
| 120 | <li>Does this change following the best practices that have been established for this project?</li> |
| 121 | <li>Is this change a good way to perform the described function?</li> |
| 122 | <li>Does this change introduce any security or instability risks?</li> |
| 123 | </ul> |
| 124 | If you approve of the change, you will then mark it with LGTM ("Looks Good to Me") within Gerrit.<br><br><h3> |
Dan Morrill | a9788cd | 2009-11-15 11:49:30 -0800 | [diff] [blame] | 125 | Verifying a change <br></h3> |
Dan Morrill | 3cd199f | 2009-11-06 14:04:16 -0800 | [diff] [blame] | 126 | If you are assigned to be the Verifier for a change, you need to do the following:<br><ul><li>Patch the change into your local client using one of the Download commands.</li> |
| 127 | <li>Build and test the change.</li> |
| 128 | <li>Within Gerrit use Publish Comments to mark the commit as "Verified", or "Fails" (and add a message explaining what problems were identified).<br></li> |
| 129 | </ul> |
| 130 | <h3> |
| 131 | Viewing diffs and comments</h3> |
| 132 | To open the details of the change within Gerrit, click on the "Id number" or "Subject" of a change. To compare the established code with the updated code, click the file name under "Side-by-side diffs."<br></div> |
| 133 | <div><h3> |
| 134 | Adding comments</h3> |
| 135 | Anyone in the community can use Gerrit to add inline comments to code submissions. A good comment will be relevant to the line or section of code to which it is attached in Gerrit. It might be a short and constructive suggestion about how a line of code could be improved, or it might be an explanation from the author about why the code makes sense the way it is.<br><br>To add an inline comment, double-click the relevant line of the code and write your comment in the text box that opens. When you click Save, only you can see your comment.<br><br>To publish your comments so that others using Gerrit will be able to see them, click the Publish Comments button. Your comments will be emailed to all relevant parties for this change, including the change owner, the patch set uploader (if different from the owner), and all current reviewers.<br><br><h3> |
| 136 | After a submission is approved</h3> |
| 137 | After a submission makes it through the review and verification process, Gerrit automatically merges the change into the public repository. The change will now be visible in gitweb, and others users will be able to run repo sync to pull the update into their local client.<br><br><h3> |
| 138 | How do I become a Verifier or Approver?</h3> |
Dan Morrill | a9788cd | 2009-11-15 11:49:30 -0800 | [diff] [blame] | 139 | In short, contribute high-quality code to one or more of the Android projects. |
| 140 | For details about the different roles in the Android Open Source community and |
| 141 | who plays them, see <a href="{@docRoot}source/roles.html">Project roles</a> |
Dan Morrill | 3cd199f | 2009-11-06 14:04:16 -0800 | [diff] [blame] | 142 | .<br><br><h2> |
| 143 | Using GitWeb to track patch histories</h2> |
Dan Morrill | a9788cd | 2009-11-15 11:49:30 -0800 | [diff] [blame] | 144 | To view snapshots of the files that are in the public Android repositories and view file histories, use the <a href="http://android.git.kernel.org/">Android instance of GitWeb</a> |
Dan Morrill | 3cd199f | 2009-11-06 14:04:16 -0800 | [diff] [blame] | 145 | .<br></div> |
| 146 | </div> |
| 147 | </div> |