overcommit 0.58.0 → 0.59.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/bin/overcommit +6 -5
  3. data/config/default.yml +1 -1
  4. data/lib/overcommit/cli.rb +14 -13
  5. data/lib/overcommit/command_splitter.rb +2 -0
  6. data/lib/overcommit/configuration.rb +1 -1
  7. data/lib/overcommit/configuration_loader.rb +3 -3
  8. data/lib/overcommit/git_config.rb +1 -0
  9. data/lib/overcommit/git_repo.rb +4 -4
  10. data/lib/overcommit/hook/commit_msg/spell_check.rb +1 -1
  11. data/lib/overcommit/hook/commit_msg/text_width.rb +1 -1
  12. data/lib/overcommit/hook/post_checkout/base.rb +1 -0
  13. data/lib/overcommit/hook/post_commit/git_guilt.rb +2 -1
  14. data/lib/overcommit/hook/pre_commit/bundle_audit.rb +1 -1
  15. data/lib/overcommit/hook/pre_commit/chamber_compare.rb +5 -5
  16. data/lib/overcommit/hook/pre_commit/chamber_security.rb +1 -0
  17. data/lib/overcommit/hook/pre_commit/coffee_lint.rb +1 -1
  18. data/lib/overcommit/hook/pre_commit/css_lint.rb +1 -1
  19. data/lib/overcommit/hook/pre_commit/dart_analyzer.rb +1 -1
  20. data/lib/overcommit/hook/pre_commit/erb_lint.rb +1 -1
  21. data/lib/overcommit/hook/pre_commit/fasterer.rb +1 -1
  22. data/lib/overcommit/hook/pre_commit/foodcritic.rb +3 -1
  23. data/lib/overcommit/hook/pre_commit/hlint.rb +1 -1
  24. data/lib/overcommit/hook/pre_commit/html_tidy.rb +1 -1
  25. data/lib/overcommit/hook/pre_commit/java_checkstyle.rb +1 -1
  26. data/lib/overcommit/hook/pre_commit/js_lint.rb +1 -1
  27. data/lib/overcommit/hook/pre_commit/jsl.rb +1 -1
  28. data/lib/overcommit/hook/pre_commit/kt_lint.rb +1 -1
  29. data/lib/overcommit/hook/pre_commit/license_finder.rb +1 -0
  30. data/lib/overcommit/hook/pre_commit/line_endings.rb +3 -2
  31. data/lib/overcommit/hook/pre_commit/nginx_test.rb +1 -1
  32. data/lib/overcommit/hook/pre_commit/php_cs.rb +1 -1
  33. data/lib/overcommit/hook/pre_commit/php_cs_fixer.rb +1 -1
  34. data/lib/overcommit/hook/pre_commit/php_lint.rb +3 -3
  35. data/lib/overcommit/hook/pre_commit/php_stan.rb +1 -1
  36. data/lib/overcommit/hook/pre_commit/puppet_lint.rb +1 -1
  37. data/lib/overcommit/hook/pre_commit/puppet_metadata_json_lint.rb +1 -1
  38. data/lib/overcommit/hook/pre_commit/pyflakes.rb +1 -1
  39. data/lib/overcommit/hook/pre_commit/pylint.rb +1 -1
  40. data/lib/overcommit/hook/pre_commit/python_flake8.rb +1 -1
  41. data/lib/overcommit/hook/pre_commit/rails_best_practices.rb +1 -1
  42. data/lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb +2 -2
  43. data/lib/overcommit/hook/pre_commit/rst_lint.rb +1 -1
  44. data/lib/overcommit/hook/pre_commit/scalariform.rb +1 -1
  45. data/lib/overcommit/hook/pre_commit/scalastyle.rb +1 -1
  46. data/lib/overcommit/hook/pre_commit/scss_lint.rb +3 -3
  47. data/lib/overcommit/hook/pre_commit/semi_standard.rb +1 -1
  48. data/lib/overcommit/hook/pre_commit/sqlint.rb +1 -1
  49. data/lib/overcommit/hook/pre_commit/standard.rb +1 -1
  50. data/lib/overcommit/hook/pre_commit/stylelint.rb +2 -1
  51. data/lib/overcommit/hook/pre_commit/swift_lint.rb +1 -1
  52. data/lib/overcommit/hook/pre_commit/ts_lint.rb +4 -4
  53. data/lib/overcommit/hook/pre_commit/w3c_css.rb +4 -4
  54. data/lib/overcommit/hook/pre_commit/w3c_html.rb +4 -4
  55. data/lib/overcommit/hook/pre_commit/xml_lint.rb +1 -1
  56. data/lib/overcommit/hook/pre_commit/yaml_lint.rb +1 -1
  57. data/lib/overcommit/hook/pre_commit/yaml_syntax.rb +7 -3
  58. data/lib/overcommit/hook/pre_commit/yard_coverage.rb +0 -1
  59. data/lib/overcommit/hook/pre_push/cargo_test.rb +1 -0
  60. data/lib/overcommit/hook/prepare_commit_msg/base.rb +1 -0
  61. data/lib/overcommit/hook/prepare_commit_msg/replace_branch.rb +1 -1
  62. data/lib/overcommit/hook/shared/bower_install.rb +1 -0
  63. data/lib/overcommit/hook/shared/bundle_install.rb +1 -0
  64. data/lib/overcommit/hook/shared/composer_install.rb +1 -0
  65. data/lib/overcommit/hook/shared/npm_install.rb +1 -0
  66. data/lib/overcommit/hook/shared/pronto.rb +16 -4
  67. data/lib/overcommit/hook/shared/yarn_install.rb +1 -0
  68. data/lib/overcommit/hook_context/helpers/file_modifications.rb +1 -0
  69. data/lib/overcommit/hook_context/helpers/stash_unstaged_changes.rb +3 -0
  70. data/lib/overcommit/hook_context/post_commit.rb +1 -0
  71. data/lib/overcommit/hook_context/pre_push.rb +1 -0
  72. data/lib/overcommit/hook_context/run_all.rb +1 -0
  73. data/lib/overcommit/hook_context.rb +3 -3
  74. data/lib/overcommit/hook_loader/base.rb +3 -3
  75. data/lib/overcommit/hook_loader/plugin_hook_loader.rb +3 -3
  76. data/lib/overcommit/hook_runner.rb +8 -7
  77. data/lib/overcommit/hook_signer.rb +1 -0
  78. data/lib/overcommit/installer.rb +2 -1
  79. data/lib/overcommit/logger.rb +5 -0
  80. data/lib/overcommit/printer.rb +3 -4
  81. data/lib/overcommit/subprocess.rb +24 -2
  82. data/lib/overcommit/utils/messages_utils.rb +1 -0
  83. data/lib/overcommit/version.rb +1 -1
  84. data/template-dir/hooks/commit-msg +27 -20
  85. data/template-dir/hooks/overcommit-hook +27 -20
  86. data/template-dir/hooks/post-checkout +27 -20
  87. data/template-dir/hooks/post-commit +27 -20
  88. data/template-dir/hooks/post-merge +27 -20
  89. data/template-dir/hooks/post-rewrite +27 -20
  90. data/template-dir/hooks/pre-commit +27 -20
  91. data/template-dir/hooks/pre-push +27 -20
  92. data/template-dir/hooks/pre-rebase +27 -20
  93. data/template-dir/hooks/prepare-commit-msg +27 -20
  94. metadata +5 -5
