rabbitt-githooks 1.3.0 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +5 -13
  2. data/Gemfile.lock +29 -19
  3. data/Rakefile +20 -0
  4. data/bin/githooks +2 -1
  5. data/bin/githooks-runner +10 -2
  6. data/lib/githooks.rb +11 -7
  7. data/lib/githooks/action.rb +67 -53
  8. data/lib/githooks/cli.rb +9 -6
  9. data/lib/githooks/commands/config.rb +26 -19
  10. data/lib/githooks/core_ext.rb +2 -1
  11. data/lib/githooks/core_ext/array/extract_options.rb +5 -1
  12. data/lib/githooks/core_ext/array/min_max.rb +4 -4
  13. data/lib/githooks/core_ext/array/select_with_index.rb +1 -1
  14. data/lib/githooks/core_ext/colorize.rb +30 -0
  15. data/lib/githooks/core_ext/object.rb +8 -0
  16. data/lib/githooks/core_ext/pathname.rb +7 -6
  17. data/lib/githooks/core_ext/string.rb +1 -1
  18. data/lib/githooks/core_ext/string/sanitize.rb +51 -0
  19. data/lib/githooks/error.rb +1 -0
  20. data/lib/githooks/hook.rb +21 -26
  21. data/lib/githooks/repository.rb +31 -35
  22. data/lib/githooks/repository/config.rb +16 -24
  23. data/lib/githooks/repository/diff_index_entry.rb +3 -2
  24. data/lib/githooks/repository/file.rb +14 -7
  25. data/lib/githooks/runner.rb +38 -36
  26. data/lib/githooks/section.rb +13 -19
  27. data/lib/githooks/system_utils.rb +132 -47
  28. data/lib/githooks/version.rb +1 -1
  29. data/lib/tasks/dev.task +14 -0
  30. data/rabbitt-githooks.gemspec +18 -15
  31. metadata +58 -33
  32. data/.gitignore +0 -34
  33. data/.hooks/commit-messages.rb +0 -29
  34. data/.hooks/formatting.rb +0 -44
  35. data/.rubocop.yml +0 -87
  36. data/lib/githooks/core_ext/process.rb +0 -9
  37. data/lib/githooks/core_ext/string/strip_empty_lines.rb +0 -9
  38. data/lib/githooks/terminal_colors.rb +0 -62
  39. data/thoughts.txt +0 -56
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZmVlMTFhYmNmYjA2YmM3NWJiMTA1YWNhMjk2MmE5ODhmZjQwZjZlYQ==
5
- data.tar.gz: !binary |-
6
- ZDQ3ZGMwYTI1MGY3NDc3ZmM2NTk0NGJkMjg1NjBlYWU5NTgyN2MwOQ==
2
+ SHA1:
3
+ metadata.gz: d8a2ed779870b84aa9cc8d2a61a1cec2b9ce00bb
4
+ data.tar.gz: 74d1c181b0fb1f3ead9de7fba24cf55485d5e5fc
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- NDQ0YzkzNWQ4Yjc3NjQwYWYzNWQ5ZjIwZmM1MGZlOTQxYTJhNDFiODhjMTNl
10
- ZWVkOGNmOTJhZmNhZGI1NjQ2ZDYxMTNiYzU5ZTA0MTFhMTUwODhkMmQ4MWZk
11
- NzExZTY3MDQyNzAxMzNhMzA4MzU2YTdmOGE5YmUwOWQ1Y2E5YTI=
12
- data.tar.gz: !binary |-
13
- NDZiMTMyZDllMDZjZmE3Yjg2ZTcyODJiMWJkNDAzYjAxNDRjYjViYWY2ZjBm
14
- YWRkNmY5MTc2ZGEyMGRlNDRiZmRiMjAzOGMyOGE0MTk5NDFhMmFlNDliODdj
15
- N2I0MzI4NDY5MTkxNGFmMDhiMWIzZDFmMDA5MWE5NWVlYmFiY2I=
6
+ metadata.gz: 8b5aa0a35e390045e234980f8a132eb4cbf112444df25811e1d7becb50f3a79e85c25810445585743a2a79dcb324c1a50cee34c4202ccd8976fe0f4760b8e759
7
+ data.tar.gz: 3408b935632cb28b2c1ff13f6aacd2b83fdc407b4b3acc881ae29ed76f7d0e6b60ce8edd187fe95fc8b0b53d91b64085066451425d9a554ab0ea2b266b01959a
data/Gemfile.lock CHANGED
@@ -1,43 +1,51 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rabbitt-githooks (1.3.0)
5
- colorize (~> 0.5.8)
4
+ rabbitt-githooks (1.3.2)
5
+ colorize (~> 0.7.0)
6
6
  thor (~> 0.18)
