SlideShare a Scribd company logo
1 of 18
Download to read offline
You're Doing it Wrong:
              Commit Hooks!

                          or
           Commit Hooks: the Subtle Hammer


Ben McGraw
Sr. Software Engineer, IMVU Inc.
ben@imvu.com
@bengrue
What are commit hooks?

A way to run automated actions before your local changes get
committed to your code repository.
What are commit hooks?

A way to run automated actions before your local changes get
committed to your code repository.
A way to make the computer check all those annoying little
repetitive tasks before your code goes on your permanent
record.
Computers are good at repetition.

(People are bad at repetition...
and good about forgetting little things!)

Make the computer do the repetitive,
boring stuff so you can focus on the
interesting code.
How do I make them?

In SVN:
as the SVN user, go to /PATH_TO_REPO/hooks/ and make an
executable script file in your favorite shell scripting language.


In GIT:
Basically the same... but there's a lot more options/specific
hooks available (see link at the end).
How do I make them?

The basic principle is the same in both:

1. The script receives text about the files you're attempting to
commit.

2. You inspect those files for rules you make yourself.

3. If you want the commit to not get through to the repository,
return an error code (and print out an error message to
STDERR).

4. Otherwise, your commit continues on to the repository.
Best Practices

1. Subdivide each individual check into it's own function.

2. Give each individual check it's own passphrase to skip it.
What can you use them to do?
Enforce Coding Conventions
- Prevent Code that doesn't allow Linting (Static Analysis!)

- Enforcing Company/Project-specific coding style guidelines

  - For example, IMVU has commit hooks to prevent:
     - tabs from being committed

     - leading-underscored ('lazy private') functions from being
       used outside of a module.

     - using a module's name in a function
       (e.g., customer::get() is good,
        customer::get_customer() is bad.)

- Passphrase to skip is per type ("Skip whitespace check.",
"Skip module check.", etc... )
Running tests as part of your workflow

- One of the simplest way to integrate test-running into a coding
workflow

- If you want acceptance tests, and you don't prevent commits
upon failure, you're Doing It Wrong (but that's a seperate talk).

- Running tests-pre commit doesn't scale to a large team / large
number of tests
Continuous Deployment?

- If you're doing a Continuous Deployment System, commit
hooks are a simple but critical element of your system...

    If your build system is red, you must prevent commits.




- Passphrase to commit through this:
   "Fixing buildbot"
Locking Down Sensitive Areas

- Some areas of your architechture are incredibly sensitive (e.
g., low-level database/memcache libraries, payment
processing, )

- Try to use this sparingly (make a blanklist of files, not a
whitelist) since it breaks workflow and halts engineer velocity to
have to verify everything on every file.




- Passphrase to commit through this:
   "Reviewed by XXX" where XXX is the name of an engineer.
Enforcing Social Policies

- You can enforce a Code Freeze during weekends and
holidays to prevent committing to the main code line when
there's minimal staff around.

  - Lowers stress for ops during off-hours

  - Engineers can commit to branches during the weekend to
work unimpeded
Enforcing Social Policies

- We found this useful at IMVU for years, but refinement of our
entire Continuous Deployment system has recently made us
reconsider preventing weekend commits, so we changed policy!

- Passphrase to commit on weekends is a password that is listed on
the internal wiki for the weekend commit policy. The passphrase is
changed every time we change the policy.

- The rejection error message itself contains the link to the wiki
page with the current policy and the passphrase.
The Shibboleth of Saving Face

Problem:
Sometimes you are proving something to yourself in your
sandbox (noodling through a problem) and you don't want this
code going out.

Sometimes you forget and commit that code.

Solution:
A commit hook checking for the phrase "DO NOT COMMIT".

Now when you noodle, you start it with that phrase in a
comment and your ass is covered.

Override: "Ignore Do Not Commit"
Passive Education

Not strictly "coding conventions" in the traditional sense, but
good habits based on context.

For example:
$_REQUEST bad in PHP, $_GET/$_POST are good...

...so forbid access of $_REQUEST and link to a webpage that
explains why, and provide a short blurb of how to correct the
issue.


For these types of rules, no specific "skip this" message
Further reading (yay homework)


- http://wordaligned.org/articles/a-subversion-pre-commit-hook
  General how-to for SVN pre-commit hooks

- http://book.git-scm.com/5_git_hooks.html
  General how-to for all sorts of GIT commit hooks

- http://eng.wealthfront.com/2011/03/corrective-action-with-gits-
pre-commit.html
  Corrective Actions with GIT commit hooks

- http://engineering.imvu.com/
  We do cool things, and talk about workflow/build systems a lot
