Difference between revisions of "Pull Requests"

From D Wiki
Jump to: navigation, search
(Autotester)
(Link to section)
 
(16 intermediate revisions by 10 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.
 
 
 
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>
 
 
 
==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.
 
 
 
'''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>
 
 
 
Then checkout master and pull from upstream:
 
 
 
<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].
 

Latest revision as of 10:30, 4 December 2015