committing-code.txt 11 KB

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