7
7
 
8
8
  GEM
9
9
  remote: http://rubygems.org/
10
10
  specs:
11
11
  ast (2.0.0)
12
- colorize (0.5.8)
12
+ astrolabe (1.3.0)
13
+ parser (>= 2.2.0.pre.3, < 3.0)
14
+ colorize (0.7.5)
13
15
  diff-lcs (1.2.5)
14
- json (1.8.1)
15
- parser (2.1.9)
16
+ docile (1.1.5)
17
+ multi_json (1.10.1)
18
+ parser (2.2.0.2)
16
19
  ast (>= 1.1, < 3.0)
17
- slop (~> 3.4, >= 3.4.5)
18
- powerpack (0.0.9)
20
+ powerpack (0.1.0)
19
21
  rainbow (2.0.0)
20
- rake (10.3.2)
22
+ rake (10.4.2)
21
23
  rspec (2.99.0)
22
24
  rspec-core (~> 2.99.0)
23
25
  rspec-expectations (~> 2.99.0)
24
26
  rspec-mocks (~> 2.99.0)
25
- rspec-core (2.99.1)
26
- rspec-expectations (2.99.1)
27
+ rspec-core (2.99.2)
28
+ rspec-expectations (2.99.2)
27
29
  diff-lcs (>= 1.1.3, < 2.0)
28
- rspec-mocks (2.99.1)
29
- rubocop (0.23.0)
30
- json (>= 1.7.7, < 2)
31
- parser (~> 2.1.9)
32
- powerpack (~> 0.0.6)
30
+ rspec-mocks (2.99.3)
31
+ rubocop (0.29.0)
32
+ astrolabe (~> 1.3)
33
+ parser (>= 2.2.0.1, < 3.0)
34
+ powerpack (~> 0.1)
33
35
  rainbow (>= 1.99.1, < 3.0)
34
36
  ruby-progressbar (~> 1.4)
35
- ruby-lint (2.0.1)
37
+ ruby-lint (2.0.3)
36
38
  parser (~> 2.1, >= 2.1.1)
37
39
  slop (~> 3.4, >= 3.4.7)
38
- ruby-progressbar (1.5.1)
39
- slop (3.5.0)
40
+ ruby-progressbar (1.7.1)
41
+ simplecov (0.9.1)
42
+ docile (~> 1.1.0)
43
+ multi_json (~> 1.0)
44
+ simplecov-html (~> 0.8.0)
45
+ simplecov-html (0.8.0)
46
+ slop (3.6.0)
40
47
  thor (0.19.1)
48
+ yard (0.8.7.6)
41
49
 
42
50
  PLATFORMS
43
51
  ruby
@@ -48,4 +56,6 @@ DEPENDENCIES
48
56
  rake (~> 10.1)
49
57
  rspec (~> 2.14)
50
58
  rubocop (~> 0.18)
51
- ruby-lint (~> 2.0.1)
59
+ ruby-lint (~> 2.0)
60
+ simplecov (~> 0.9)
61
+ yard (~> 0.7)
data/Rakefile CHANGED
@@ -17,3 +17,23 @@ with this program; if not, write to the Free Software Foundation, Inc.,
17
17
  =end
18
18
 
19
19
  require 'bundler/gem_tasks'
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ desc 'Code coverage detail'
29
+ task :simplecov do
30
+ ENV['COVERAGE'] = 'true'
31
+ Rake::Task['test'].execute
32
+ end
33
+
34
+ task default: :test
35
+
36
+ require 'yard'
37
+ YARD::Rake::YardocTask.new
38
+
39
+ Dir['lib/tasks/*.task'].each { |t| load t }
data/bin/githooks CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  if ENV['GITHOOKS_DEV']
4
- $:.unshift(File.expand_path(File.join(File.expand_path(__FILE__), '/../../lib')))
4
+ require 'pathname'
5
+ $:.unshift Pathname.new(__FILE__).dirname.parent.join('lib').realpath.to_s
5
6
  end
