overcommit 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,7 +27,7 @@ module Overcommit
27
27
 
28
28
  # Ignore a check if it only applies to a specific file type and there
29
29
  # are no staged files of that type in the tree
30
- next if check_class.filetype && check.staged.empty?
30
+ next if check_class.filetypes && check.staged.empty?
31
31
 
32
32
  reporter.with_status(check) do
33
33
  run_and_filter_check(check)
@@ -73,7 +73,8 @@ module Overcommit
73
73
  def run_and_filter_check(check)
74
74
  status, output = check.run_check
75
75
 
76
- output = output.to_s
76
+ # Some checks output a list of lines. Join those lines together with newlines.
77
+ output = Array[output].flatten.join("\n")
77
78
 
78
79
  unless output.empty?
79
80
  check.staged.each do |staged_file|
@@ -13,7 +13,7 @@ module Overcommit
13
13
 
14
14
  class HookSpecificCheck
15
15
  class << self
16
- attr_accessor :filetype, :stealth, :required
16
+ attr_accessor :filetypes, :stealth, :required
17
17
 
18
18
  def stealth!
19
19
  self.stealth = true
@@ -52,7 +52,8 @@ module Overcommit
52
52
 
53
53
  def staged
54
54
  @staged ||= modified_files.map do |filename|
55
- if self.class.filetype.nil? || filename.end_with?(".#{self.class.filetype}")
55
+ filetypes = Array(self.class.filetypes).map { |type| ".#{type}" }
56
+ if filetypes.empty? || filename.end_with?(*filetypes)
56
57
  StagedFile.new(filename)
57
58
  end
58
59
  end.compact
@@ -91,8 +92,11 @@ module Overcommit
91
92
  take_while { |line| !line.start_with?('diff --git') }
92
93
  end
93
94
 
94
- def self.file_type(type)
95
- self.filetype = type
95
+ class << self
96
+ def file_type(*types)
97
+ self.filetypes = types
98
+ end
99
+ alias file_types file_type
96
100
  end
97
101
  end
98
102
  end
@@ -1,7 +1,7 @@
1
1
  module Overcommit::GitHook
2
2
  class RubyStyle < HookSpecificCheck
3
3
  include HookRegistry
4
- file_type :rb
4
+ file_types :rb, :rake
5
5
 
6
6
  def run_check
7
7
  unless in_path?('rubocop')
@@ -1,7 +1,7 @@
1
1
  module Overcommit::GitHook
2
2
  class RubySyntax < HookSpecificCheck
3
3
  include HookRegistry
4
- file_type :rb
4
+ file_types :rb, :rake
5
5
 
6
6
  def run_check
7
7
  clean = true
@@ -33,7 +33,7 @@ module Overcommit
33
33
  exit 1
34
34
  when :stop
35
35
  log.warning "*** One or more #{@name} checks needs attention"
36
- log.warning "*** If you really want to commit, use SKIP_CHECKS"
36
+ log.warning '*** If you really want to commit, use SKIP_CHECKS'
37
37
  log.warning "*** (takes a space-separated list of checks to skip, or 'all')"
38
38
  exit 1
39
39
  end
@@ -59,7 +59,8 @@ module Overcommit
59
59
  log.error 'FAILED'
60
60
  print_report output
61
61
  when :warn
62
- log.warning output
62
+ log.warning 'WARNING'
63
+ print_report output
63
64
  when :stop
64
65
  log.warning 'UH OH'
65
66
  print_report output
@@ -76,8 +77,14 @@ module Overcommit
76
77
  return :good
77
78
  end
78
79
 
79
- def print_report(*report)
80
- log.log report.flatten.map { |line| " #{line}" }.join("\n")
80
+ OUTPUT_INDENT = ' ' * 4
81
+ def print_report(output)
82
+ unless output.empty?
83
+ # Take each line of output and add indentation so it nests under check
84
+ # name (except for the last newline if there is one)
85
+ output = OUTPUT_INDENT + output.gsub(/\n(?!$)/, "\n#{OUTPUT_INDENT}")
86
+ log.log output
87
+ end
81
88
  end
82
89
  end
83
90
  end
@@ -1,3 +1,3 @@
1
1
  module Overcommit
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: overcommit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-20 00:00:00.000000000 Z
12
+ date: 2013-07-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec