"Git Hooked!" Using Git hooks to improve your software development process

Post on 02-Jul-2015

490 views 0 download

description

Famous last words: "Works for me!" Sometimes, even though code works for you, when you push it to the remote repository or install it on the production site, suddenly you're faced with pesky errors that escaped the testing process. The later bugs are found during development, the more expensive a project becomes in terms of time, frustration, and money. One way to improve your code quality is to use automated testing with Git hooks. In this session, Milton Bryant will walk you through some practical applications of automated testing using Git hooks. He'll demonstrate how to get Git hooks working with existing PHPUnit tests, to allow you to test your code as you commit it. Presented at the Joomla World Conference 2014 in Cancun, Mexico - November 7, 2014

Transcript of "Git Hooked!" Using Git hooks to improve your software development process

Milton BryantDevOps Lead

for Polished Geek

GitHooked!

Milton BryantDevOps Lead at Polished Geek

Working with Joomla since 2010

Email - Milton@PolishedGeek.com

Twitter - @Krealic

What hooks are &

how to use them

Demo #1

Triggering unit test(s) with pre-commit git hook

Changes to

CommitCommit Push Repo

Update

Local Remote

pre-commit

prepare-commit-msg

commit-msg

post-commit

pre-receive

update

post-receive

Changes to

CommitCommit Push Repo

Update

Local Remote

pre-commit

prepare-commit-msg

commit-msg

post-commit

pre-receive

update

post-receive

CheckoutRebase

post-checkoutpre-rebase

Merge

post-merge

Changes to

CommitCommit Push Repo

Update

Local Remote

pre-commit

prepare-commit-msg

commit-msg

post-commit

pre-receive

update

post-receive

pre-commitcode validationunit testscheck for missing files

If fail, aborts with message and no commit

Alert you to merge conflict code inside of files

Execute Scripts

Changes to

CommitCommit Push Repo

Update

Local Remote

pre-commit

prepare-commit-msg

commit-msg

post-commit

pre-receive

update

post-receive

prepare-commit-msgedit pre-defined template messages

Changes to

CommitCommit Push Repo

Update

Local Remote

pre-commit

prepare-commit-msg

commit-msg

post-commit

pre-receive

update

post-receive

commit-msgruns during commituse to ensure standards followed

Example: abort commit if JIRA issue resolution comments missing

Send a pre-defined message or enforce commit signature policy

Changes to

CommitCommit Push Repo

Update

Local Remote

pre-commit

prepare-commit-msg

commit-msg

post-commit

pre-receive

update

post-receive

post-commitruns only after successful commituse for notifications

Notify users when commits or pushes have been made

Changes to

CommitCommit Push Repo

Update

Local Remote

pre-commit

prepare-commit-msg

commit-msg

post-commit

pre-receive

update

post-receive

pre-receiveenforce dev policies

can reject entire push

Generate/update ticket or issue under related project

Changes to

CommitCommit Push Repo

Update

Local Remote

pre-commit

prepare-commit-msg

commit-msg

post-commit

pre-receive

update

post-receive

updateexecutes per branch

updatedPass/Fail per branch

updated

“mini-pre-receive”

Changes to

CommitCommit Push Repo

Update

Local Remote

pre-commit

prepare-commit-msg

commit-msg

post-commit

pre-receive

update

post-receive

post-receiveteam notifications

continuous integration

only runs after successful update

Build Log Files

Relocate Files

Demo #2Sending a notification to Slack with the post-commit git hook

Top 5 Tips

Tip #1By default, git hooks are not shared to the remote repository.

Tip #2You can create a symbolic link from a “hooks” directory

Tip #3If responses flicker too fast on the screen, pool them to a file.

Tip #4It is possible to bypass hooks by using --no-verify, --no-merge or –no-checkout

Tip #5With git hooks, you can…

Milton BryantDevOps Lead

milton@polishedgeek.com@KrealicPolishedGeek.com @PolishedGeek

Slides available online https://PolishedGeek.com/githooked

??? ??