Module: GitHook

Defined in:
lib/git_hook.rb,
lib/git_hook/io.rb,
lib/git_hook/cli.rb,
lib/git_hook/dsl.rb,
lib/git_hook/hook.rb,
lib/git_hook/hooks.rb,
lib/git_hook/runner.rb,
lib/git_hook/version.rb

Defined Under Namespace

Modules: Hooks Classes: CLI, DSL, Hook, IO, Runner

Constant Summary collapse

WINDOWS =
RbConfig::CONFIG["host_os"] =~ %r!(msdos|mswin|djgpp|mingw)!
NULL =
WINDOWS ? 'NUL' : '/dev/null'
TIMINGS =
[:'applypatch-msg', :'pre-applypatch', :'post-applypatch', :'pre-commit', :'prepare-commit-msg', :'commit-msg', :'post-commit', :'pre-rebase', :'post-checkout', :'post-merge', :'pre-receive', :'update', :'post-receive', :'post-update', :'pre-auto-gc', :'post-rewrite']
VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.git_dirObject



33
34
35
36
37
38
39
# File 'lib/git_hook.rb', line 33

def git_dir
  @git_dir ||= begin
               dir = `git rev-parse --git-dir 2> #{NULL}`.strip
               raise NotAGitRepository unless $? == 0
               Pathname.new(dir).expand_path
             end
end

.hooks_dirObject



41
42
43
# File 'lib/git_hook.rb', line 41

def hooks_dir
  git_dir.join('hooks')
end

.ioObject



25
26
27
# File 'lib/git_hook.rb', line 25

def io
  @io ||= GitHook::IO.new
end

.repo_dirObject



29
30
31
# File 'lib/git_hook.rb', line 29

def repo_dir
  @repo_dir ||= Pathname.new(Dir.pwd).join(`git rev-parse --show-cdup 2> #{NULL}`.strip).expand_path
end

.with_pretty_exception(&block) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/git_hook.rb', line 13

def with_pretty_exception(&block)
  begin
    block.call
  rescue Exception => exception
    GitHook.io.error(exception.class)
    GitHook.io.info(">> #{exception.message}")
    exception.backtrace.each do | backtrace |
      GitHook.io.warn("+ #{backtrace}")
    end
  end
end