blob: 2b7bae1e16cf353dbb66c71bce8bab7ec0f5096f [file] [log] [blame]
Dan Morrilla9788cd2009-11-15 11:49:30 -08001page.title=Android Contributors' Workflow
Dan Morrill3cd199f2009-11-06 14:04:16 -08002doc.type=source
3@jd:body
Dan Morrill3cd199f2009-11-06 14:04:16 -08004<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>
5Prerequisites</h2>
Dan Morrilla9788cd2009-11-15 11:49:30 -08006Before you follow the instructions on this page, you will need to set up your
7local working environment and get the Android source files. For instructions,
8see <a href="{@docRoot}source/download.html">Get source</a>
9.<br><br>Other recommended reading:<br><ul><li>For an overview of the code
10contribution and review process, see <a
Dan Morrill55de6812009-11-15 15:46:36 -080011href="{@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 Morrilla9788cd2009-11-15 11:49:30 -080013<li>For information about the different roles you can play within the Android
Dan Morrill55de6812009-11-15 15:46:36 -080014Open Source community, see <a href="{@docRoot}source/roles.html">Project roles</a>.</li>
Dan Morrilla9788cd2009-11-15 11:49:30 -080015<li>If you plan to contribute code to the Android platform, be sure to read
16the <a href="{@docRoot}source/licenses.html">AOSP's licensing information</a>.</li>
Dan Morrill3cd199f2009-11-06 14:04:16 -080017</ul>
18<h2>
19Working with the code</h2>
Dan Morrilla9788cd2009-11-15 11:49:30 -080020First, download the source into your working directory, as described in <a
21href="{@docRoot}source/download.html">Get source</a>
22. For information about how to choose which branch to use, see <a
23href="{@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 Morrill3cd199f2009-11-06 14:04:16 -080024<div><img src="{@docRoot}images/submit-patches-0.png">
25</div>
Dan Morrilla9788cd2009-11-15 11:49:30 -080026<ol><li>Use repo start <i>branchname</i>
Dan Morrill3cd199f2009-11-06 14:04:16 -080027to 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>
38You 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>
39Starting a topic branch</h3>
Dan Morrill55de6812009-11-15 15:46:36 -080040Start 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 Morrill3cd199f2009-11-06 14:04:16 -080041Editing the files</h3>
42You do not need to check files out before working on them. Edit the files using vim, emacs, or any other editor.<br><br><h3>
43Staging changes</h3>
44To 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 Morrilla9788cd2009-11-15 11:49:30 -080046Using repo status <br></h3>
Dan Morrill55de6812009-11-15 15:46:36 -080047To 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 Morrill3cd199f2009-11-06 14:04:16 -080048Using git diff</h3>
Dan Morrilla9788cd2009-11-15 11:49:30 -080049To see uncommitted changes, cd into the project directory and run <br><br>$ git
50diff <br><br>Without any arguments, git diff will show you the differences
Dan Morrill3cd199f2009-11-06 14:04:16 -080051between the files in your working directory and the committed
52files.<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 Morrilla9788cd2009-11-15 11:49:30 -080056To 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 Morrill3cd199f2009-11-06 14:04:16 -080057Committing changes</h3>
58At 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 Morrilla9788cd2009-11-15 11:49:30 -080061<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 Morrill3cd199f2009-11-06 14:04:16 -080062does 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 Morrilla9788cd2009-11-15 11:49:30 -080063<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 Morrill3cd199f2009-11-06 14:04:16 -080064<br>If you do not add a log message, the commit will be aborted. Add a message and save the file.<br><br><h3>
65Committing changes during code review</h3>
66If 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>
72Editing uploaded changes</h3>
73To 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 Morrilla9788cd2009-11-15 11:49:30 -080074<li>Use repo upload --replace <i>proj1</i>
Dan Morrill3cd199f2009-11-06 14:04:16 -080075to 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 Morrilla9788cd2009-11-15 11:49:30 -080078For more details, see <a href="{@docRoot}source/git-repo.html#TOC-upload">Using Repo and Git</a>
Dan Morrill3cd199f2009-11-06 14:04:16 -080079.<br><h3>
80Uploading changes to Gerrit</h3>
Dan Morrilla9788cd2009-11-15 11:49:30 -080081To 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 Morrill3cd199f2009-11-06 14:04:16 -080082in Gerrit, granting the Android Open Source Project permission to distribute your changes to others.</li>
Dan Morrilla9788cd2009-11-15 11:49:30 -080083<li>Select an <a href="https://review.source.android.com/#settings,ssh-keys">SSH Username</a>
84and upload your <a href="https://review.source.android.com/#settings,ssh-keys">public SSH key</a>
Dan Morrill3cd199f2009-11-06 14:04:16 -080085, 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 Morrilla9788cd2009-11-15 11:49:30 -080089<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 Morrill3cd199f2009-11-06 14:04:16 -080090.<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>
95After 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 Morrilla9788cd2009-11-15 11:49:30 -080098For 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 Morrill3cd199f2009-11-06 14:04:16 -080099.<br><br><h3>
Dan Morrilla9788cd2009-11-15 11:49:30 -0800100Summary example <br></h3>
101Here 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 Morrill3cd199f2009-11-06 14:04:16 -0800103<br><i>...visit the provided URL to open Gerrit and track your change...</i>
104<br><br><h3>
105Downloading changes from Gerrit</h3>
Dan Morrilla9788cd2009-11-15 11:49:30 -0800106To 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 Morrill3cd199f2009-11-06 14:04:16 -0800109.<br><br><h2>
Dan Morrilla9788cd2009-11-15 11:49:30 -0800110Using the Gerrit code-review tool <br></h2>
Dan Morrill55de6812009-11-15 15:46:36 -0800111You 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 Morrilla9788cd2009-11-15 11:49:30 -0800112Viewing the status of uploaded changes <br></h3>
113To check the status of a change that you uploaded, open <a href="https://review.source.android.com/mine">Gerrit</a>
Dan Morrill3cd199f2009-11-06 14:04:16 -0800114, sign in, and click MyChanges.<br><b><br></b>
115<h3>
Dan Morrilla9788cd2009-11-15 11:49:30 -0800116Reviewing a change <br></h3>
117If 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 Morrill3cd199f2009-11-06 14:04:16 -0800118<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>
124If you approve of the change, you will then mark it with LGTM ("Looks Good to Me") within Gerrit.<br><br><h3>
Dan Morrilla9788cd2009-11-15 11:49:30 -0800125Verifying a change <br></h3>
Dan Morrill3cd199f2009-11-06 14:04:16 -0800126If 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>
131Viewing diffs and comments</h3>
132To 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>
134Adding comments</h3>
135Anyone 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>
136After a submission is approved</h3>
137After 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>
138How do I become a Verifier or Approver?</h3>
Dan Morrilla9788cd2009-11-15 11:49:30 -0800139In short, contribute high-quality code to one or more of the Android projects.
140For details about the different roles in the Android Open Source community and
141who plays them, see <a href="{@docRoot}source/roles.html">Project roles</a>
Dan Morrill3cd199f2009-11-06 14:04:16 -0800142.<br><br><h2>
143Using GitWeb to track patch histories</h2>
Dan Morrilla9788cd2009-11-15 11:49:30 -0800144To 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 Morrill3cd199f2009-11-06 14:04:16 -0800145.<br></div>
146</div>
147</div>