@@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit
5
5
  #
6
6
  # @see https://github.com/purcell/sqlint
7
7
  class Sqlint < Base
8
- MESSAGE_REGEX = /(?<file>(?:\w:)?.+):(?<line>\d+):\d+:(?<type>\w+)/
8
+ MESSAGE_REGEX = /(?<file>(?:\w:)?.+):(?<line>\d+):\d+:(?<type>\w+)/.freeze
9
9
 
10
10
  MESSAGE_TYPE_CATEGORIZER = lambda do |type|
11
11
  type == 'ERROR' ? :error : :warning
@@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit
5
5
  #
6
6
  # @see https://github.com/feross/standard
7
7
  class Standard < Base
8
- MESSAGE_REGEX = /^\s*(?<file>(?:\w:)?[^:]+):(?<line>\d+)/
8
+ MESSAGE_REGEX = /^\s*(?<file>(?:\w:)?[^:]+):(?<line>\d+)/.freeze
9
9
 
10
10
  def run
11
11
  result = execute(command, args: applicable_files)
@@ -8,12 +8,13 @@ module Overcommit::Hook::PreCommit
8
8
  # example of output:
9
9
  # index.css: line 4, col 4, error - Expected indentation of 2 spaces (indentation)
10
10
 
11
- MESSAGE_REGEX = /^(?<file>.+):\D*(?<line>\d+).*$/
11
+ MESSAGE_REGEX = /^(?<file>[^:]+):\D*(?<line>\d+).*$/.freeze
12
12
 
