Menyerahkan kode

Bagian ini dialamatkan ke Committers dan siapapun yang tertatik dalam mengetahui bagaimana kode didiserahkan kedalam inti Django. Jika anda adalah anggota komunitas yang ingin membantu kode pada Django, lihatlah ini Bekerja dengan Git dan GitHub sebagai gantinya.

Penanganan permintaan tarik

Sejak Django sekarang disimpan pada Github, kebanyakan tambalan disediakan di formulir permintaan tarik.

Ketika menyerahkan permintaan menarik, pastikan setiap penyerahan individu cocok dengan panduan penyerahan digambarkan dibawah. Penyumbang diharapkan untuk menyediakan kemungkinan permintaan menarik terbaik. Dalam praktiknya bagaimanapun, penyerah - yang akan lebih akrab dengan panduan penyerahan - mungkin memutuskan membawa penyerahan ke standar mereka sendiri.

Catatan

Sebelum menggabungkan, tetapi setelah meninjau, lakukan percobaan Jenkins menarik permintaan dengan mengkomentarkan “buildbot, test this please” pada PR. Lihat Jenkins wiki page kami untuk lebih rinci.

Sebuah cara mudah untuk memeriksa penarikan permintaan secara lokal adalah sebuah alias pada ~/.gitconfig anda (upstream dianggap menjadi django/django):

[alias]
    pr = !sh -c \"git fetch upstream pull/${1}/head:pr/${1} && git checkout pr/${1}\"

Sekarang anda dapat dengan mudah menjalankan git pr #### untuk memeriksa permintaan tarik terhubung.

Pada titik ini, anda dapat bekerja pada kode. Gunakan git rebase -i dan git commit --amend untuk memastikan penyerahan mempunyai tingkatan yang diharapkan dari kualitas. Sekali anda sedang siap:

$ # Pull in the latest changes from master.
$ git checkout master
$ git pull upstream master
$ # Rebase the pull request on master.
$ git checkout pr/####
$ git rebase master
$ git checkout master
$ # Merge the work as "fast-forward" to master to avoid a merge commit.
$ # (in practice, you can omit "--ff-only" since you just rebased)
$ git merge --ff-only pr/XXXX
$ # If you're not sure if you did things correctly, check that only the
$ # changes you expect will be pushed to upstream.
$ git push --dry-run upstream master
$ # Push!
$ git push upstream master
$ # Delete the pull request branch.
$ git branch -d pr/xxxx

For changes on your own branches, force push to your fork after rebasing on master but before merging and pushing to upstream. This allows the commit hashes on master and your branch to match which automatically closes the pull request. Since you can’t push to other contributors’ branches, comment on the pull request “Merged in XXXXXXX” (replacing with the commit hash) after you merge it. Trac checks for this message format to indicate on the ticket page whether or not a pull request is merged.

Hindari menggunakan tombol “Merge pull request” Github pada website karena akan membuat “merge commit” yang tidak baik dan membuat navigasi riwayat lebih susah.

Ketika menulis kembali riwayat commit dari pull request, tujuannya adalah membuat riwayat commit django sebaik mungkin:

  • If a patch contains back-and-forth commits, then rewrite those into one. For example, if a commit adds some code and a second commit fixes stylistic issues introduced in the first commit, those commits should be squashed before merging.
  • Separate changes to different commits by logical grouping: if you do a stylistic cleanup at the same time as you do other changes to a file, separating the changes into two different commits will make reviewing history easier.
  • Waspada dari menggabungkan cabang hulu dalam permintaan tarikan.

  • Percobaan harus dilewati dan dokumen harus dibangun setelah setiap penyerahan. Juga tidak percobaan maupun dokumen harus mengeluarkan peringatan.

  • Tambalan sepele dan kecil biasanya baik diselesaikan dalam satu penyerahan. Pekerjaan menengah sampai besar mungkin dipisah menjadi banyak penyerahan jika itu masuk akal.

Practicality beats purity, so it is up to each committer to decide how much history mangling to do for a pull request. The main points are engaging the community, getting work done, and having a usable commit history.

Panduan penyerahan

