committing-code.txt 10 KB

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