Class: Overcommit::GitHook::BaseHook

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

Direct Known Subclasses

CommitMessageHook, PreCommitHook

Instance Method Summary collapse

Constructor Details

#initializeBaseHook

Returns a new instance of BaseHook.



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

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

Instance Method Details

#run(*args) ⇒ Object



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

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
      run_and_filter_check(check)
    end
  end

  reporter.print_result
end

#skip_checksObject



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

def skip_checks
  @skip_checks ||= ENV.fetch('SKIP_CHECKS', '').split(/[:, ]/)
end