6
7
  require 'githooks'
7
8
 
data/bin/githooks-runner CHANGED
@@ -1,8 +1,16 @@
1
1
  #!/usr/bin/env ruby
2
- # rubocop:disable Style/FileName
2
+ # rubocop:disable FileName
3
3
 
4
4
  if ENV['GITHOOKS_DEV']
5
- $:.unshift(File.expand_path(File.join(File.expand_path(__FILE__), '/../../lib')))
5
+ require 'pathname'
6
+ path = Pathname.new(__FILE__).dirname
7
+ $:.unshift(
8
+ if path.to_s.end_with? '.git/hooks'
9
+ path.parent.parent
10
+ else
11
+ path.parent
12
+ end.join('lib').realpath.to_s
13
+ )
6
14
  end
7
15
  require 'githooks'
8
16
 
data/lib/githooks.rb CHANGED
@@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
20
20
  require 'pathname'
21
21
  require 'githooks/error'
22
22
  require 'githooks/core_ext'
23
+ require 'githooks/core_ext/colorize'
23
24
  require 'githooks/version'
24
25
 
25
26
  module GitHooks
@@ -35,7 +36,6 @@ module GitHooks
35
36
  autoload :Repository, 'githooks/repository'
36
37
  autoload :Runner, 'githooks/runner'
37
38
  autoload :SystemUtils, 'githooks/system_utils'
38
- autoload :TerminalColors, 'githooks/terminal_colors'
39
39
 
40
40
  class << self
41
41
  attr_reader :debug, :verbose, :ignore_script
@@ -74,13 +74,17 @@ module GitHooks
74
74
  end
75
75
  end
76
76
 
77
- LIB_PATH = Pathname.new(__FILE__).dirname.realpath
78
- GEM_PATH = LIB_PATH.parent
79
- BIN_PATH = GEM_PATH + 'bin'
77
+ SUCCESS_SYMBOL = '✓'.success! unless defined? SUCCESS_SYMBOL
78
+ FAILURE_SYMBOL = 'X'.failure! unless defined? FAILURE_SYMBOL
79
+ UNKNOWN_SYMBOL = '?'.unknown! unless defined? UNKNOWN_SYMBOL
80
80
 
81
- SCRIPT_PATH = Pathname.new($0)
82
- SCRIPT_NAME = SCRIPT_PATH.basename.to_s
83
- HOOK_NAME = SCRIPT_NAME.to_s
81
+ LIB_PATH = Pathname.new(__FILE__).dirname.realpath unless defined? LIB_PATH
82
+ GEM_PATH = LIB_PATH.parent unless defined? GEM_PATH
83
+ BIN_PATH = GEM_PATH.join('bin') unless defined? BIN_PATH
84
+
85
+ SCRIPT_PATH = Pathname.new($0) unless defined? SCRIPT_PATH
86
+ SCRIPT_NAME = SCRIPT_PATH.basename.to_s unless defined? SCRIPT_NAME
87
+ HOOK_NAME = SCRIPT_NAME.to_s unless defined? HOOK_NAME
84
88
 
85
89
  if ARGV.include? '--ignore-script'
86
90
  ARGV.delete('--ignore-script')
@@ -17,14 +17,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
17
17
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
18
  =end
19
19
 
20
- require 'stringio'
21
- require 'open3'
22
20
  require 'set'
21
+ require 'stringio'
22
+ require 'colorize'
23
+ require_relative 'repository'
23
24
 
24
25
  module GitHooks
25
- class Action # rubocop:disable Style/ClassLength
26
- include TerminalColors
27
-
26
+ class Action # rubocop:disable Metrics/ClassLength
28
27
  attr_reader :title, :section, :on, :limiters
29
28
  attr_reader :success, :errors, :warnings, :benchmark
30
29
  private :section, :on
@@ -55,9 +54,9 @@ module GitHooks
55
54
  status_colorize title
56
55
  end
57
56
 
58
- def state_symbol
59
- return status_colorize('?') unless finished?
60
- status_colorize success? ? '✓' : 'X'
57
+ def status_symbol
58
+ return GitHooks::UNKNOWN_SYMBOL unless finished?
59
+ success? ? GitHooks::SUCCESS_SYMBOL : GitHooks::FAILURE_SYMBOL
61
60
  end