13
13
  def run
14
14
  result = execute(command, args: applicable_files)
15
15
  output = result.stdout.chomp
16
16
  return :pass if result.success? && output.empty?
17
+
17
18
  extract_messages(
18
19
  output.split("\n"),
19
20
  MESSAGE_REGEX
@@ -4,7 +4,7 @@ module Overcommit::Hook::PreCommit
4
4
  # Runs `swiftlint lint` against modified Swift files.
5
5
  # @see https://github.com/realm/SwiftLint
6
6
  class SwiftLint < Base
7
- MESSAGE_REGEX = /^(?<file>(?:\w:)?[^:]+):(?<line>\d+)[^ ]* (?<type>[^ ]+):(?<message>.*)/
7
+ MESSAGE_REGEX = /^(?<file>(?:\w:)?[^:]+):(?<line>\d+)[^ ]* (?<type>[^ ]+):(?<message>.*)/.freeze
8
8
 
9
9
  def run
10
10
  result = execute(command, args: applicable_files)
@@ -8,7 +8,7 @@ module Overcommit::Hook::PreCommit
8
8
  # "src/file/anotherfile.ts[298, 1]: exceeds maximum line length of 140"
9
9
  # or
10
10
  # "ERROR: src/AccountController.ts[4, 28]: expected call-signature to have a typedef"
11
- MESSAGE_REGEX = /^(?<type>.+: )?(?<file>.+?(?=\[))[^\d]+(?<line>\d+).*?/
11
+ MESSAGE_REGEX = /^(?<type>.+: )?(?<file>.+?(?=\[))[^\d]+(?<line>\d+).*?/.freeze
12
12
 
13
13
  def run
14
14
  result = execute(command, args: applicable_files)
@@ -19,9 +19,9 @@ module Overcommit::Hook::PreCommit
19
19
  type_categorizer = ->(type) { type.nil? || type.include?('ERROR') ? :error : :warning }
20
20
 
21
21
  extract_messages(
22
- output_lines,
23
- MESSAGE_REGEX,
24
- type_categorizer
22
+ output_lines,
23
+ MESSAGE_REGEX,
24
+ type_categorizer
25
25
  )
26
26
  end
27
27
  end
@@ -42,10 +42,10 @@ module Overcommit::Hook::PreCommit
42
42
  def opts
43
43
  @opts ||= {
44
44
  validator_uri: config['validator_uri'],
45
- proxy_server: config['proxy_server'],
46
- proxy_port: config['proxy_port'],
47
- proxy_user: config['proxy_user'],
48
- proxy_pass: config['proxy_pass']
45
+ proxy_server: config['proxy_server'],
46
+ proxy_port: config['proxy_port'],
47
+ proxy_user: config['proxy_user'],
48
+ proxy_pass: config['proxy_pass']
49
49
  }
50
50
  end
51
51
 
@@ -42,10 +42,10 @@ module Overcommit::Hook::PreCommit
42
42
  def opts
43
43
  @opts ||= {
44
44
  validator_uri: config['validator_uri'],
45
- proxy_server: config['proxy_server'],
46
- proxy_port: config['proxy_port'],
47
- proxy_user: config['proxy_user'],
48
- proxy_pass: config['proxy_pass']
45
+ proxy_server: config['proxy_server'],
46
+ proxy_port: config['proxy_port'],
47
+ proxy_user: config['proxy_user'],
48
+ proxy_pass: config['proxy_pass']
49
49
  }
50
50
  end
51
51
 
@@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit
5
5
  #
6
6
  # @see http://xmlsoft.org/xmllint.html
7
7
  class XmlLint < Base
8
- MESSAGE_REGEX = /^(?<file>(?:\w:)?[^:]+):(?<line>\d+):/
8
+ MESSAGE_REGEX = /^(?<file>(?:\w:)?[^:]+):(?<line>\d+):/.freeze
9
9
 
10
10
  def run
11
11
  result = execute(command, args: applicable_files)
@@ -11,7 +11,7 @@ module Overcommit::Hook::PreCommit
11
11
  :(?<col>\d+)
12
12
  :\s\[(?<type>\w+)\]
13
13
  \s(?<msg>.+)$
14
- /x
14
+ /x.freeze
15
15
 
16
16
  def run
17
17
  result = execute(command, args: applicable_files)
@@ -8,9 +8,13 @@ module Overcommit::Hook::PreCommit
8
8
 
9
9
  applicable_files.each do |file|
10
10
  begin
11
- YAML.load_file(file)
12
- rescue ArgumentError, Psych::SyntaxError => e
13
- messages << Overcommit::Hook::Message.new(:error, file, nil, e.message)
11
+ YAML.load_file(file, aliases: true)
12
+ rescue ArgumentError
13
+ begin
14
+ YAML.load_file(file)
15
+ rescue ArgumentError, Psych::SyntaxError => e
16
+ messages << Overcommit::Hook::Message.new(:error, file, nil, e.message)
17
+ end
14
18
  end
15
19
  end
16
20
 
@@ -1,4 +1,3 @@
1
-
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module Overcommit::Hook::PreCommit
@@ -6,6 +6,7 @@ module Overcommit::Hook::PrePush
6
6
  def run
7
7
  result = execute(command)
8
8
  return :pass if result.success?
9
+
9
10
  [:fail, result.stdout]
10
11
  end
11
12
  end
@@ -12,6 +12,7 @@ module Overcommit::Hook::PrepareCommitMsg
12
12
 
13
13
  def modify_commit_message
14
14
  raise 'This expects a block!' unless block_given?
15
+
15
16
  # NOTE: this assumes all the hooks of the same type share the context's
16
17
  # memory. If that's not the case, this won't work.
17
18
  lock.synchronize do
@@ -29,7 +29,7 @@ module Overcommit::Hook::PrepareCommitMsg
29
29
  # - 'squash' - if squashing
30
30
  #
31
31
  class ReplaceBranch < Base
32
- DEFAULT_BRANCH_PATTERN = /\A(\d+)-(\w+).*\z/
32
+ DEFAULT_BRANCH_PATTERN = /\A(\d+)-(\w+).*\z/.freeze
33
33
 
34
34
  def run
35
35
  return :pass if skip?
@@ -9,6 +9,7 @@ module Overcommit::Hook::Shared
9
9
  def run
10
10
  result = execute(command)
11
11
  return :fail, result.stderr unless result.success?
12
+
12
13
  :pass
13
14
  end
14
15
  end
@@ -9,6 +9,7 @@ module Overcommit::Hook::Shared
9
9
  def run
10
10
  result = execute(command)
11
11
  return :fail, result.stdout unless result.success?
12
+
12
13
  :pass
13
14
  end
14
15
  end
@@ -9,6 +9,7 @@ module Overcommit::Hook::Shared
9
9
  def run
10
10
  result = execute(command)
11
11
  return :fail, result.stdout unless result.success?
12
+
12
13
  :pass
13
14
  end
14
15
  end
@@ -9,6 +9,7 @@ module Overcommit::Hook::Shared
9
9
  def run
10
10
  result = execute(command)
11
11
  return :fail, result.stderr unless result.success?
12
+
12
13
  :pass
13
14
  end
14
15
  end
@@ -1,21 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Overcommit::Hook::Shared
4
- # Shared code used by all Pronto hooks. Runs pronto linter.
4
+ # Shared code used by all Pronto hooks. Runs pronto linters.
5
+
6
+ # @see https://github.com/prontolabs/pronto
5
7
  module Pronto
6
8
  MESSAGE_TYPE_CATEGORIZER = lambda do |type|
7
9
  type.include?('E') ? :error : :warning
8
10
  end
9
11
 
12
+ MESSAGE_REGEX = /^(?<file>(?:\w:)?[^:]+):(?<line>\d+) (?<type>[^ ]+)/.freeze
13
+
10
14
  def run
11
15
  result = execute(command)
12
16
  return :pass if result.success?
13
17
 
14
- extract_messages(
15
- result.stdout.split("\n"),
16
- /^(?<file>(?:\w:)?[^:]+):(?<line>\d+) (?<type>[^ ]+)/,
18
+ # e.g. runtime errors
19
+ generic_errors = extract_messages(
20
+ result.stderr.split("\n"),
21
+ /^(?<type>[a-z]+)/i
22
+ )
23
+
24
+ pronto_infractions = extract_messages(
25
+ result.stdout.split("\n").select { |line| line.match?(MESSAGE_REGEX) },
26
+ MESSAGE_REGEX,
17
27
  MESSAGE_TYPE_CATEGORIZER,
18
28
  )
29
+
30
+ generic_errors + pronto_infractions
19
31
  end
20
32
  end
21
33
  end
@@ -9,6 +9,7 @@ module Overcommit::Hook::Shared
9
9
  def run
10
10
  result = execute(command)
11
11
  return :fail, result.stderr unless result.success?
12
+
12
13
  :pass
13
14
  end
14
15
  end
@@ -11,6 +11,7 @@ module Overcommit::HookContext
11
11
 
12
12
  cmd = Overcommit::Utils.parent_command
13
13
  return unless cmd
14
+
14
15
  amend_pattern = 'commit(\s.*)?\s--amend(\s|$)'
15
16
 
16
17
  # Since the ps command can return invalid byte sequences for commands
@@ -26,6 +26,7 @@ module Overcommit::HookContext
26
26
  # Returns whether the current git branch is empty (has no commits).
27
27
  def initial_commit?
28
28
  return @initial_commit unless @initial_commit.nil?
29
+
29
30
  @initial_commit = Overcommit::GitRepo.initial_commit?
30
31
  end
31
32
 
@@ -63,6 +64,7 @@ module Overcommit::HookContext
63
64
  (staged_files + unstaged_files).each do |file|
64
65
  next if Overcommit::Utils.broken_symlink?(file)
65
66
  next unless File.exist?(file) # Ignore renamed files (old file no longer exists)
67
+
66
68
  @modified_times[file] = File.mtime(file)
67
69
  end
68
70
  end
@@ -101,6 +103,7 @@ module Overcommit::HookContext
101
103
  @modified_times.each do |file, time|
102
104
  next if Overcommit::Utils.broken_symlink?(file)
103
105
  next unless File.exist?(file)
106
+
104
107
  File.utime(time, time, file)
105
108
  end
106
109
  end
@@ -27,6 +27,7 @@ module Overcommit::HookContext
27
27
  # @return [true,false]
28
28
  def initial_commit?
29
29
  return @initial_commit unless @initial_commit.nil?
30
+
30
31
  @initial_commit = !Overcommit::Utils.execute(%w[git rev-parse HEAD~]).success?
31
32
  end
32
33
  end
@@ -76,6 +76,7 @@ module Overcommit::HookContext
76
76
 
77
77
  def overwritten_commits
78
78
  return @overwritten_commits if defined? @overwritten_commits
79
+
79
80
  result = Overcommit::Subprocess.spawn(%W[git rev-list #{remote_sha1} ^#{local_sha1}])
80
81
  if result.success?
81
82
  result.stdout.split("\n")
@@ -36,6 +36,7 @@ module Overcommit::HookContext
36
36
 
37
37
  def initial_commit?
38
38
  return @initial_commit unless @initial_commit.nil?
39
+
39
40
  @initial_commit = Overcommit::GitRepo.initial_commit?
40
41
  end
41
42
 
@@ -9,11 +9,11 @@ module Overcommit::HookContext
9
9
  require "overcommit/hook_context/#{underscored_hook_type}"
10
10
 
11
11
  Overcommit::HookContext.const_get(hook_type_class).new(config, args, input)
12
- rescue LoadError, NameError => error
12
+ rescue LoadError, NameError => e
13
13
  # Could happen when a symlink was created for a hook type Overcommit does
14
14
  # not yet support.
15
15
  raise Overcommit::Exceptions::HookContextLoadError,
16
- "Unable to load '#{hook_type}' hook context: '#{error}'",
17
- error.backtrace
16
+ "Unable to load '#{hook_type}' hook context: '#{e}'",
17
+ e.backtrace
18
18
  end
19
19
  end
@@ -38,10 +38,10 @@ module Overcommit::HookLoader
38
38
  Overcommit::Hook.const_get(@context.hook_class_name).
39
39
  const_get(hook_name).
40
40
  new(@config, @context)
41
- rescue LoadError, NameError => error
41
+ rescue LoadError, NameError => e
42
42
  raise Overcommit::Exceptions::HookLoadError,
43
- "Unable to load hook '#{hook_name}': #{error}",
44
- error.backtrace
43
+ "Unable to load hook '#{hook_name}': #{e}",
44
+ e.backtrace
45
45
  end
46
46
  end
47
47
  end
@@ -93,10 +93,10 @@ module Overcommit::HookLoader
93
93
  end
94
94
 
95
95
  hook_module.const_set(hook_name, hook_class).new(@config, @context)
96
- rescue LoadError, NameError => error
96
+ rescue LoadError, NameError => e
97
97
  raise Overcommit::Exceptions::HookLoadError,
98
- "Unable to load hook '#{hook_name}': #{error}",
99
- error.backtrace
98
+ "Unable to load hook '#{hook_name}': #{e}",
99
+ e.backtrace
100
100
  end
101
101
  end
102
102
  end
@@ -94,6 +94,7 @@ module Overcommit
94
94
  loop do
95
95
  hook = @lock.synchronize { @hooks_left.pop }
96
96
  break unless hook
97
+
97
98
  run_hook(hook)
98
99
  end
99
100
  end
@@ -159,12 +160,12 @@ module Overcommit
159
160
  return if should_skip?(hook)
160
161
 
161
162
  status, output = hook.run_and_transform
162
- rescue Overcommit::Exceptions::MessageProcessingError => ex
163
+ rescue Overcommit::Exceptions::MessageProcessingError => e
163
164
  status = :fail
164
- output = ex.message
165
- rescue StandardError => ex
165
+ output = e.message
166
+ rescue StandardError => e
166
167
  status = :fail
167
- output = "Hook raised unexpected error\n#{ex.message}\n#{ex.backtrace.join("\n")}"
168
+ output = "Hook raised unexpected error\n#{e.message}\n#{e.backtrace.join("\n")}"
168
169
  end
169
170
 
170
171
  @failed = true if status == :fail
@@ -202,7 +203,7 @@ module Overcommit
202
203
 
203
204
  # Load plugin hooks after so they can subclass existing hooks
204
205
  @hooks += HookLoader::PluginHookLoader.new(@config, @context, @log).load_hooks
205
- rescue LoadError => ex
206
+ rescue LoadError => e
206
207
  # Include a more helpful message that will probably save some confusion
207
208
  message = 'A load error occurred. ' +
208
209
  if @config['gemfile']
@@ -212,8 +213,8 @@ module Overcommit
212
213
  end
213
214
 
214
215
  raise Overcommit::Exceptions::HookLoadError,
215
- "#{message}\n#{ex.message}",
216
- ex.backtrace
216
+ "#{message}\n#{e.message}",
217
+ e.backtrace
217
218
  end
218
219
  end
219
220
  end
@@ -52,6 +52,7 @@ module Overcommit
52
52
 
53
53
  def signable_file?(file)
54
54
  return unless file
55
+
55
56
  sep = Overcommit::OS.windows? ? '\\' : File::SEPARATOR
56
57
  file.start_with?(".#{sep}") ||
57
58
  file.start_with?(Overcommit::Utils.repo_root)
@@ -4,7 +4,7 @@ require 'fileutils'
4
4
 
5
5
  module Overcommit
6
6
  # Manages the installation of Overcommit hooks in a git repository.
7
- class Installer # rubocop:disable ClassLength
7
+ class Installer # rubocop:disable Metrics/ClassLength
8
8
  TEMPLATE_DIRECTORY = File.join(Overcommit::HOME, 'template-dir')
9
9
  MASTER_HOOK = File.join(TEMPLATE_DIRECTORY, 'hooks', 'overcommit-hook')
10
10
 
@@ -174,6 +174,7 @@ module Overcommit
174
174
  repo_config_file = File.join(@target, Overcommit::CONFIG_FILE_NAME)
175
175
 
176
176
  return if File.exist?(repo_config_file)
177
+
177
178
  FileUtils.cp(File.join(Overcommit::HOME, 'config', 'starter.yml'), repo_config_file)
178
179
  end
179
180
 
@@ -31,6 +31,11 @@ module Overcommit
31
31
  log
32
32
  end
33
33
 
34
+ # Flushes the [IO] object for partial lines
35
+ def flush
36
+ @out.flush if @out.respond_to? :flush
37
+ end
38
+
34
39
  # Write a line of output.
35
40
  #
36
41
  # A newline character will always be appended.
@@ -43,16 +43,14 @@ module Overcommit
43
43
  end
44
44
 
45
45
  def interrupt_triggered
46
- log.newline
47
- log.error 'Interrupt signal received. Stopping hooks...'
46
+ log.error "\nInterrupt signal received. Stopping hooks..."
48
47
  end
49
48
 
50
49
  # Executed when a hook run was interrupted/cancelled by user.
51
50
  def run_interrupted
52
51
  log.newline
53
52
  log.warning '⚠ Hook run interrupted by user'
54
- log.warning '⚠ If files appear modified/missing, check your stash to recover them'
55
- log.newline
53
+ log.warning "⚠ If files appear modified/missing, check your stash to recover them\n"
56
54
  end
57
55
 
58
56
  # Executed when one or more hooks by the end of the run.
@@ -91,6 +89,7 @@ module Overcommit
91
89
  log.partial hook.description
92
90
  log.partial '.' * [70 - hook.description.length - hook_name.length, 0].max
93
91
  log.partial hook_name
92
+ log.flush
94
93
  end
95
94
 
96
95
  def print_result(hook, status, output) # rubocop:disable Metrics/CyclomaticComplexity
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'childprocess'
4
4
  require 'tempfile'
5
+ require 'overcommit/os'
5
6
 
6
7
  module Overcommit
7
8
  # Manages execution of a child process, collecting the exit status and
@@ -38,7 +39,7 @@ module Overcommit
38
39
  if options[:input]
39
40
  begin
40
41
  process.io.stdin.puts(options[:input])
41
- rescue StandardError # rubocop:disable Lint/HandleExceptions
42
+ rescue StandardError
42
43
  # Silently ignore if the standard input stream of the spawned
43
44
  # process is closed before we get a chance to write to it. This
44
45
  # happens on JRuby a lot.
@@ -51,7 +52,7 @@ module Overcommit
51
52
  err.rewind
52
53
  out.rewind
53
54
 
54
- Result.new(process.exit_code, out.read, err.read)
55
+ Result.new(process.exit_code, to_utf8(out.read), to_utf8(err.read))
55
56
  end
56
57
 
57
58
  # Spawns a new process in the background using the given array of
@@ -83,6 +84,27 @@ module Overcommit
83
84
  %w[cmd.exe /c] + [args.join(' ')]
84
85
  end
85
86
 
87
+ # Convert string from current locale to utf-8
88
+ #
89
+ # When running commands under windows the command output is using
90
+ # current system locale (depends on system lanuage) not UTF-8
91
+ #
92
+ # @param process [String]
93
+ # @return [String]
94
+ def to_utf8(string)
95
+ # Our encoding code doesn't work on the GitHub Actions Windows
96
+ # environment for unknown reasons, so just skip it in CI.
97
+ return string if OS.windows? && ENV['GITHUB_ACTIONS']
98
+
99
+ if Encoding.locale_charmap == 'UTF-8'
100
+ return string
101
+ end
102
+
103
+ ec = Encoding::Converter.new(Encoding.locale_charmap, 'UTF-8')
104
+ # Convert encoding, alternatively simple: string.scrub will suffice
105
+ ec.convert(string)
106
+ end
107
+
86
108
  # @param process [ChildProcess]
87
109
  # @return [Array<IO>]
88
110
  def assign_output_streams(process)
@@ -52,6 +52,7 @@ module Overcommit::Utils
52
52
 
53
53
  def extract_line(match, message)
54
54
  return unless match.names.include?('line')
55
+
55
56
  Integer(match[:line])
56
57
  rescue ArgumentError, TypeError
57
58
  raise Overcommit::Exceptions::MessageProcessingError,
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  module Overcommit
5
- VERSION = '0.58.0'
5
+ VERSION = '0.59.0'
6
6
  end
@@ -29,15 +29,22 @@ end
29
29
  # Check if Overcommit should invoke a Bundler context for loading gems
30
30
  require 'yaml'
31
31
  # rubocop:disable Style/RescueModifier
32
- if gemfile = YAML.load_file('.overcommit.yml')['gemfile'] rescue nil
32
+ gemfile =
33
+ begin
34
+ YAML.load_file('.overcommit.yml', aliases: true)['gemfile']
35
+ rescue ArgumentError
36
+ YAML.load_file('.overcommit.yml')['gemfile']
37
+ end rescue nil
38
+
39
+ if gemfile
33
40
  ENV['BUNDLE_GEMFILE'] = gemfile
34
41
  require 'bundler'
35
42
 
36
43
  begin
37
44
  Bundler.setup
38
- rescue Bundler::BundlerError => ex
39
- puts "Problem loading '#{gemfile}': #{ex.message}"
40
- puts "Try running:\nbundle install --gemfile=#{gemfile}" if ex.is_a?(Bundler::GemNotFound)
45
+ rescue Bundler::BundlerError => e
46
+ puts "Problem loading '#{gemfile}': #{e.message}"
47
+ puts "Try running:\nbundle install --gemfile=#{gemfile}" if e.is_a?(Bundler::GemNotFound)
41
48
  exit 78 # EX_CONFIG
42
49
  end
43
50
  end
@@ -80,37 +87,37 @@ begin
80
87
  status = runner.run
81
88
 
82
89
  exit(status ? 0 : 65) # 65 = EX_DATAERR
83
- rescue Overcommit::Exceptions::ConfigurationError => error
84
- puts error
90
+ rescue Overcommit::Exceptions::ConfigurationError => e
91
+ puts e
85
92
  exit 78 # EX_CONFIG
86
- rescue Overcommit::Exceptions::HookContextLoadError => error
87
- puts error
93
+ rescue Overcommit::Exceptions::HookContextLoadError => e
94
+ puts e
88
95
  puts 'Are you running an old version of Overcommit?'
89
96
  exit 69 # EX_UNAVAILABLE
90
97
  rescue Overcommit::Exceptions::HookLoadError,
91
- Overcommit::Exceptions::InvalidHookDefinition => error
92
- puts error.message
93
- puts error.backtrace
98
+ Overcommit::Exceptions::InvalidHookDefinition => e
99
+ puts e.message
100
+ puts e.backtrace
94
101
  exit 78 # EX_CONFIG
95
102
  rescue Overcommit::Exceptions::HookSetupFailed,
96
- Overcommit::Exceptions::HookCleanupFailed => error
97
- puts error.message
103
+ Overcommit::Exceptions::HookCleanupFailed => e
104
+ puts e.message
98
105
  exit 74 # EX_IOERR
99
106
  rescue Overcommit::Exceptions::HookCancelled
100
107
  puts 'You cancelled the hook run'
101
108
  exit 130 # Ctrl-C cancel
102
- rescue Overcommit::Exceptions::InvalidGitRepo => error
103
- puts error
109
+ rescue Overcommit::Exceptions::InvalidGitRepo => e
110
+ puts e
104
111
  exit 64 # EX_USAGE
105
- rescue Overcommit::Exceptions::ConfigurationSignatureChanged => error
106
- puts error
112
+ rescue Overcommit::Exceptions::ConfigurationSignatureChanged => e
113
+ puts e
107
114
  puts "For more information, see #{Overcommit::REPO_URL}#security"
108
115
  exit 1
109
116
  rescue Overcommit::Exceptions::InvalidHookSignature
110
117
  exit 1
111
- rescue StandardError => error
112
- puts error.message
113
- puts error.backtrace
118
+ rescue StandardError => e
119
+ puts e.message
120
+ puts e.backtrace
114
121
  puts "Report this bug at #{Overcommit::BUG_REPORT_URL}"
115
122
  exit 70 # EX_SOFTWARE
116
123
  end