Project

git-hooks

0.01
No commit activity in last 3 years
No release in over 3 years
There's a lot of open issues
It stores git hooks and force git hooks installation.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.6
>= 0.7.0
>= 0
~> 3.0

Runtime

~> 0.0.9
~> 1.2
~> 0.23
~> 0.19
 Project Readme

Version Dependencies Build Status Coverage Code Climate

GitHooks

This gem provides an interface to write useful git hooks in Ruby. Those hooks can be used when working in projects in any programming language.

Installation

Add this line to your application's Gemfile:

gem 'git-hooks'

And then execute:

$ bundle

Or install it yourself as:

$ gem install git-hooks

Usage

Install git_hooks on your project.

$ cd /path/to/project
$ git_hooks install pre-commit [--force]

Create configuration file

Create a .git_hooks.yml on project root.

$ cd /path/to/project
$ git_hooks init

By now you will find the following built-in hooks:

  • Prevent commits on master branch.
  • Prevent commits with rubocop offenses.
  • Prevent commits with broken rspec tests.
  • Prevent commits with debugger.
  • Prevent commits with trailing white space.

Warning about Rubocop pre-commit use_stash option:

This feature is yet experimental. Be aware that in some odd circumstances you may encounter merge conflicts when applying the stash.

Ensure hooks existence

To ensure that hooks exists on .git/hooks, include the following line on your application's start-up code (e.g. config/environments/development.rb or config/environments/test.rb for a rails app).

GitHooks.validate_hooks!

This will force git_hooks installation before you can run your application. Be sure not to call GitHooks#validate_hooks! on production environments though!

Problems with ruby version

If you run git under other systems such as gitk or Emacs' Magit, you may encounter problems with the ruby version being used to run GitHooks. This happens because those applications don't source the ~/.bashrc file, which is required by ruby version managers such as Rbenv and Rvm.

In order to fix this problem, you can install the hooks by passing your ruby path to the --ruby_path option. For example:

$ git_hooks install pre-commit --ruby_path `which ruby`

You can also manually edit the .git/hooks/{hook-name} file though.

Contributing

  1. Fork it ( https://github.com/stupied4ever/ruby-git-hooks/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request