2011-05-27 18:49:47 +08:00
|
|
|
===============
|
|
|
|
Committing code
|
|
|
|
===============
|
|
|
|
|
2017-02-15 00:30:33 +08:00
|
|
|
This section is addressed to the committers and to anyone interested in knowing
|
|
|
|
how code gets committed into Django. If you're a community member who wants to
|
|
|
|
contribute code to Django, look at :doc:`writing-code/working-with-git` instead.
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2013-09-13 07:01:47 +08:00
|
|
|
.. _handling-pull-requests:
|
|
|
|
|
2012-06-08 00:48:29 +08:00
|
|
|
Handling pull requests
|
2016-01-03 18:56:22 +08:00
|
|
|
======================
|
2012-06-08 00:48:29 +08:00
|
|
|
|
2015-02-18 04:32:47 +08:00
|
|
|
Since Django is now hosted at GitHub, most patches are provided in the form of
|
2012-06-08 17:26:22 +08:00
|
|
|
pull requests.
|
|
|
|
|
|
|
|
When committing a pull request, make sure each individual commit matches the
|
|
|
|
commit guidelines described below. Contributors are expected to provide the
|
|
|
|
best pull requests possible. In practice however, committers - who will likely
|
|
|
|
be more familiar with the commit guidelines - may decide to bring a commit up
|
|
|
|
to standard themselves.
|
2012-06-08 00:48:29 +08:00
|
|
|
|
2018-01-16 10:37:54 +08:00
|
|
|
You may want to have Jenkins test the pull request with one of the pull request
|
|
|
|
builders that doesn't run automatically, such as Oracle or Selenium. See the
|
|
|
|
`Jenkins wiki page`_ for instructions.
|
2014-11-16 20:32:40 +08:00
|
|
|
|
|
|
|
.. _Jenkins wiki page: https://code.djangoproject.com/wiki/Jenkins
|
|
|
|
|
2015-02-18 04:32:47 +08:00
|
|
|
An easy way to checkout a pull request locally is to add an alias to your
|
|
|
|
``~/.gitconfig`` (``upstream`` is assumed to be ``django/django``)::
|
2012-06-08 00:48:29 +08:00
|
|
|
|
2015-02-18 04:32:47 +08:00
|
|
|
[alias]
|
|
|
|
pr = !sh -c \"git fetch upstream pull/${1}/head:pr/${1} && git checkout pr/${1}\"
|
2012-06-08 00:48:29 +08:00
|
|
|
|
2015-02-18 04:32:47 +08:00
|
|
|
Now you can simply run ``git pr ####`` to checkout the corresponding pull
|
|
|
|
request.
|
2012-06-08 00:48:29 +08:00
|
|
|
|
|
|
|
At this point, you can work on the code. Use ``git rebase -i`` and ``git
|
|
|
|
commit --amend`` to make sure the commits have the expected level of quality.
|
2015-02-18 04:32:47 +08:00
|
|
|
Once you're ready:
|
|
|
|
|
2018-01-21 01:38:48 +08:00
|
|
|
.. console::
|
2015-02-18 04:32:47 +08:00
|
|
|
|
|
|
|
$ # Pull in the latest changes from master.
|
|
|
|
$ git checkout master
|
|
|
|
$ git pull upstream master
|
|
|
|
$ # Rebase the pull request on master.
|
|
|
|
$ git checkout pr/####
|
|
|
|
$ git rebase master
|
|
|
|
$ git checkout master
|
|
|
|
$ # Merge the work as "fast-forward" to master to avoid a merge commit.
|
|
|
|
$ # (in practice, you can omit "--ff-only" since you just rebased)
|
|
|
|
$ git merge --ff-only pr/XXXX
|
|
|
|
$ # If you're not sure if you did things correctly, check that only the
|
|
|
|
$ # changes you expect will be pushed to upstream.
|
|
|
|
$ git push --dry-run upstream master
|
|
|
|
$ # Push!
|
|
|
|
$ git push upstream master
|
|
|
|
$ # Delete the pull request branch.
|
|
|
|
$ git branch -d pr/xxxx
|
|
|
|
|
2018-04-07 01:04:11 +08:00
|
|
|
Force push to the branch after rebasing on master but before merging and
|
|
|
|
pushing to upstream. This allows the commit hashes on master and the branch to
|
|
|
|
match which automatically closes the pull request.
|
2015-02-18 04:32:47 +08:00
|
|
|
|
2016-09-22 00:13:21 +08:00
|
|
|
If a pull request doesn't need to be merged as multiple commits, you can use
|
|
|
|
GitHub's "Squash and merge" button on the website. Edit the commit message as
|
|
|
|
needed to conform to :ref:`the guidelines <committing-guidelines>` and remove
|
|
|
|
the pull request number that's automatically appended to the message's first
|
|
|
|
line.
|
2012-06-08 00:48:29 +08:00
|
|
|
|
|
|
|
When rewriting the commit history of a pull request, the goal is to make
|
2012-06-08 07:02:52 +08:00
|
|
|
Django's commit history as usable as possible:
|
2012-06-08 00:48:29 +08:00
|
|
|
|
|
|
|
* If a patch contains back-and-forth commits, then rewrite those into one.
|
2015-02-18 04:32:47 +08:00
|
|
|
For example, if a commit adds some code and a second commit fixes stylistic
|
|
|
|
issues introduced in the first commit, those commits should be squashed
|
|
|
|
before merging.
|
2012-06-08 00:48:29 +08:00
|
|
|
|
|
|
|
* Separate changes to different commits by logical grouping: if you do a
|
2012-06-08 07:02:52 +08:00
|
|
|
stylistic cleanup at the same time as you do other changes to a file,
|
|
|
|
separating the changes into two different commits will make reviewing
|
2012-06-08 00:48:29 +08:00
|
|
|
history easier.
|
|
|
|
|
|
|
|
* Beware of merges of upstream branches in the pull requests.
|
|
|
|
|
|
|
|
* Tests should pass and docs should build after each commit. Neither the
|
|
|
|
tests nor the docs should emit warnings.
|
|
|
|
|
|
|
|
* Trivial and small patches usually are best done in one commit. Medium to
|
2015-02-18 04:32:47 +08:00
|
|
|
large work may be split into multiple commits if it makes sense.
|
2012-06-08 00:48:29 +08:00
|
|
|
|
|
|
|
Practicality beats purity, so it is up to each committer to decide how much
|
|
|
|
history mangling to do for a pull request. The main points are engaging the
|
2012-06-08 07:02:52 +08:00
|
|
|
community, getting work done, and having a usable commit history.
|
2012-06-08 00:48:29 +08:00
|
|
|
|
2013-01-29 23:45:40 +08:00
|
|
|
.. _committing-guidelines:
|
2012-06-08 00:48:29 +08:00
|
|
|
|
2011-05-27 18:49:47 +08:00
|
|
|
Committing guidelines
|
2016-01-03 18:56:22 +08:00
|
|
|
=====================
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2012-06-08 00:48:29 +08:00
|
|
|
In addition, please follow the following guidelines when committing code to
|
|
|
|
Django's Git repository:
|
|
|
|
|
2016-11-16 06:00:50 +08:00
|
|
|
* Never change the published history of ``django/django`` branches by force
|
|
|
|
pushing. If you absolutely must (for security reasons for example), first
|
|
|
|
discuss the situation with the team.
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* For any medium-to-big changes, where "medium-to-big" is according to
|
2013-10-04 06:51:22 +08:00
|
|
|
your judgment, please bring things up on the |django-developers|
|
2011-10-14 08:12:01 +08:00
|
|
|
mailing list before making the change.
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2013-10-04 06:51:22 +08:00
|
|
|
If you bring something up on |django-developers| and nobody responds,
|
2011-10-14 08:12:01 +08:00
|
|
|
please don't take that to mean your idea is great and should be
|
2016-11-26 03:03:11 +08:00
|
|
|
implemented immediately because nobody contested it. Everyone doesn't always
|
|
|
|
have a lot of time to read mailing list discussions immediately, so you may
|
|
|
|
have to wait a couple of days before getting a response.
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* Write detailed commit messages in the past tense, not present tense.
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* Good: "Fixed Unicode bug in RSS API."
|
|
|
|
* Bad: "Fixes Unicode bug in RSS API."
|
|
|
|
* Bad: "Fixing Unicode bug in RSS API."
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2012-06-08 00:48:29 +08:00
|
|
|
The commit message should be in lines of 72 chars maximum. There should be
|
|
|
|
a subject line, separated by a blank line and then paragraphs of 72 char
|
|
|
|
lines. The limits are soft. For the subject line, shorter is better. In the
|
2017-04-20 23:32:56 +08:00
|
|
|
body of the commit message more detail is better than less:
|
|
|
|
|
|
|
|
.. code-block:: none
|
2012-06-08 00:48:29 +08:00
|
|
|
|
|
|
|
Fixed #18307 -- Added git workflow guidelines
|
|
|
|
|
|
|
|
Refactored the Django's documentation to remove mentions of SVN
|
|
|
|
specific tasks. Added guidelines of how to use Git, GitHub, and
|
|
|
|
how to use pull request together with Trac instead.
|
|
|
|
|
2019-03-26 06:26:23 +08:00
|
|
|
Credit the contributors in the commit message: "Thanks A for the report and B
|
|
|
|
for review." Use git's `Co-Authored-By`_ as appropriate.
|
|
|
|
|
|
|
|
.. _Co-Authored-By: https://help.github.com/articles/creating-a-commit-with-multiple-authors/
|
2012-06-08 00:48:29 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* For commits to a branch, prefix the commit message with the branch name.
|
2012-06-08 17:26:22 +08:00
|
|
|
For example: "[1.4.x] Fixed #xxxxx -- Added support for mind reading."
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* Limit commits to the most granular change that makes sense. This means,
|
|
|
|
use frequent small commits rather than infrequent large commits. For
|
|
|
|
example, if implementing feature X requires a small change to library Y,
|
2016-11-26 03:03:11 +08:00
|
|
|
first commit the change to library Y, then commit feature X in a separate
|
|
|
|
commit. This goes a *long way* in helping everyone follow your changes.
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2012-06-08 00:48:29 +08:00
|
|
|
* Separate bug fixes from feature changes. Bugfixes may need to be backported
|
2018-01-31 23:12:51 +08:00
|
|
|
to the stable branch, according to :ref:`supported-versions-policy`.
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* If your commit closes a ticket in the Django `ticket tracker`_, begin
|
2012-06-08 17:26:22 +08:00
|
|
|
your commit message with the text "Fixed #xxxxx", where "xxxxx" is the
|
2011-10-14 08:12:01 +08:00
|
|
|
number of the ticket your commit fixes. Example: "Fixed #123 -- Added
|
2012-06-08 00:48:29 +08:00
|
|
|
whizbang feature.". We've rigged Trac so that any commit message in that
|
|
|
|
format will automatically close the referenced ticket and post a comment
|
|
|
|
to it with the full commit message.
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2012-06-08 00:48:29 +08:00
|
|
|
For the curious, we're using a `Trac plugin`_ for this.
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2012-09-28 04:19:04 +08:00
|
|
|
.. note::
|
|
|
|
|
|
|
|
Note that the Trac integration doesn't know anything about pull requests.
|
|
|
|
So if you try to close a pull request with the phrase "closes #400" in your
|
|
|
|
commit message, GitHub will close the pull request, but the Trac plugin
|
|
|
|
will also close the same numbered ticket in Trac.
|
|
|
|
|
2015-08-08 19:56:37 +08:00
|
|
|
.. _Trac plugin: https://github.com/trac-hacks/trac-github
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* If your commit references a ticket in the Django `ticket tracker`_ but
|
2012-06-08 17:26:22 +08:00
|
|
|
does *not* close the ticket, include the phrase "Refs #xxxxx", where "xxxxx"
|
2012-06-08 00:48:29 +08:00
|
|
|
is the number of the ticket your commit references. This will automatically
|
|
|
|
post a comment to the appropriate ticket.
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2017-04-20 23:32:56 +08:00
|
|
|
* Write commit messages for backports using this pattern:
|
|
|
|
|
|
|
|
.. code-block:: none
|
2011-12-30 20:52:49 +08:00
|
|
|
|
|
|
|
[<Django version>] Fixed <ticket> -- <description>
|
|
|
|
|
|
|
|
Backport of <revision> from <branch>.
|
|
|
|
|
2017-04-20 23:32:56 +08:00
|
|
|
For example:
|
|
|
|
|
|
|
|
.. code-block:: none
|
2011-12-30 20:52:49 +08:00
|
|
|
|
2014-08-27 15:18:56 +08:00
|
|
|
[1.3.x] Fixed #17028 -- Changed diveintopython.org -> diveintopython.net.
|
2011-12-30 20:52:49 +08:00
|
|
|
|
2012-06-08 07:02:52 +08:00
|
|
|
Backport of 80c0cbf1c97047daed2c5b41b296bbc56fe1d7e3 from master.
|
2011-12-30 20:52:49 +08:00
|
|
|
|
2015-02-18 04:32:47 +08:00
|
|
|
There's a `script on the wiki
|
|
|
|
<https://code.djangoproject.com/wiki/CommitterTips#AutomatingBackports>`_
|
|
|
|
to automate this.
|
|
|
|
|
2018-04-07 01:04:11 +08:00
|
|
|
If the commit fixes a regression, include this in the commit message:
|
|
|
|
|
|
|
|
.. code-block:: none
|
|
|
|
|
|
|
|
Regression in 6ecccad711b52f9273b1acb07a57d3f806e93928.
|
|
|
|
|
|
|
|
(use the commit hash where the regression was introduced).
|
|
|
|
|
2011-05-27 18:49:47 +08:00
|
|
|
Reverting commits
|
2016-01-03 18:56:22 +08:00
|
|
|
=================
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2012-06-08 17:26:22 +08:00
|
|
|
Nobody's perfect; mistakes will be committed.
|
|
|
|
|
|
|
|
But try very hard to ensure that mistakes don't happen. Just because we have a
|
|
|
|
reversion policy doesn't relax your responsibility to aim for the highest
|
|
|
|
quality possible. Really: double-check your work, or have it checked by
|
|
|
|
another committer, **before** you commit it in the first place!
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2012-06-08 17:26:22 +08:00
|
|
|
When a mistaken commit is discovered, please follow these guidelines:
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2014-07-22 01:55:37 +08:00
|
|
|
* If possible, have the original author revert their own commit.
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* Don't revert another author's changes without permission from the
|
|
|
|
original author.
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2012-06-08 00:48:29 +08:00
|
|
|
* Use git revert -- this will make a reverse commit, but the original
|
|
|
|
commit will still be part of the commit history.
|
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* If the original author can't be reached (within a reasonable amount
|
|
|
|
of time -- a day or so) and the problem is severe -- crashing bug,
|
2016-01-11 00:48:16 +08:00
|
|
|
major test failures, etc. -- then ask for objections on the
|
2013-10-04 06:51:22 +08:00
|
|
|
|django-developers| mailing list then revert if there are none.
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* If the problem is small (a feature commit after feature freeze,
|
|
|
|
say), wait it out.
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* If there's a disagreement between the committer and the
|
2013-10-04 06:51:22 +08:00
|
|
|
reverter-to-be then try to work it out on the |django-developers|
|
2011-10-14 08:12:01 +08:00
|
|
|
mailing list. If an agreement can't be reached then it should
|
|
|
|
be put to a vote.
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* If the commit introduced a confirmed, disclosed security
|
|
|
|
vulnerability then the commit may be reverted immediately without
|
|
|
|
permission from anyone.
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* The release branch maintainer may back out commits to the release
|
|
|
|
branch without permission if the commit breaks the release branch.
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2016-11-16 06:00:50 +08:00
|
|
|
* If you mistakenly push a topic branch to ``django/django``, just delete it.
|
2012-06-08 00:48:29 +08:00
|
|
|
For instance, if you did: ``git push upstream feature_antigravity``,
|
|
|
|
just do a reverse push: ``git push upstream :feature_antigravity``.
|
|
|
|
|
2016-06-03 06:46:57 +08:00
|
|
|
.. _ticket tracker: https://code.djangoproject.com/
|