Getting "Hooked" with Git
Jeff Amaral and Aaron Froehlich
Git Intro
Git from 40,000 feet
.git
.git
├── HEAD
├── config
├── description
├── hooks
│ ├── applypatch-msg.sample
│ ├── commit-msg.sample
│ ├── post-update.sample
│ ├── pre-applypatch.sample
│ ├── pre-commit.sample
│ ├── pre-push.sample
│ ├── pre-rebase.sample
│ ├── prepare-commit-msg.sample
│ └── update.sample
├── index
├── info
│ └── exclude
├── logs
│ ├── HEAD
│ └── refs
│ ├── heads
│ │ └── master
│ └── remotes
│ └── origin
│ └── HEAD
├── objects
│ ├── 00
│ │ └── 1d890215
└── refs
├── heads
│ └── master
├── remotes
│ └── origin
│ └── HEAD
└── tags
What's a hook?
Kinds of hooks
.git
└── hooks
├── applypatch-msg.sample
├── commit-msg.sample
├── post-update.sample
├── pre-applypatch.sample
├── pre-commit.sample
├── pre-push.sample
├── pre-rebase.sample
├── prepare-commit-msg.sample
└── update.sample
Examples: pre-commit
Ensure that there's a commit message
Check for code errors with PHP CS
https://gist.github.com/eethann/0abd3cb74c4e69aeff14
Example: post-checkout
Drupal specific: check for branch change, and archive branch data
Example: post-receive
Runs on a bare repo (what's that?) and is great for simple deployments.
#!/bin/sh
# post-receive hook that checks out the latest tag to the live web root and the head of the master branch to dev web root
LATESTTAG=`git --git-dir=/path/to/repo.git rev-list --tags --max-count=1`
LATESTTAGNAME=`git --git-dir=/path/to/repo.git describe --tags $LATESTTAG`
git --work-tree=/srv/www/example.org --git-dir=/path/to/repo.git checkout -fq $LATESTTAG
git --work-tree=/srv/www/dev.example.org --git-dir=/path/to/repo.git checkout -fq master
echo "Updated test site to master"
echo "Updated live site to $LATESTTAGNAME"
Example: post-receive
For more complicated post-receive processes that take a lot of time, use a task queue.
Example: post-checkout
Allows production deployment of compiled CSS
Example: Post-commit
Proclaimed “The single most useful piece of software known to humankind”
Have some fun with your team
Save the moment for posterity