Questions?




Ben McGraw - @bengrue

More Related Content

What's hot

Comments: Why not What
Comments: Why not WhatComments: Why not What
Comments: Why not WhatSean Kelly
 
Fall 2011 PHP Class - Session 1
Fall 2011 PHP Class - Session 1Fall 2011 PHP Class - Session 1
Fall 2011 PHP Class - Session 1jimbojsb
 
Best Practices For Writing Super Readable Code
Best Practices For Writing Super Readable CodeBest Practices For Writing Super Readable Code
Best Practices For Writing Super Readable CodeAnsviaLab
 
A quick guide to some prominent Ruby on Rails learning materials
A quick guide to some prominent Ruby on Rails learning materialsA quick guide to some prominent Ruby on Rails learning materials
A quick guide to some prominent Ruby on Rails learning materialsThomas Elam
 
2019 PHP Serbia - Boosting your performance with Blackfire
2019 PHP Serbia - Boosting your performance with Blackfire2019 PHP Serbia - Boosting your performance with Blackfire
2019 PHP Serbia - Boosting your performance with BlackfireMarko Mitranić
 
Developing The Web
Developing The WebDeveloping The Web
Developing The Webtimoh
 
OOP paradigm, principles of good design and architecture of Java applications
OOP paradigm, principles of good design and architecture of Java applicationsOOP paradigm, principles of good design and architecture of Java applications
OOP paradigm, principles of good design and architecture of Java applicationsMikalai Alimenkou
 
Java 8, the Good, the Bad and the Ugly
Java 8, the Good, the Bad and the UglyJava 8, the Good, the Bad and the Ugly
Java 8, the Good, the Bad and the UglyMikalai Alimenkou
 

What's hot (8)

Comments: Why not What
Comments: Why not WhatComments: Why not What
Comments: Why not What
 
Fall 2011 PHP Class - Session 1
Fall 2011 PHP Class - Session 1Fall 2011 PHP Class - Session 1
Fall 2011 PHP Class - Session 1
 
Best Practices For Writing Super Readable Code
Best Practices For Writing Super Readable CodeBest Practices For Writing Super Readable Code
Best Practices For Writing Super Readable Code
 
A quick guide to some prominent Ruby on Rails learning materials
A quick guide to some prominent Ruby on Rails learning materialsA quick guide to some prominent Ruby on Rails learning materials
A quick guide to some prominent Ruby on Rails learning materials
 
2019 PHP Serbia - Boosting your performance with Blackfire
2019 PHP Serbia - Boosting your performance with Blackfire2019 PHP Serbia - Boosting your performance with Blackfire
2019 PHP Serbia - Boosting your performance with Blackfire
 
Developing The Web
Developing The WebDeveloping The Web
Developing The Web
 
OOP paradigm, principles of good design and architecture of Java applications
OOP paradigm, principles of good design and architecture of Java applicationsOOP paradigm, principles of good design and architecture of Java applications
OOP paradigm, principles of good design and architecture of Java applications
 
Java 8, the Good, the Bad and the Ugly
Java 8, the Good, the Bad and the UglyJava 8, the Good, the Bad and the Ugly
Java 8, the Good, the Bad and the Ugly
 

Similar to Commit Hooks: the Subtle Hammer

Chelberg ptcuser 2010
Chelberg ptcuser 2010Chelberg ptcuser 2010
Chelberg ptcuser 2010Clay Helberg
 
Writing code for people
Writing code for peopleWriting code for people
Writing code for peopleAlexey Ivanov
 
debugging (1).ppt
debugging (1).pptdebugging (1).ppt
debugging (1).pptjerlinS1
 
An important characteristic of a test suite that is computed by a dynamic ana...
An important characteristic of a test suite that is computed by a dynamic ana...An important characteristic of a test suite that is computed by a dynamic ana...
An important characteristic of a test suite that is computed by a dynamic ana...jeyasrig
 
Workshop - The Little Pattern That Could.pdf
Workshop - The Little Pattern That Could.pdfWorkshop - The Little Pattern That Could.pdf
Workshop - The Little Pattern That Could.pdfTobiasGoeschel
 
Guide to Destroying Codebases The Demise of Clever Code
Guide to Destroying Codebases   The Demise of Clever CodeGuide to Destroying Codebases   The Demise of Clever Code
Guide to Destroying Codebases The Demise of Clever CodeGabor Varadi
 
ITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
ITARC15 Workshop - Architecting a Large Software Project - Lessons LearnedITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
ITARC15 Workshop - Architecting a Large Software Project - Lessons LearnedJoão Pedro Martins
 
