Contributing code

From MoKee Open Source Wiki
Jump to: navigation, search
This page contains changes which are not marked for translation.

Other languages:
English

Creating a patch

The beauty of open source projects is the ability for even the most novice of developers to be involved in determining the trajectory of the project. The difficulty is in knowing exactly how to submit your patch for code review and (hopefully) inclusion into the project.

Below are the simple, basic steps for contributing code:

  1. Begin by performing a repo sync so that we know we’re dealing with the most recent versions of the code. We're also assuming that you have experience with terminal & you have your MoKee OpenSource repo in ~/mokee:
    cd ~/mokee
    repo sync
  2. Go to https://review.mfunz.com and register. Make sure to accept the agreement.
  3. Now go and make the changes to the files you are wanting to change.
  4. Now in terminal, navigate to the project directory.
  5. We need to commit the changes to gerrit for review, along with a message telling exactly what was done for the reviewer(s) to review
    • Let's check what all we changed
    git status (this will tell you the files that were changed)
    • Now let's add the files
    git add <file name> if you need only some of the changed files
    or use git add -A to add all the files.
    • Now we need to create a commit for the changes
    git commit
    • This will open up an editor and at the top line you will need to provide the comment about the changes you have done.
    Suggested format: <PackageName>: <overview of change(s) made>
    Example: base: fix clock style when hidden
    • Once done press CTRL-O to save your changes, and then CTRL-X to exit
    Your changes will be saved, and you’ll receive a notice about the number of changes to be submitted
  6. Now we need to upload our changes to gerrit for review.
    git push ssh://<username>@review.mfunz.com/<project> HEAD:refs/for/<branch>
    Example: git push ssh://martincz@review.mfunz.com/android_frameworks_base HEAD:refs/for/kk_mkt
    This will upload the changes, and you’ll receive a web link to those changes like https://review.mfunz.com/6346

For more information on Gerrit, see Gerrit Rules.

Creating a patchset

Now that you have created a patch, you may want to change it maybe because you have a better idea, or you did a mistake. So let's begin

  1. Begin by performing a repo sync so that we know we’re dealing with the most recent versions of the code. We're also assuming that you have your MoKee OpenSource repo in ~/mokee:
    cd ~/mokee
    repo sync
  2. Now in terminal, navigate to the project directory.
  3. Cherry-pick your patch from gerrit.
  4. Make changes
  5. Now let's change our original commit
    • Let's check what all we changed
    git status (this will tell you the files that were changed)
    • Now let's add the files
    git add <file name> if you need only some of the changed files
    or use git commit -A to add all the files.
    • We want to change our original commit instead of a new one
    git commit --amend
    This will open up the same editor we dealt with already
    • Get done with it
  6. Now the commit is ready to be pushed. This will edit the original commit instead of creating a new one.

Getting lazy

Typing git push ssh://<username>@review.mfunz.com/<project> HEAD:refs/for/<branch> everytime is a painful job.

  1. So instead of typing it everytime, we create a remote for it.
    git remote add <name> ssh://<username>@review.mfunz.com/<project>
  2. Using it
    git push <name> HEAD:refs/for/<branch>

You'll have to create remotes for every project.

Getting more lazy :)

Install git-review, here is a guide

Git review config:

git remote add gerrit ssh://<username>@review.mfunz.com/<project>

git review -s

Creating a patch:

$ git checkout -b mycoolfeature
change files
$ git commit -a
$ git review

Creating a patchset:

$ git checkout mycoolfeature
change files
$ git commit -a --amend
$ git review

Licensing

It is important that any code you contribute follows either the existing licensing, or utilizes the correct licensing. For pre-created headers, see the License template