committing-code.txt 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. ===============
  2. Committing code
  3. ===============
  4. This section is addressed to the :ref:`committers` and to anyone interested in
  5. knowing how code gets committed into Django core. If you're a community member
  6. who wants to contribute code to Django, have a look at
  7. :doc:`writing-code/working-with-git` instead.
  8. .. _handling-pull-requests:
  9. Handling pull requests
  10. ----------------------
  11. Since Django is now hosted at GitHub, many patches are provided in the form of
  12. pull requests.
  13. When committing a pull request, make sure each individual commit matches the
  14. commit guidelines described below. Contributors are expected to provide the
  15. best pull requests possible. In practice however, committers - who will likely
  16. be more familiar with the commit guidelines - may decide to bring a commit up
  17. to standard themselves.
  18. Here is one way to commit a pull request::
  19. # Create a new branch tracking upstream/master -- upstream is assumed
  20. # to be django/django.
  21. git checkout -b pull_xxxxx upstream/master
  22. # Download the patches from github and apply them.
  23. curl https://github.com/django/django/pull/xxxxx.patch | git am
  24. At this point, you can work on the code. Use ``git rebase -i`` and ``git
  25. commit --amend`` to make sure the commits have the expected level of quality.
  26. Once you're ready::
  27. # Make sure master is ready to receive changes.
  28. git checkout master
  29. git pull upstream master
  30. # Merge the work as "fast-forward" to master, to avoid a merge commit.
  31. git merge --ff-only pull_xxxxx
  32. # Check that only the changes you expect will be pushed to upstream.
  33. git push --dry-run upstream master
  34. # Push!
  35. git push upstream master
  36. # Get rid of the pull_xxxxx branch.
  37. git branch -d pull_xxxxx
  38. An alternative is to add the contributor's repository as a new remote,
  39. checkout the branch and work from there::
  40. git remote add <contributor> https://github.com/<contributor>/django.git
  41. git checkout pull_xxxxx <contributor> <contributor's pull request branch>
  42. Yet another alternative is to fetch the branch without adding the
  43. contributor's repository as a remote::
  44. git fetch https://github.com/<contributor>/django.git <contributor's pull request branch>
  45. git checkout -b pull_xxxxx FETCH_HEAD
  46. At this point, you can work on the code and continue as above.
  47. GitHub provides a one-click merge functionality for pull requests. This should
  48. only be used if the pull request is 100% ready, and you have checked it for
  49. errors (or trust the request maker enough to skip checks). Currently, it isn't
  50. possible to check that the tests pass and that the docs build without
  51. downloading the changes to your development environment.
  52. When rewriting the commit history of a pull request, the goal is to make
  53. Django's commit history as usable as possible:
  54. * If a patch contains back-and-forth commits, then rewrite those into one.
  55. Typically, a commit can add some code, and a second commit can fix
  56. stylistic issues introduced in the first commit.
  57. * Separate changes to different commits by logical grouping: if you do a
  58. stylistic cleanup at the same time as you do other changes to a file,
  59. separating the changes into two different commits will make reviewing
  60. history easier.
  61. * Beware of merges of upstream branches in the pull requests.
  62. * Tests should pass and docs should build after each commit. Neither the
  63. tests nor the docs should emit warnings.
  64. * Trivial and small patches usually are best done in one commit. Medium to
  65. large work should be split into multiple commits if possible.
  66. Practicality beats purity, so it is up to each committer to decide how much
  67. history mangling to do for a pull request. The main points are engaging the
  68. community, getting work done, and having a usable commit history.
  69. .. _committing-guidelines:
  70. Committing guidelines
  71. ---------------------
  72. In addition, please follow the following guidelines when committing code to
  73. Django's Git repository:
  74. * Never change the published history of django/django branches! **Never force-
  75. push your changes to django/django.** If you absolutely must (for security
  76. reasons for example) first discuss the situation with the core team.
  77. * For any medium-to-big changes, where "medium-to-big" is according to
  78. your judgment, please bring things up on the |django-developers|
  79. mailing list before making the change.
  80. If you bring something up on |django-developers| and nobody responds,
  81. please don't take that to mean your idea is great and should be
  82. implemented immediately because nobody contested it. Django's core
  83. developers don't have a lot of time to read mailing-list discussions
  84. immediately, so you may have to wait a couple of days before getting a
  85. response.
  86. * Write detailed commit messages in the past tense, not present tense.
  87. * Good: "Fixed Unicode bug in RSS API."
  88. * Bad: "Fixes Unicode bug in RSS API."
  89. * Bad: "Fixing Unicode bug in RSS API."
  90. The commit message should be in lines of 72 chars maximum. There should be
  91. a subject line, separated by a blank line and then paragraphs of 72 char
  92. lines. The limits are soft. For the subject line, shorter is better. In the
  93. body of the commit message more detail is better than less::
  94. Fixed #18307 -- Added git workflow guidelines
  95. Refactored the Django's documentation to remove mentions of SVN
  96. specific tasks. Added guidelines of how to use Git, GitHub, and
  97. how to use pull request together with Trac instead.
  98. If the patch wasn't a pull request, you should credit the contributors in
  99. the commit message: "Thanks A for report, B for the patch and C for the
  100. review."
  101. * For commits to a branch, prefix the commit message with the branch name.
  102. For example: "[1.4.x] Fixed #xxxxx -- Added support for mind reading."
  103. * Limit commits to the most granular change that makes sense. This means,
  104. use frequent small commits rather than infrequent large commits. For
  105. example, if implementing feature X requires a small change to library Y,
  106. first commit the change to library Y, then commit feature X in a
  107. separate commit. This goes a *long way* in helping all Django core
  108. developers follow your changes.
  109. * Separate bug fixes from feature changes. Bugfixes may need to be backported
  110. to the stable branch, according to the :ref:`backwards-compatibility policy
  111. <backwards-compatibility-policy>`.
  112. * If your commit closes a ticket in the Django `ticket tracker`_, begin
  113. your commit message with the text "Fixed #xxxxx", where "xxxxx" is the
  114. number of the ticket your commit fixes. Example: "Fixed #123 -- Added
  115. whizbang feature.". We've rigged Trac so that any commit message in that
  116. format will automatically close the referenced ticket and post a comment
  117. to it with the full commit message.
  118. If your commit closes a ticket and is in a branch, use the branch name
  119. first, then the "Fixed #xxxxx." For example:
  120. "[1.4.x] Fixed #123 -- Added whizbang feature."
  121. For the curious, we're using a `Trac plugin`_ for this.
  122. .. note::
  123. Note that the Trac integration doesn't know anything about pull requests.
  124. So if you try to close a pull request with the phrase "closes #400" in your
  125. commit message, GitHub will close the pull request, but the Trac plugin
  126. will also close the same numbered ticket in Trac.
  127. .. _Trac plugin: https://github.com/aaugustin/trac-github
  128. * If your commit references a ticket in the Django `ticket tracker`_ but
  129. does *not* close the ticket, include the phrase "Refs #xxxxx", where "xxxxx"
  130. is the number of the ticket your commit references. This will automatically
  131. post a comment to the appropriate ticket.
  132. * Write commit messages for backports using this pattern::
  133. [<Django version>] Fixed <ticket> -- <description>
  134. Backport of <revision> from <branch>.
  135. For example::
  136. [1.3.x] Fixed #17028 - Changed diveintopython.org -> diveintopython.net.
  137. Backport of 80c0cbf1c97047daed2c5b41b296bbc56fe1d7e3 from master.
  138. Reverting commits
  139. -----------------
  140. Nobody's perfect; mistakes will be committed.
  141. But try very hard to ensure that mistakes don't happen. Just because we have a
  142. reversion policy doesn't relax your responsibility to aim for the highest
  143. quality possible. Really: double-check your work, or have it checked by
  144. another committer, **before** you commit it in the first place!
  145. When a mistaken commit is discovered, please follow these guidelines:
  146. * If possible, have the original author revert their own commit.
  147. * Don't revert another author's changes without permission from the
  148. original author.
  149. * Use git revert -- this will make a reverse commit, but the original
  150. commit will still be part of the commit history.
  151. * If the original author can't be reached (within a reasonable amount
  152. of time -- a day or so) and the problem is severe -- crashing bug,
  153. major test failures, etc -- then ask for objections on the
  154. |django-developers| mailing list then revert if there are none.
  155. * If the problem is small (a feature commit after feature freeze,
  156. say), wait it out.
  157. * If there's a disagreement between the committer and the
  158. reverter-to-be then try to work it out on the |django-developers|
  159. mailing list. If an agreement can't be reached then it should
  160. be put to a vote.
  161. * If the commit introduced a confirmed, disclosed security
  162. vulnerability then the commit may be reverted immediately without
  163. permission from anyone.
  164. * The release branch maintainer may back out commits to the release
  165. branch without permission if the commit breaks the release branch.
  166. * If you mistakenly push a topic branch to django/django, just delete it.
  167. For instance, if you did: ``git push upstream feature_antigravity``,
  168. just do a reverse push: ``git push upstream :feature_antigravity``.
  169. .. _ticket tracker: https://code.djangoproject.com/newticket