committing-code.txt 11 KB

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