62
61
 
63
62
  %w(finished running waiting).each do |method|
@@ -66,42 +65,61 @@ module GitHooks
66
65
  end
67
66
 
68
67
  def status_colorize(text)
69
- return color_dark_cyan(text) unless finished?
70
- success? ? color_bright_green(text) : color_bright_red(text)
68
+ return text.unknown! unless finished?
69
+ success? ? text.success! : text.failure!
70
+ end
71
+
72
+ def run # rubocop:disable MethodLength, AbcSize
73
+ running!
74
+ with_benchmark do
75
+ with_captured_output {
76
+ begin
77
+ @success &= @on.call
78
+ rescue StandardError => e
79
+ $stderr.puts "Exception thrown during action call: #{e.class.name}: #{e.message}"
80
+ if GitHooks.debug?
81
+ $stderr.puts "#{e.class}: #{e.message}:\n\t#{e.backtrace.join("\n\t")}"
82
+ else
83
+ hooks_files = e.backtrace.select! { |line| line =~ %r{/hooks/} }
84
+ hooks_files.collect! { |line| line.split(':')[0..1].join(':') }
85
+ $stderr.puts " -> in hook file:line, #{hooks_files.join("\n\t")}" unless hooks_files.empty?
86
+ end
87
+ @success = false
88
+ ensure
89
+ finished!
90
+ end
91
+ }
92
+ end
71
93
  end
72
94
 
73
- def run # rubocop:disable MethodLength
74
- warnings, errors = StringIO.new, StringIO.new
95
+ def with_captured_output(&_block)
96
+ fail ArgumentError, 'expected block, none given' unless block_given?
75
97
 
76
98
  begin
77
- running!
78
- $stdout, $stderr = warnings, errors
79
- time_start = Time.now
80
- @success &= @on.call
81
- rescue => error
82
- errors.puts "Exception thrown during action call: #{error.class.name}: #{error.message}"
83
-
84
- if !GitHooks.debug?
85
- hooks_files = error.backtrace.select! { |line| line =~ %r{/hooks/} }
86
- hooks_files.collect! { |line| line.split(':')[0..1].join(':') }
87
- errors.puts " -> in hook file:line, #{hooks_files.join("\n\t")}" unless hooks_files.empty?
88
- else
89
- errors.puts "\t#{error.backtrace.join("\n\t")}"
90
- end
91
-
92
- @success = false
99
+ $stdout = warnings = StringIO.new
100
+ $stderr = errors = StringIO.new
101
+ yield
93
102
  ensure
94
- @benchmark = Time.now - time_start
95
- @errors, @warnings = [errors, warnings].collect do |io|
96
- io.rewind
97
- io.read.split(/\n/)
98
- end
99
-
100
- $stdout, $stderr = STDOUT, STDERR
101
- finished!
103
+ @errors = errors.rewind && errors.read.split(/\n/)
104
+ @warnings = warnings.rewind && warnings.read.split(/\n/)
105
+ $stdout = STDOUT
106
+ $stderr = STDERR
102
107
  end
108
+ end
109
+
110
+ def with_benchmark(&_block)
111
+ fail ArgumentError, 'expected block, none given' unless block_given?
112
+ begin
113
+ start_time = Time.now
114
+ yield
115
+ ensure
116
+ @benchmark = Time.now - start_time
117
+ end
118
+ end
103
119
 
104
- @success
120
+ def respond_to_missing?(method, include_private = false)
121
+ return super unless section.hook.find_command(method)
122
+ true
105
123
  end
106
124
 
107
125
  def method_missing(method, *args, &block)
@@ -123,15 +141,15 @@ module GitHooks
123
141
  end
124
142
 
125
143
  def on_all_files(&block)
126
- @on = ->() { block.call manifest }
144
+ @on = -> { block.call manifest }
127
145
  end
128
146
 
129
147
  def on_argv(&block)
130
- @on = ->() { block.call section.hook.args }
148
+ @on = -> { block.call section.hook.args }
131
149
  end
132
150
 
133
151
  def on(*args, &block)
134
- @on = ->() { block.call(*args) }
152
+ @on = -> { block.call(*args) }
135
153
  end
