Git Hooks 
The lion tamer 
Umut IŞIK
Agenda 
▪ The Case 
▪ The Problem 
▪ The Purpose 
▪ Git Hooks 
▪ Personal Experience 
▪ Discussion
1. The Case 
Life Of Developer 
▪ Code 
▪ Bug Fix 
▪ Refactor 
▪ Work with Multiple Developers 
▪ Merge 
▪ Deadline
1. The Case 
Poor Pi
1. The Case 
▪ Pi is the developer 
▪ Boat is the software development 
▪ Storm, ocean, sun, etc are the challanges 
▪ Survival is the requirement 
▪ Tiger is the habbits
2. The Problem 
What we do? 
▪ Implementation 
▪ New Feature 
▪ Bug Fix 
▪ Commit 
▪ ‘git commit –a’
We are what we repeatedly do. Excellence, then, is not an act, but 
a habit. 
Aristotle 
2. The Problem
2. The Problem 
Habbits 
▪ Implementation 
▪ Coding standards 
▪ Code Comments 
▪ Naming convention 
▪ Unused variable 
▪ Copy/Paste
2. The Problem 
Habbits 
▪ Commit 
▪ Tests 
▪ Team members 
▪ The number of files 
▪ Case / Story ID
2. The Problem 
Confession Time
2. The Problem 
▪ We are a little bit lazy.
2. The Problem 
The ego 
▪ The all code is crap, except mine, attitude.
2. The Problem 
A Second Miracle 
▪ The “I fix that in a second” catastrophe. 
▪ The “That will only take a second” misconception.
2. The Problem 
We do not 
▪ obey coding standards 
▪ check unused variables 
▪ write comments
2. The Problem 
We like 
▪ copy paste
2. The Problem 
We commit without checking 
▪ Unit Tests 
▪ team members
2. The Problem 
▪ Bad habbits will kill you soon…
3. The Purpose 
▪ Try to have good habbits
3. The Purpose 
▪ Setup better rules (good habbits ☺ ) 
▪ Fource yourself to obey the new rules
4. Git Hooks 
Fire custom scripts when certain actions occured 
▪ Client-Side 
▪ Server-Side
4. Git Hooks 
Installation 
▪ Nothing todo 
▪ .git/hooks folder 
▪ Shell scripts 
▪ Custom scripts with Phyton, Ruby, PHP or whatever .. 
▪ Not interactive ☹
4. Git Hooks 
Client-Side 
▪ Committing Workflow 
▪ E-mail Workflow 
▪ Other
4. Git Hooks 
▪ Committing Workflow 
▪ pre-commit 
▪ prepare-commit-msg 
▪ commit-msg 
▪ post-commit 
▪ Email Workflow 
▪ applypatch-msg 
▪ pre-applypatch 
▪ post-applypatch
4. Git Hooks 
▪ Other 
▪ pre-rebase 
▪ post-merge 
▪ post-checkout
4. Git Hooks 
▪ Server-side 
▪ pre-receive 
▪ post-recieve 
▪ update
4. Personal Experience 
Bad habbits 
▪ Unused variable 
▪ Copy-Paste 
▪ Unit Test 
▪ Commit comments
4. Personal Experience 
Check my code before commit 
▪ Use «pre-commit» hook 
▪ Fired before commit 
▪ Can stop commit process
4. Personal Experience 
«php -l» syntax check 
▪ Syntax errors 
▪ Unused variables
4. Personal Experience 
«phpcpd» tool 
▪ Copy/Paste Detector (CPD) for PHP code
4. Personal Experience 
PHPCodesniffer 
▪ PHP, JavaScript and CSS files 
▪ Detects violations of a defined set of coding standards
4. Personal Experience 
▪ «pre-commit» hook
4. Personal Experience 
Commit message 
▪ «prepare-commit-msg» hook 
▪ Fired before comment editor 
▪ You can change default message 
▪ «commit-msg» hook 
▪ Validate commit comment
4. Personal Experience 
Improvement 
▪ Check view files for XSS 
▪ Check test implementation for methods 
▪ Check log implementation 
▪ Check if test the test suite failed because of my commit 
▪ Validate Jira/Mingle case id
5. Discussion ☺

