Difference between revisions of "Pull Requests"

From D Wiki
Jump to: navigation, search
(Updated to deal with stable branch)
(Link to section)
 
(7 intermediate revisions by 5 users not shown)
Line 1: Line 1:
The source code of the D compiler (dmd), runtime library (druntime), and standard library (Phobos), are all available at [https://github.com/D-Programming-Language GitHub].
+
#REDIRECT [[Starting as a Contributor#Create_a_pull_request]]
 
 
==Fork the project==
 
 
 
To contribute to the D compiler, runtime library, or standard library, you need to create an account on GitHub, and then navigate to the [https://github.com/D-Programming-Language D programming language] page, select the project you wish to contribute to, and create a fork of that project.
 
 
 
For example, if you wish to submit a patch to the D compiler, you should navigate to [https://github.com/D-Programming-Language/dmd D-Programming-Language/dmd], then click on the "Fork" button at the top right corner of the page. This will clone the D compiler sources into your list of projects.
 
 
 
==Check out the sources==
 
 
 
{{seealso|Using Git on Windows}}
 
 
 
Once you have forked the project you wish to contribute to, use git to checkout a local copy of the project.
 
 
 
Generally, you should checkout a copy of at least dmd, druntime, and phobos in order to have a working compiler toolchain that you can use to test your changes.
 
 
 
Note: if you are intending to fix a regression for the current version for a point release, you must use the [[#Stable Branch|stable branch]] of the code. See the section on the stable branch for more information.
 
 
 
After checking out the sources, you will probably want to [[Building DMD|build DMD]].
 
 
 
==Make your changes in a branch==
 
 
 
{{seealso_url|http://dlang.org/dstyle.html|D coding style}}
 
 
 
Generally, it is preferred that any changes you wish to contribute should be made in its own dedicated topic branch. For example, if you have a fix for issue 1234 in the D compiler, you might want to do something like this:
 
 
 
<syntaxhighlight lang="bash">
 
cd /usr/src/d/dmd/src
 
git checkout -b issue_1234
 
vim expression.c    # make your changes here
 
make -f posix.mak
 
...                # test your changes here
 
git commit -a      # commit to the branch named 'issue_1234'
 
git push -u origin  # push changes to your fork of DMD
 
</syntaxhighlight>
 
 
 
If you are fixing a specific bugzilla issue, then putting "Fix Issue NNNN" in the commit message will automatically add a message to the bug report when the commit is merged.
 
 
 
==Test your changes==
 
 
 
Before you submit your changes, it's a good idea to test it thoroughly first. It's also a good idea to run the unittests for druntime and phobos:
 
 
 
<syntaxhighlight lang=bash>
 
cd /usr/src/d/druntime
 
make -f posix.mak unittest
 
cd ../phobos
 
make -f posix.mak unittest
 
</syntaxhighlight>
 
 
 
Pull requests that fail unittests will not be accepted by the maintainers, except under special circumstances.
 
 
 
'''TBD:''' add instructions on running dmd's unittests.
 
 
 
==Create a pull request==
 
 
 
Once you have tested all your changes and pushed them to your fork on GitHub, you are ready to submit a pull request.
 
 
 
# Navigate to your fork of the project on GitHub.
 
# '''Important''': Select the branch that you made your changes in, say issue_1234.
 
# Click on the "Pull Request" button.
 
 
 
This will submit your changes for review by the D maintainers. If your changes are approved, they will be merged into the master branch. Otherwise, if the maintainers have some comments or feedback, you can refine your changes by editing and testing in your local workspace, and pushing the new changes to the same git branch. The new changes will be automatically included in your pull request.
 
 
 
Choose a title for your pull request that clearly states what it does.  When fixing a bug, the usual thing to do is to use the summary from the bugzilla report.  Eg a title like "Fix 3797" or "Issue 3797" contains much less information than "Fix Issue 3797 - Regression(2.038): Implicit conversion between incompatible function pointers" and requires a lot more effort for the reviewers to determine if it is something they are interested in.
 
 
 
Pull request descriptions should contain a hyperlink to the [[Bugzilla]] issue that is being fixed.  This is usually added at the end of the description.
 
 
 
After the pull request is created, the corresponding bugzilla issue should have the 'pull' keyword added and a link to the pull request posted in a comment.
 
 
 
===Autotester===
 
 
 
Pull requests are automatically picked up by the [[Git Commit Tester|autotester]], which compiles the code in the pull request and runs it through the dmd, druntime, and phobos unittests on all supported platforms. Generally, pull requests must pass all tests before they will be merged. The status of the tests can be monitored through the pull request page.
 
 
 
Every user must be manually approved before the autotester will start testing their pull requests.  Users can be approved by anyone with commit access.
 
 
 
===Rebasing===
 
 
 
Sometimes, if a particular change you are working on is taking a long time, or if you encounter a problem that is fixed by a new commit upstream, you may need to sync your local branch with master in order to keep the code up-to-date. In this case, it is recommended that you use git rebase to apply your changes ''on top of'' the latest git master, so that when you submit a pull request, the change history will be easier for the reviewers to follow. Using git merge is ''not'' recommended, as it may produce a lot of merge commits that may not be relevant to your changes.
 
 
 
For example, you may be working on your changes:
 
 
 
<syntaxhighlight lang=bash>
 
cd /usr/src/d/phobos
 
git checkout mybranch
 
vim std/algorithm.d  # apply lots of cool changes here
 
</syntaxhighlight>
 
 
 
First, before you resync with master, make sure all your changes are checked in (or stashed):
 
 
 
<syntaxhighlight lang=bash>
 
git commit -a
 
</syntaxhighlight>
 
 
 
If you forked from the official D programming language repositories you may need to add an upstream remote to pull in the latest official changes. If this is the case you can add an upstream remote like this:
 
 
 
<syntaxhighlight lang=bash>
 
git remote add upstream git@github.com:D-Programming-Language/phobos
 
</syntaxhighlight>
 
 
This adds another remote to your repository called upstream and only needs to be done once. Once the upstream remote is added, you can update your repository's master branch by running the following:
 
 
 
<syntaxhighlight lang=bash>
 
git checkout master
 
git pull --ff-only upstream master
 
</syntaxhighlight>
 
 
 
The --ff-only option is to ensure that your master branch is identical to the official D sources' master branch, since otherwise you will end up with a very messy history that will be hard to clean up (and the reviewers will probably reject your pull request due to having unrelated merge commits).
 
 
 
Now go back to your branch and rebase it:
 
 
 
<syntaxhighlight lang=bash>
 
git checkout mybranch
 
git rebase master
 
</syntaxhighlight>
 
 
 
Now your sources should be up-to-date. Recompile and test everything to make sure it all works.
 
 
 
Note that after rebasing, you will need to force an update to your fork on GitHub with the -f flag, otherwise it will fail because the histories don't match anymore:
 
 
 
<syntaxhighlight lang=bash>
 
git push -f origin mybranch
 
</syntaxhighlight>
 
 
 
You may wish to read up on [http://git-scm.com/book/en/Git-Branching-Rebasing how git rebase works] if you're not familiar with the concept.
 
 
 
If, during the 'git rebase' command, you encounter conflicts, you may want to learn [http://stackoverflow.com/questions/8780257/git-rebase-a-branch-onto-master-failed-how-to-resolve how to resolve a conflict during git rebase].
 
 
 
==Stable Branch==
 
 
 
If you are working on a fix for a regression, chances are it should go into the next point release, and not the next major version (e.g. 2.067.1 instead of 2.068). In this case, you should check out the stable branch of each subproject BEFORE you create your topic branch:
 
 
 
<syntaxhighlight lang=bash>
 
cd dmd
 
git checkout stable
 
cd ../druntime
 
git checkout stable
 
cd ../phobos
 
git checkout stable
 
</syntaxhighlight>
 
 
 
Then follow the instructions for [[#Make your changes in a branch|making a branch]].
 
 
 
If you forget to do this, or didn't realize it, It's not possible to simply re-target your branch for pulling into the stable branch. Github will let you do this, but your branch will include many of the changes from the unstable branch!
 
 
 
In order to fix such a problem, you can [[#Rebasing|rebase]] on top of the stable branch:
 
 
 
<syntaxhighlight lang=bash>
 
git rebase stable
 
</syntaxhighlight>
 
 
 
You may have to follow the instructions in the [[#Rebasing|Rebasing section]] on adding the upstream branch, substituting stable for master.
 
 
 
This sometimes may not work, as the changes between the stable and master are too drastic. In this case, you may have to re create your changes after a clean checkout of the stable branch.
 
 
 
When creating a pull request, you need to tell github to target the stable branch instead of master on the upstream repository. This is done via a drop-down at the top of the page, make sure to do this before submitting your pull request as this cannot be changed after the PR is created (you will have to close the PR and create a new one).
 
 
 
If you notice in your PR a whole slew of changes that seem to have nothing to do with your changes, it's likely because you forgot one of these steps.
 
 
 
==Reviews==
 
 
 
Any pull requests that make language changes must be approved by Walter and Andrei. This includes druntime changes that implement the specification.
 
 
 
Any pull requests that make significant changes to code should be reviewed by more than one person. This means that at least two people need to approve the pull request before it is merged. One person must be a person with commit rights, but the other need not be, as long as that person is trusted within the developer community.
 
 
 
Pull requests that are trivial (typos, obvious minor bug fixes, etc.) may be pulled without a second review.
 
 
 
Please note that any updates pushed to the candidate branch do not automatically notify a subscribed person. If you update your branch to correct an issue, please also put in a comment indicating it.
 
 
 
==Copyright assignment==
 
 
 
Please note that all contributions to DMD source code require that the copyright to that code be assigned to Digital Mars.
 
 
 
 
 
[[Category: Contribution Guidelines]]
 

Latest revision as of 10:30, 4 December 2015