Software Security : From school to reality and back!
Software Security : From school to reality and back!Software Security : From school to reality and back!
Software Security : From school to reality and back!Peter Hlavaty
 
An Introduction to unit testing
An Introduction to unit testingAn Introduction to unit testing
An Introduction to unit testingSteven Casey
 
Topic production code
Topic production codeTopic production code
Topic production codeKavi Kumar
 
Performant Django - Ara Anjargolian
Performant Django - Ara AnjargolianPerformant Django - Ara Anjargolian
Performant Django - Ara AnjargolianHakka Labs
 
C++ Restrictions for Game Programming.
C++ Restrictions for Game Programming.C++ Restrictions for Game Programming.
C++ Restrictions for Game Programming.Richard Taylor
 
DevOps Days Vancouver 2014 Slides
DevOps Days Vancouver 2014 SlidesDevOps Days Vancouver 2014 Slides
DevOps Days Vancouver 2014 SlidesAlex Cruise
 
Architecting a Large Software Project - Lessons Learned
Architecting a Large Software Project - Lessons LearnedArchitecting a Large Software Project - Lessons Learned
Architecting a Large Software Project - Lessons LearnedJoão Pedro Martins
 
Medium Trust for Umbraco
Medium Trust for UmbracoMedium Trust for Umbraco
Medium Trust for UmbracoWarren Buckley
 
What Are We Still Doing Wrong
What Are We Still Doing WrongWhat Are We Still Doing Wrong
What Are We Still Doing Wrongafa reg
 
Dev buchan 30 proven tips
Dev buchan 30 proven tipsDev buchan 30 proven tips
Dev buchan 30 proven tipsBill Buchan
 

Similar to Commit Hooks: the Subtle Hammer (20)

Chelberg ptcuser 2010
Chelberg ptcuser 2010Chelberg ptcuser 2010
Chelberg ptcuser 2010
 
Writing code for people
Writing code for peopleWriting code for people
Writing code for people
 
debugging (1).ppt
debugging (1).pptdebugging (1).ppt
debugging (1).ppt
 
An important characteristic of a test suite that is computed by a dynamic ana...
An important characteristic of a test suite that is computed by a dynamic ana...An important characteristic of a test suite that is computed by a dynamic ana...
An important characteristic of a test suite that is computed by a dynamic ana...
 
Testing 101
Testing 101Testing 101
Testing 101
 
Workshop - The Little Pattern That Could.pdf
Workshop - The Little Pattern That Could.pdfWorkshop - The Little Pattern That Could.pdf
Workshop - The Little Pattern That Could.pdf
 
Guide to Destroying Codebases The Demise of Clever Code
Guide to Destroying Codebases   The Demise of Clever CodeGuide to Destroying Codebases   The Demise of Clever Code
Guide to Destroying Codebases The Demise of Clever Code
 
ITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
ITARC15 Workshop - Architecting a Large Software Project - Lessons LearnedITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
ITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
 
Software Security : From school to reality and back!
Software Security : From school to reality and back!Software Security : From school to reality and back!
Software Security : From school to reality and back!
 
An Introduction to unit testing
An Introduction to unit testingAn Introduction to unit testing
An Introduction to unit testing
 
Topic production code
Topic production codeTopic production code
Topic production code
 
Performant Django - Ara Anjargolian
Performant Django - Ara AnjargolianPerformant Django - Ara Anjargolian
Performant Django - Ara Anjargolian
 
C++ Restrictions for Game Programming.
C++ Restrictions for Game Programming.C++ Restrictions for Game Programming.
C++ Restrictions for Game Programming.
 
DevOps Days Vancouver 2014 Slides
DevOps Days Vancouver 2014 SlidesDevOps Days Vancouver 2014 Slides
DevOps Days Vancouver 2014 Slides
 
Git Makes Me Angry Inside
Git Makes Me Angry InsideGit Makes Me Angry Inside
Git Makes Me Angry Inside
 
Architecting a Large Software Project - Lessons Learned
Architecting a Large Software Project - Lessons LearnedArchitecting a Large Software Project - Lessons Learned
Architecting a Large Software Project - Lessons Learned
 
Debugging
DebuggingDebugging
Debugging
 
Medium Trust for Umbraco
Medium Trust for UmbracoMedium Trust for Umbraco
Medium Trust for Umbraco
 
What Are We Still Doing Wrong
What Are We Still Doing WrongWhat Are We Still Doing Wrong
What Are We Still Doing Wrong
 
Dev buchan 30 proven tips
Dev buchan 30 proven tipsDev buchan 30 proven tips
Dev buchan 30 proven tips
 

