$30 off During Our Annual Pro Sale. View Details »

Git Hooks: How to Make Friends

Git Hooks: How to Make Friends

Joseph Hsu

April 14, 2012
Tweet

More Decks by Joseph Hsu

Other Decks in Programming

Transcript

  1. by Joseph Hsu
    GIT HOOKS
    HOW TO
    MAKE FRIENDS

    View Slide

  2. GIT HOOKS
    by Joseph Hsu
    HOW TO
    MAKE FRIENDS

    View Slide

  3. @JHSU
    Joe Hsu

    View Slide

  4. We all use git (right?)

    View Slide

  5. DVCS - distributed version control system

    View Slide

  6. View Slide

  7. View Slide

  8. View Slide

  9. I wish I could automate...

    View Slide

  10. too lazy to...

    View Slide

  11. Git hooks

    View Slide

  12. Git hooks
    http://book.git-scm.com/5_git_hooks.html
    Hooks are little scripts you can place in $GIT_DIR/
    hooks directory to trigger action at certain points.

    View Slide

  13. post-commit
    no parameters
    cannot affect the outcome of git-commit

    View Slide

  14. pre-commit
    run tests, linting

    View Slide

  15. post-receive
    #

    View Slide

  16. and more...

    View Slide

  17. setup

    View Slide

  18. where?
    project .git/hooks
    new repos /usr/share/git-core/templates/hooks/

    View Slide

  19. chmod +x

    View Slide

  20. post-hook
    What happens after depends on exit status,
    exit of non-zero leaves dirty state

    View Slide

  21. pre-commit
    #!/usr/bin/env bash
    exit 1

    View Slide

  22. #!/usr/bin/env bash
    git reset HEAD^ --hard
    post-commit

    View Slide

  23. Useful examples

    View Slide

  24. cowsay
    commit-msg
    * WOOF * * WOOF *

    View Slide

  25. fixing bugs, BRO
    commit-msg

    View Slide

  26. git commit -m “stuff”
    commit-msg

    View Slide

  27. View Slide

  28. View Slide

  29. View Slide

  30. AlTeRnAtInG cAsE
    commit-msg

    View Slide

  31. https://github.com/jhsu/githooks

    View Slide

  32. Thanks.

    View Slide