Giter VIP home page Giter VIP logo

githooks's Introduction

rabbitt-githooks

GitHooks

Githooks provides a framework for creating standard pre-commit and commit-msg hooks for your git repository. These hooks run client side (not on a remote server), and can be used to validate your commits (actual deltas and commit messages), reducing the possibility of broken commits (or bad commit messages) making it into your repository.

Installation

  1. gem install rabbitt-githooks
  2. add rabbitt-githooks to the development group of your project's Gemfile
  3. setup your project to use githooks:
cd /path/to/project
mkdir commit-hooks
githooks attach --path /path/to/commit-hooks

With the hooks installed, you can run the checks against your staged or unstaged deltas before you commit, or just commit your deltas and have the checks run automatically.

Creating Tests

Tests Path

All tests should be located under the path that was defined when attaching githooks to your project. In the following examples we'll assume a project root of /work/projects/railsapp and a hooks path of /work/projects/railsapp/.hooks.

Registration

All hooks must be registered via GitHooks::Hook.register <PHASE>, <BLOCK>

Commands

Sections

Actions

Limiters (aka filters)

on* (action executors)

on_each_file(&block)
on_all_files(&block)
on_argv(&block)

pre-commit vs commit-msg

Command-Line Usage

Listing Attached Tests

To view the list of checks currently attached to your repository:

$ cd /path/to/cms ; githooks list

Main Testing Library with Tests (in execution order):
  Tests loaded from:
    /Users/jdoe/work/repos/myproject/commit-hooks

  Phase PreCommit:
      1: Standards
        1: Validate Ruby Syntax
          Limiter 1: :type -> [:modified, :added]
          Limiter 2: :path -> /^(app|lib)\/.+\.rb$/
        2: No Leading Spaces in Ruby files
          Limiter 1: :type -> [:modified, :added]
          Limiter 2: :path -> /^(app|lib)\/.+\.rb$/
        3: Validate CSS Syntax
          Limiter 1: :type -> [:modified, :added]
          Limiter 2: :path -> /^(app|lib)\/.+css$/
  Phase CommitMsg:
      1: Commit Message
        1: Message Length > 5 characters
        2: Verify no simple commit messages

Manually Running Tests

To run the pre-commit hook on unstaged deltas, run the following command:

$ cd /path/to/cms ; githooks exec --unstaged
===== PreCommit :: Standards =====
  1. [ X ] Validate Ruby Syntax
    X app/models/element.rb:245: syntax error, unexpected keyword_end, expecting end-of-input
  2. [ X ] No Leading Spaces in Ruby files
    X app/models/element.rb:4: _______# something here
    X app/models/element.rb:5: __a = 1
    X app/models/element.rb:6: ____
  3. [ X ] Validate CSS Syntax
    X app/assets/stylesheets/application.css.scss:4 [W] Prefer single quoted strings
    X app/assets/stylesheets/application.css.scss:8 [W] Use // comments everywhere
    X app/assets/stylesheets/application.css.scss:10 [W] Line should be indented 1 spaces, but was indented 2 spaces
    X app/assets/stylesheets/application.css.scss:19 [W] Each selector in a comma sequence should be on its own line
    X app/assets/stylesheets/application.css.scss:20 [W] Properties should be sorted in alphabetical order, with vendor-prefixed extensions before the standardized CSS property
    X app/assets/stylesheets/application.css.scss:22 [W] `0.75` should be written without a leading zero as `.75`
    X app/assets/stylesheets/application.css.scss:23 [W] `border: 0;` is preferred over `border: none;`
    X app/assets/stylesheets/elements.css.scss:35 [W] Commas in function arguments should be followed by a single space
    X app/assets/stylesheets/elements.css.scss:35 [W] Colon after property should be followed by 1 space instead of 0 spaces
    X app/assets/stylesheets/elements.css.scss:35 [W] Commas in function arguments should be followed by a single space

Commit failed due to errors listed above.
Please fix and attempt your commit again.

githooks's People

Contributors

rabbitt avatar rdubya avatar

Stargazers

Conail Stewart avatar Zhouyou avatar Chutian Yang avatar Yunlei Liu avatar Edd Morgan avatar Amit Erandole avatar  avatar  avatar Matt avatar Brandon Weiss avatar george ardeleanu avatar Jonn Beames avatar

Watchers

 avatar  avatar James Cloos avatar  avatar

Forkers

rdubya

githooks's Issues

--unstaged argument no longer works

using the command for githooks exec --unstaged no longer appears to work. getting the following errors:
ERROR: "githooks execute" was called with arguments ["--unstaged"]
Usage: "githooks execute"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.