committing-code.txt 10 KB

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