Drupal Sprint - Patching

Inside your drupal 8 git repo

  1. Get the latest updates to all the branches

    git fetch --all
    • We are fetching instead of pulling so we don't clobber our working directory with a merge... yet.
    • The --all makes sure all branches are fetched, not just the tracking branch.
  2. Make a new branch for the issue you are working on.

    git checkout origin/8.x -b 12345-twig-views-rss
    • The -b creates a new branch to work from.
    • The branch name is comprised of the issue number 12345 followed by a meaningful name of sorts twig-views-rss.
  3. Apply the Patch to your git

    curl http://drupal.org/files/name-of-patch-12345-2.patch | git apply --index

    • curl followed by the patch URL will print the patch contents to standard output.
    • The pipe | will pump the standard output into the git apply command.
    • --index will do the equivent to a git add -A . and the changes are staged.
  4. Add and Commit the patch

    git commit -m "12345-2"
    • The name of the commit message doesn't mean a lot here, but I usually put in the comment number of the patch, so I know which comment was commited.
Test and/or fix ...
  1. Add files and Commit changes

    git add -A . && git commit -m "12345-3 fixed some unicorns... etc"
    • The -A flag makes sure that additions, modifications and file deletions get staged.
    • && Allows for two commands to run right after eachother on one line.
  2. Rebase to make sure you have the latest from core

    git fetch --all && git rebase origin/8.x
    • We're explicitly telling the rebase to pull from the origin/8.x just incase my local 8.x is dirty or not up to date.
  3. Make an interdiff (diff between last two commits)

    git show > interdiff.txt
    • git show is equivilent to git diff HEAD~1..HEAD except it has commit messages/notes in it.
    • This is saved as a .txt file to prevent testbot from trying to test it against head (which wouldn't apply)
    • Another filename format for interdiffs: interdiff-NNNNN-X-Y.txt is more explict, where NNNNN is the issue number and X-Y are the patch comment #s the diff is between.
    • The greater than symbol > will take the output and send it to a file of which we name after it.
  4. Make a new patch

    git diff origin/8.x > name-of-patch-12345-3.patch
    • Again we're explicitly making the patch against origin/8.x instead of 8.x incase my local branch is unclean.
    • The filename has both the issue number #12345 and the next comment #3 for the comment we are about to post.

Hurray! Now sit and watch testbot for a few hours till it goes green:)