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

Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
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
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 

Recently uploaded (20)

Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
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
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 

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