Class: Overcommit::GitHook::BaseHook

Inherits:
Object
  • Object
show all
Includes:
ConsoleMethods
Defined in:
lib/overcommit/git_hook.rb

Direct Known Subclasses

CommitMessageHook, PreCommitHook

Instance Method Summary collapse

Methods included from ConsoleMethods

#bold, #error, #notice, #success, #warning

Constructor Details

#initializeBaseHook

Returns a new instance of BaseHook.



6
7
8
9
10
11
12
13
# File 'lib/overcommit/git_hook.rb', line 6

def initialize
  Overcommit.config.desired_plugins.each do |plugin|
    require plugin
  end
rescue NameError => ex
  error "Couldn't load plugin: #{ex}"
  exit 0
end

Instance Method Details

#run(*args) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/overcommit/git_hook.rb', line 15

def run(*args)
  # Support 'bare' installation where we don't have any hooks yet.
  # Silently pass.
  exit unless (checks = registered_checks) && checks.any?

  exit if requires_modified_files? && Utils.modified_files.empty?

  reporter = Reporter.new(Overcommit::Utils.hook_name, checks)

  reporter.print_header

  checks.each do |check_class|
    check = check_class.new(*args)
    next if check.skip?

    # Ignore a check if it only applies to a specific file type and there
    # are no staged files of that type in the tree
    next if check_class.filetype && check.staged.empty?

    reporter.with_status(check) do
      check.run_check
    end
  end

  reporter.print_result
end