Recently uploaded

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 

Recently uploaded (20)

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 

Commit Hooks: the Subtle Hammer

  • 1. You're Doing it Wrong: Commit Hooks! or Commit Hooks: the Subtle Hammer Ben McGraw Sr. Software Engineer, IMVU Inc. ben@imvu.com @bengrue
  • 2. What are commit hooks? A way to run automated actions before your local changes get committed to your code repository.
  • 3. What are commit hooks? A way to run automated actions before your local changes get committed to your code repository. A way to make the computer check all those annoying little repetitive tasks before your code goes on your permanent record.
  • 4. Computers are good at repetition. (People are bad at repetition... and good about forgetting little things!) Make the computer do the repetitive, boring stuff so you can focus on the interesting code.
  • 5. How do I make them? In SVN: as the SVN user, go to /PATH_TO_REPO/hooks/ and make an executable script file in your favorite shell scripting language. In GIT: Basically the same... but there's a lot more options/specific hooks available (see link at the end).
  • 6. How do I make them? The basic principle is the same in both: 1. The script receives text about the files you're attempting to commit. 2. You inspect those files for rules you make yourself. 3. If you want the commit to not get through to the repository, return an error code (and print out an error message to STDERR). 4. Otherwise, your commit continues on to the repository.
  • 7. Best Practices 1. Subdivide each individual check into it's own function. 2. Give each individual check it's own passphrase to skip it.
  • 8. What can you use them to do?
  • 9. Enforce Coding Conventions - Prevent Code that doesn't allow Linting (Static Analysis!) - Enforcing Company/Project-specific coding style guidelines - For example, IMVU has commit hooks to prevent: - tabs from being committed - leading-underscored ('lazy private') functions from being used outside of a module. - using a module's name in a function (e.g., customer::get() is good, customer::get_customer() is bad.) - Passphrase to skip is per type ("Skip whitespace check.", "Skip module check.", etc... )
  • 10. Running tests as part of your workflow - One of the simplest way to integrate test-running into a coding workflow - If you want acceptance tests, and you don't prevent commits upon failure, you're Doing It Wrong (but that's a seperate talk). - Running tests-pre commit doesn't scale to a large team / large number of tests
  • 11. Continuous Deployment? - If you're doing a Continuous Deployment System, commit hooks are a simple but critical element of your system... If your build system is red, you must prevent commits. - Passphrase to commit through this: "Fixing buildbot"
  • 12. Locking Down Sensitive Areas - Some areas of your architechture are incredibly sensitive (e. g., low-level database/memcache libraries, payment processing, ) - Try to use this sparingly (make a blanklist of files, not a whitelist) since it breaks workflow and halts engineer velocity to have to verify everything on every file. - Passphrase to commit through this: "Reviewed by XXX" where XXX is the name of an engineer.
  • 13. Enforcing Social Policies - You can enforce a Code Freeze during weekends and holidays to prevent committing to the main code line when there's minimal staff around. - Lowers stress for ops during off-hours - Engineers can commit to branches during the weekend to work unimpeded
  • 14. Enforcing Social Policies - We found this useful at IMVU for years, but refinement of our entire Continuous Deployment system has recently made us reconsider preventing weekend commits, so we changed policy! - Passphrase to commit on weekends is a password that is listed on the internal wiki for the weekend commit policy. The passphrase is changed every time we change the policy. - The rejection error message itself contains the link to the wiki page with the current policy and the passphrase.
  • 15. The Shibboleth of Saving Face Problem: Sometimes you are proving something to yourself in your sandbox (noodling through a problem) and you don't want this code going out. Sometimes you forget and commit that code. Solution: A commit hook checking for the phrase "DO NOT COMMIT". Now when you noodle, you start it with that phrase in a comment and your ass is covered. Override: "Ignore Do Not Commit"
  • 16. Passive Education Not strictly "coding conventions" in the traditional sense, but good habits based on context. For example: $_REQUEST bad in PHP, $_GET/$_POST are good... ...so forbid access of $_REQUEST and link to a webpage that explains why, and provide a short blurb of how to correct the issue. For these types of rules, no specific "skip this" message
  • 17. Further reading (yay homework) - http://wordaligned.org/articles/a-subversion-pre-commit-hook General how-to for SVN pre-commit hooks - http://book.git-scm.com/5_git_hooks.html General how-to for all sorts of GIT commit hooks - http://eng.wealthfront.com/2011/03/corrective-action-with-gits- pre-commit.html Corrective Actions with GIT commit hooks - http://engineering.imvu.com/ We do cool things, and talk about workflow/build systems a lot