136
154
 
137
155
  private
@@ -141,19 +159,15 @@ module GitHooks
141
159
  end
142
160
 
143
161
  def run_command(command, *args, &block)
144
- options = args.extract_options
145
- prefix = options.delete(:prefix_output)
146
- args << options
147
-
148
- command.execute(*args, &block).tap do |res|
149
- res.output.split(/\n/).each do |line|
150
- $stdout.puts prefix ? "#{prefix}: #{line}" : line
151
- end
152
-
153
- res.error.split(/\n/).each do |line|
154
- $stderr.puts prefix ? "#{prefix}: #{line}" : line
155
- end
156
- end.status.success?
162
+ prefix = nil
163
+ args.extract_options.tap { |options|
164
+ prefix = options.delete(:prefix_output)
165
+ }
166
+
167
+ result = command.execute(*args, &block)
168
+ result.output_lines(prefix).each { |line| puts line }
169
+ result.error_lines(prefix).each { |line| puts line }
170
+ result.status.success?
157
171
  end
158
172
  end
159
173
  end
data/lib/githooks/cli.rb CHANGED
@@ -1,9 +1,12 @@
1
1
  require 'thor'
2
+ require_relative 'hook'
3
+ require_relative 'runner'
2
4
 
3
5
  module GitHooks
4
6
  module CLI
5
7
  autoload :Config, 'githooks/commands/config'
6
8
 
9
+ # rubocop:disable AbcSize
7
10
  class Base < Thor
8
11
  class_option :verbose, aliases: '-v', type: :boolean, desc: 'verbose output', default: false
9
12
  class_option :debug, aliases: '-d', type: :boolean, desc: 'debug output', default: false
@@ -18,7 +21,7 @@ module GitHooks
18
21
  method_option :repo, aliases: '-r', type: :string, desc: 'Path to repo to run tests on', default: Dir.getwd
19
22
  method_option :hooks, { # rubocop:disable BracesAroundHashParameters
20
23
  type: :array,
21
- desc: 'Path to repo to run tests on',
24
+ desc: 'hooks to attach',
22
25
  enum: Hook::VALID_PHASES,
23
26
  default: Hook::VALID_PHASES
24
27
  }
@@ -27,7 +30,7 @@ module GitHooks
27
30
  GitHooks.debug = !!options['debug']
28
31
 
29
32
  unless options['script'] || options['path']
30
- fail ArgumentError, %q|Neither 'path' nor 'script' were specified - please provide at least one.|
33
+ fail ArgumentError, %q"Neither 'path' nor 'script' were specified - please provide at least one."
31
34
  end
32
35
 
33
36
  Runner.attach(options)
@@ -72,9 +75,9 @@ module GitHooks
72
75
  method_option :repo, aliases: '-r', type: :string, desc: 'Path to repo to run tests on', default: Dir.getwd
73
76
  method_option :'skip-pre', type: :boolean, desc: 'Skip PreRun Scripts', default: false
74
77
  method_option :'skip-post', type: :boolean, desc: 'Skip PostRun Scripts', default: false
75
- method_option :'skip-bundler', type: :boolean, desc: %Q|Don't load bundler gemfile|, default: false
78
+ method_option :'skip-bundler', type: :boolean, desc: %q"Don't load bundler gemfile", default: false
76
79
  method_option :args, type: :array, desc: 'Args to pass to pre/post scripts and main testing script', default: []
77
- def execute(*args)
80
+ def execute
78
81
  GitHooks.verbose = !!options['verbose']
79
82
  GitHooks.debug = !!options['debug']
80
83
 
@@ -82,10 +85,10 @@ module GitHooks
82
85
 
83
86
  if opts['staged']
84
87
  if opts['tracked']
85
- warn %q|--tracked conflicts with --staged. Dropping --tracked...|
88
+ warn '--tracked conflicts with --staged. Dropping --tracked...'
86
89
  opts['tracked'] = false
87
90
  elsif opts['untracked']
88
- warn %q|--untracked conflicts with --staged. Dropping --untracked...|
91
+ warn '--untracked conflicts with --staged. Dropping --untracked...'
89
92
  opts['untracked'] = false
90
93
  end
91
94
  end
@@ -1,3 +1,6 @@
1
+ require 'thor'
2
+ require 'githooks/repository'
3
+
1
4
  module GitHooks