In addition, please follow the following guidelines when committing code to Django’s Git repository:

  • Never change the published history of django/django branches! Never force- push your changes to django/django. If you absolutely must (for security reasons for example) first discuss the situation with the core team.

  • For any medium-to-big changes, where “medium-to-big” is according to your judgment, please bring things up on the django-developers mailing list before making the change.

    If you bring something up on django-developers and nobody responds, please don’t take that to mean your idea is great and should be implemented immediately because nobody contested it. Django’s core developers don’t have a lot of time to read mailing-list discussions immediately, so you may have to wait a couple of days before getting a response.

  • Write detailed commit messages in the past tense, not present tense.

    • Bagus: “Memperbaiki kesalahan Unicode dalam API RSS.”

    • Buruk: “Memperbaiki kesalahan Unicode dalam API RSS.”

    • Buruk: “Memperbaiki kesalahan Unicode dalam API RSS.”

    The commit message should be in lines of 72 chars maximum. There should be a subject line, separated by a blank line and then paragraphs of 72 char lines. The limits are soft. For the subject line, shorter is better. In the body of the commit message more detail is better than less:

    Fixed #18307 -- Added git workflow guidelines
    
    Refactored the Django's documentation to remove mentions of SVN
    specific tasks. Added guidelines of how to use Git, GitHub, and
    how to use pull request together with Trac instead.
    

    If the patch wasn’t a pull request, you should credit the contributors in the commit message: “Thanks A for report, B for the patch and C for the review.”

  • For commits to a branch, prefix the commit message with the branch name. For example: “[1.4.x] Fixed #xxxxx – Added support for mind reading.”

  • Limit commits to the most granular change that makes sense. This means, use frequent small commits rather than infrequent large commits. For example, if implementing feature X requires a small change to library Y, first commit the change to library Y, then commit feature X in a separate commit. This goes a long way in helping all Django core developers follow your changes.

  • Pisahkan perbaikan kesalahan dari perubahan fitur. Perbaikan kesalahan mungkin butuh disambungkan ke cabang stabil, menurut kebijakan kecocokan-sebelumnya.

  • If your commit closes a ticket in the Django ticket tracker, begin your commit message with the text “Fixed #xxxxx”, where “xxxxx” is the number of the ticket your commit fixes. Example: “Fixed #123 – Added whizbang feature.”. We’ve rigged Trac so that any commit message in that format will automatically close the referenced ticket and post a comment to it with the full commit message.

    If your commit closes a ticket and is in a branch, use the branch name first, then the “Fixed #xxxxx.” For example: “[1.4.x] Fixed #123 – Added whizbang feature.”

    Untuk ingin tahu, kami menggunakan `Tambahan Trac `_ untuk ini.

Catatan

Note that the Trac integration doesn’t know anything about pull requests. So if you try to close a pull request with the phrase “closes #400” in your commit message, GitHub will close the pull request, but the Trac plugin will also close the same numbered ticket in Trac.

  • If your commit references a ticket in the Django ticket tracker but does not close the ticket, include the phrase “Refs #xxxxx”, where “xxxxx” is the number of the ticket your commit references. This will automatically post a comment to the appropriate ticket.

  • Tulis pesan commit untuk backport menggunakan pola berikut:

    [<Django version>] Fixed <ticket> -- <description>
    
    Backport of <revision> from <branch>.
    

    Sebagai contoh:

    [1.3.x] Fixed #17028 -- Changed diveintopython.org -> diveintopython.net.
    
    Backport of 80c0cbf1c97047daed2c5b41b296bbc56fe1d7e3 from master.
    

    Terdapat tulisan pada wiki <https://code.djangoproject.com/wiki/CommitterTips#AutomatingBackports>`_ untuk mengotomatisasi ini.

Reverting commits

Tidak seorangpun sempurna; kesalahan akan diserahkan.

But try very hard to ensure that mistakes don’t happen. Just because we have a reversion policy doesn’t relax your responsibility to aim for the highest quality possible. Really: double-check your work, or have it checked by another committer, before you commit it in the first place!

When a mistaken commit is discovered, please follow these guidelines:

  • Jika memungkinkan, penulis asli mengembalikan penyerahan mereka sendiri.

  • Don’t revert another author’s changes without permission from the original author.
  • Use git revert – this will make a reverse commit, but the original commit will still be part of the commit history.
  • If the original author can’t be reached (within a reasonable amount of time – a day or so) and the problem is severe – crashing bug, major test failures, etc. – then ask for objections on the django-developers mailing list then revert if there are none.
  • If the problem is small (a feature commit after feature freeze, say), wait it out.
  • If there’s a disagreement between the committer and the reverter-to-be then try to work it out on the django-developers mailing list. If an agreement can’t be reached then it should be put to a vote.
  • If the commit introduced a confirmed, disclosed security vulnerability then the commit may be reverted immediately without permission from anyone.
  • The release branch maintainer may back out commits to the release branch without permission if the commit breaks the release branch.
  • If you mistakenly push a topic branch to django/django, just delete it. For instance, if you did: git push upstream feature_antigravity, just do a reverse push: git push upstream :feature_antigravity.