Git hooks For PHP Developers

  • 1.
    Git Hooks Thelion tamer Umut IŞIK
  • 2.
    Agenda ▪ TheCase ▪ The Problem ▪ The Purpose ▪ Git Hooks ▪ Personal Experience ▪ Discussion
  • 3.
    1. The Case Life Of Developer ▪ Code ▪ Bug Fix ▪ Refactor ▪ Work with Multiple Developers ▪ Merge ▪ Deadline
  • 4.
    1. The Case Poor Pi
  • 5.
    1. The Case ▪ Pi is the developer ▪ Boat is the software development ▪ Storm, ocean, sun, etc are the challanges ▪ Survival is the requirement ▪ Tiger is the habbits
  • 6.
    2. The Problem What we do? ▪ Implementation ▪ New Feature ▪ Bug Fix ▪ Commit ▪ ‘git commit –a’
  • 7.
    We are whatwe repeatedly do. Excellence, then, is not an act, but a habit. Aristotle 2. The Problem
  • 8.
    2. The Problem Habbits ▪ Implementation ▪ Coding standards ▪ Code Comments ▪ Naming convention ▪ Unused variable ▪ Copy/Paste
  • 9.
    2. The Problem Habbits ▪ Commit ▪ Tests ▪ Team members ▪ The number of files ▪ Case / Story ID
  • 10.
    2. The Problem Confession Time
  • 11.
    2. The Problem ▪ We are a little bit lazy.
  • 12.
    2. The Problem The ego ▪ The all code is crap, except mine, attitude.
  • 13.
    2. The Problem A Second Miracle ▪ The “I fix that in a second” catastrophe. ▪ The “That will only take a second” misconception.
  • 14.
    2. The Problem We do not ▪ obey coding standards ▪ check unused variables ▪ write comments
  • 15.
    2. The Problem We like ▪ copy paste
  • 16.
    2. The Problem We commit without checking ▪ Unit Tests ▪ team members
  • 17.
    2. The Problem ▪ Bad habbits will kill you soon…
  • 18.
    3. The Purpose ▪ Try to have good habbits
  • 19.
    3. The Purpose ▪ Setup better rules (good habbits ☺ ) ▪ Fource yourself to obey the new rules
  • 20.
    4. Git Hooks Fire custom scripts when certain actions occured ▪ Client-Side ▪ Server-Side
  • 21.
    4. Git Hooks Installation ▪ Nothing todo ▪ .git/hooks folder ▪ Shell scripts ▪ Custom scripts with Phyton, Ruby, PHP or whatever .. ▪ Not interactive ☹
  • 22.
    4. Git Hooks Client-Side ▪ Committing Workflow ▪ E-mail Workflow ▪ Other
  • 23.
    4. Git Hooks ▪ Committing Workflow ▪ pre-commit ▪ prepare-commit-msg ▪ commit-msg ▪ post-commit ▪ Email Workflow ▪ applypatch-msg ▪ pre-applypatch ▪ post-applypatch
  • 24.
    4. Git Hooks ▪ Other ▪ pre-rebase ▪ post-merge ▪ post-checkout
  • 25.
    4. Git Hooks ▪ Server-side ▪ pre-receive ▪ post-recieve ▪ update
  • 26.
    4. Personal Experience Bad habbits ▪ Unused variable ▪ Copy-Paste ▪ Unit Test ▪ Commit comments
  • 27.
    4. Personal Experience Check my code before commit ▪ Use «pre-commit» hook ▪ Fired before commit ▪ Can stop commit process
  • 28.
    4. Personal Experience «php -l» syntax check ▪ Syntax errors ▪ Unused variables
  • 29.
    4. Personal Experience «phpcpd» tool ▪ Copy/Paste Detector (CPD) for PHP code
  • 30.
    4. Personal Experience PHPCodesniffer ▪ PHP, JavaScript and CSS files ▪ Detects violations of a defined set of coding standards
  • 31.
    4. Personal Experience ▪ «pre-commit» hook
  • 32.
    4. Personal Experience Commit message ▪ «prepare-commit-msg» hook ▪ Fired before comment editor ▪ You can change default message ▪ «commit-msg» hook ▪ Validate commit comment
  • 33.
    4. Personal Experience Improvement ▪ Check view files for XSS ▪ Check test implementation for methods ▪ Check log implementation ▪ Check if test the test suite failed because of my commit ▪ Validate Jira/Mingle case id
  • 34.