2
5
  module CLI
3
6
  class Config < Thor
@@ -19,26 +22,30 @@ module GitHooks
19
22
  }
20
23
 
21
24
  desc :get, 'display the value for a configuration option'
22
- def get(option_name) # rubocop:disable MethodLength
25
+ def get(option_name) # rubocop:disable MethodLength, AbcSize
23
26
  unless VALID_CONFIG_OPTIONS.include? option_name
24
27
  puts "Invalid option '#{option_name}': expected one of #{VALID_CONFIG_OPTIONS.join(', ')}"
25
28
  return 1
26
29
  end
27
30
 
28
- GitHooks.verbose = true if options['verbose']
29
- GitHooks.debug = true if options['debug']
31
+ GitHooks.verbose = !!options['verbose']
32
+ GitHooks.debug = !!options['debug']
30
33
  options['repo'] ||= GitHooks::Repository.root_path
31
34
 
32
35
  repo_data = GitHooks::Repository::Config.new.get(
33
36
  option_name,
34
- repo_path: options['repo'], global: options['global']
37
+ repo_path: options['repo'],
38
+ global: options['global']
35
39
  )
40
+
36
41
  if repo_data.nil?
37
42
  puts "Repository [#{options['repo']}] option '#{option_name}' is currently not set."
38
43
  return
39
44
  end
40
- [repo_data].flatten.each do |value|
41
- puts "#{option_name}: #{value || 'not set'}"
45
+
46
+ Array(repo_data).flatten.each do |value|
47
+ value ||= 'not set'
48
+ puts "#{option_name}: #{value}"
42
49
  end
43
50
  end
44
51
 
@@ -49,9 +56,9 @@ module GitHooks
49
56
  desc: 'overwrite all existing values.',
50
57
  default: false
51
58
  }
52
- def set(option_name, option_value)
53
- GitHooks.verbose = true if options['verbose']
54
- GitHooks.debug = true if options['debug']
59
+ def set(option_name, option_value) # rubocop:disable AbcSize
60
+ GitHooks.verbose = !!options['verbose']
61
+ GitHooks.debug = !!options['debug']
55
62
  options['repo'] ||= GitHooks::Repository.root_path
56
63
 
57
64
  GitHooks::Repository::Config.new.set(
@@ -66,9 +73,9 @@ module GitHooks
66
73
  end
67
74
 
68
75
  desc :unset, 'Unsets a configuration value'
69
- def unset(option_name, option_value = nil)
70
- GitHooks.verbose = true if options['verbose']
71
- GitHooks.debug = true if options['debug']
76
+ def unset(option_name, option_value = nil) # rubocop:disable AbcSize
77
+ GitHooks.verbose = !!options['verbose']
78
+ GitHooks.debug = !!options['debug']
72
79
  options['repo'] ||= GitHooks::Repository.root_path
73
80
 
74
81
  GitHooks::Repository::Config.new.unset(
@@ -82,25 +89,25 @@ module GitHooks
82
89
  end
83
90
 
84
91
  desc :list, 'Lists all githooks configuration values'
85
- def list
86
- puts options.inspect
87
-
88
- GitHooks.verbose = true if options['verbose']
89
- GitHooks.debug = true if options['debug']
92
+ def list # rubocop:disable AbcSize
93
+ GitHooks.verbose = !!options['verbose']
94
+ GitHooks.debug = !!options['debug']
90
95
 
91
96
  options['repo'] ||= GitHooks::Repository.root_path
92
97
  config = GitHooks::Repository::Config.new
93
98
 
94
99
  githooks = config.list(global: options['global'], repo_path: options['repo'])['githooks']
100
+ return unless githooks
101
+
95
102
  githooks.each do |path, data|
96
103
  puts "Repository #{path}:"
97
- key_size, value_size = data.keys.collect(&:size).max, data.values.collect(&:size).max
104
+ key_size, value_size = data.keys.collect(&:size).maximum, data.values.collect(&:size).maximum
98
105
  data.each do |key, value|
99
106
  [value].flatten.each do |v|
100
107
  printf " %-#{key_size}s : %-#{value_size}s\n", key, v
101
108
  end
102
109
  end
103
- end if githooks
110
+ end
104
111
  end
105
112
  end
106
113
  end