Class: Overcommit::GitHook::Whitespace

Inherits:
HookSpecificCheck show all
Includes:
HookRegistry
Defined in:
lib/overcommit/plugins/pre_commit/whitespace.rb

Instance Method Summary collapse

Methods included from HookRegistry

included

Methods inherited from HookSpecificCheck

file_type, friendly_name, #initialize, #name, required!, #skip?, skippable?, #staged, stealth!, #stealth?

Constructor Details

This class inherits a constructor from Overcommit::GitHook::HookSpecificCheck

Instance Method Details

#run_checkObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/overcommit/plugins/pre_commit/whitespace.rb', line 5

def run_check
  paths = staged.collect(&:path).join(' ')

  # Catches hard tabs
  output = `grep -Inl "\t" #{paths}`
  unless output.empty?
    return :stop, "Don't use hard tabs:\n#{output}"
  end

  # Catches trailing whitespace, conflict markers etc
  output = `git diff --check --cached`
  return :stop, output unless $?.exitstatus.zero?

  :good
end