overcommit 0.58.0 → 0.59.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/overcommit +6 -5
- data/config/default.yml +1 -1
- data/lib/overcommit/cli.rb +14 -13
- data/lib/overcommit/command_splitter.rb +2 -0
- data/lib/overcommit/configuration.rb +1 -1
- data/lib/overcommit/configuration_loader.rb +3 -3
- data/lib/overcommit/git_config.rb +1 -0
- data/lib/overcommit/git_repo.rb +4 -4
- data/lib/overcommit/hook/commit_msg/spell_check.rb +1 -1
- data/lib/overcommit/hook/commit_msg/text_width.rb +1 -1
- data/lib/overcommit/hook/post_checkout/base.rb +1 -0
- data/lib/overcommit/hook/post_commit/git_guilt.rb +2 -1
- data/lib/overcommit/hook/pre_commit/bundle_audit.rb +1 -1
- data/lib/overcommit/hook/pre_commit/chamber_compare.rb +5 -5
- data/lib/overcommit/hook/pre_commit/chamber_security.rb +1 -0
- data/lib/overcommit/hook/pre_commit/coffee_lint.rb +1 -1
- data/lib/overcommit/hook/pre_commit/css_lint.rb +1 -1
- data/lib/overcommit/hook/pre_commit/dart_analyzer.rb +1 -1
- data/lib/overcommit/hook/pre_commit/erb_lint.rb +1 -1
- data/lib/overcommit/hook/pre_commit/fasterer.rb +1 -1
- data/lib/overcommit/hook/pre_commit/foodcritic.rb +3 -1
- data/lib/overcommit/hook/pre_commit/hlint.rb +1 -1
- data/lib/overcommit/hook/pre_commit/html_tidy.rb +1 -1
- data/lib/overcommit/hook/pre_commit/java_checkstyle.rb +1 -1
- data/lib/overcommit/hook/pre_commit/js_lint.rb +1 -1
- data/lib/overcommit/hook/pre_commit/jsl.rb +1 -1
- data/lib/overcommit/hook/pre_commit/kt_lint.rb +1 -1
- data/lib/overcommit/hook/pre_commit/license_finder.rb +1 -0
- data/lib/overcommit/hook/pre_commit/line_endings.rb +3 -2
- data/lib/overcommit/hook/pre_commit/nginx_test.rb +1 -1
- data/lib/overcommit/hook/pre_commit/php_cs.rb +1 -1
- data/lib/overcommit/hook/pre_commit/php_cs_fixer.rb +1 -1
- data/lib/overcommit/hook/pre_commit/php_lint.rb +3 -3
- data/lib/overcommit/hook/pre_commit/php_stan.rb +1 -1
- data/lib/overcommit/hook/pre_commit/puppet_lint.rb +1 -1
- data/lib/overcommit/hook/pre_commit/puppet_metadata_json_lint.rb +1 -1
- data/lib/overcommit/hook/pre_commit/pyflakes.rb +1 -1
- data/lib/overcommit/hook/pre_commit/pylint.rb +1 -1
- data/lib/overcommit/hook/pre_commit/python_flake8.rb +1 -1
- data/lib/overcommit/hook/pre_commit/rails_best_practices.rb +1 -1
- data/lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb +2 -2
- data/lib/overcommit/hook/pre_commit/rst_lint.rb +1 -1
- data/lib/overcommit/hook/pre_commit/scalariform.rb +1 -1
- data/lib/overcommit/hook/pre_commit/scalastyle.rb +1 -1
- data/lib/overcommit/hook/pre_commit/scss_lint.rb +3 -3
- data/lib/overcommit/hook/pre_commit/semi_standard.rb +1 -1
- data/lib/overcommit/hook/pre_commit/sqlint.rb +1 -1
- data/lib/overcommit/hook/pre_commit/standard.rb +1 -1
- data/lib/overcommit/hook/pre_commit/stylelint.rb +2 -1
- data/lib/overcommit/hook/pre_commit/swift_lint.rb +1 -1
- data/lib/overcommit/hook/pre_commit/ts_lint.rb +4 -4
- data/lib/overcommit/hook/pre_commit/w3c_css.rb +4 -4
- data/lib/overcommit/hook/pre_commit/w3c_html.rb +4 -4
- data/lib/overcommit/hook/pre_commit/xml_lint.rb +1 -1
- data/lib/overcommit/hook/pre_commit/yaml_lint.rb +1 -1
- data/lib/overcommit/hook/pre_commit/yaml_syntax.rb +7 -3
- data/lib/overcommit/hook/pre_commit/yard_coverage.rb +0 -1
- data/lib/overcommit/hook/pre_push/cargo_test.rb +1 -0
- data/lib/overcommit/hook/prepare_commit_msg/base.rb +1 -0
- data/lib/overcommit/hook/prepare_commit_msg/replace_branch.rb +1 -1
- data/lib/overcommit/hook/shared/bower_install.rb +1 -0
- data/lib/overcommit/hook/shared/bundle_install.rb +1 -0
- data/lib/overcommit/hook/shared/composer_install.rb +1 -0
- data/lib/overcommit/hook/shared/npm_install.rb +1 -0
- data/lib/overcommit/hook/shared/pronto.rb +16 -4
- data/lib/overcommit/hook/shared/yarn_install.rb +1 -0
- data/lib/overcommit/hook_context/helpers/file_modifications.rb +1 -0
- data/lib/overcommit/hook_context/helpers/stash_unstaged_changes.rb +3 -0
- data/lib/overcommit/hook_context/post_commit.rb +1 -0
- data/lib/overcommit/hook_context/pre_push.rb +1 -0
- data/lib/overcommit/hook_context/run_all.rb +1 -0
- data/lib/overcommit/hook_context.rb +3 -3
- data/lib/overcommit/hook_loader/base.rb +3 -3
- data/lib/overcommit/hook_loader/plugin_hook_loader.rb +3 -3
- data/lib/overcommit/hook_runner.rb +8 -7
- data/lib/overcommit/hook_signer.rb +1 -0
- data/lib/overcommit/installer.rb +2 -1
- data/lib/overcommit/logger.rb +5 -0
- data/lib/overcommit/printer.rb +3 -4
- data/lib/overcommit/subprocess.rb +24 -2
- data/lib/overcommit/utils/messages_utils.rb +1 -0
- data/lib/overcommit/version.rb +1 -1
- data/template-dir/hooks/commit-msg +27 -20
- data/template-dir/hooks/overcommit-hook +27 -20
- data/template-dir/hooks/post-checkout +27 -20
- data/template-dir/hooks/post-commit +27 -20
- data/template-dir/hooks/post-merge +27 -20
- data/template-dir/hooks/post-rewrite +27 -20
- data/template-dir/hooks/pre-commit +27 -20
- data/template-dir/hooks/pre-push +27 -20
- data/template-dir/hooks/pre-rebase +27 -20
- data/template-dir/hooks/prepare-commit-msg +27 -20
- 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
|
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
|
-
|
23
|
-
|
24
|
-
|
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:
|
46
|
-
proxy_port:
|
47
|
-
proxy_user:
|
48
|
-
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:
|
46
|
-
proxy_port:
|
47
|
-
proxy_user:
|
48
|
-
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)
|
@@ -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
|
13
|
-
|
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
|
|
@@ -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
|
@@ -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
|
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
|
-
|
15
|
-
|
16
|
-
|
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
|
@@ -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
|
@@ -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")
|
@@ -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 =>
|
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: '#{
|
17
|
-
|
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 =>
|
41
|
+
rescue LoadError, NameError => e
|
42
42
|
raise Overcommit::Exceptions::HookLoadError,
|
43
|
-
"Unable to load hook '#{hook_name}': #{
|
44
|
-
|
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 =>
|
96
|
+
rescue LoadError, NameError => e
|
97
97
|
raise Overcommit::Exceptions::HookLoadError,
|
98
|
-
"Unable to load hook '#{hook_name}': #{
|
99
|
-
|
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 =>
|
163
|
+
rescue Overcommit::Exceptions::MessageProcessingError => e
|
163
164
|
status = :fail
|
164
|
-
output =
|
165
|
-
rescue StandardError =>
|
165
|
+
output = e.message
|
166
|
+
rescue StandardError => e
|
166
167
|
status = :fail
|
167
|
-
output = "Hook raised unexpected error\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 =>
|
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#{
|
216
|
-
|
216
|
+
"#{message}\n#{e.message}",
|
217
|
+
e.backtrace
|
217
218
|
end
|
218
219
|
end
|
219
220
|
end
|
data/lib/overcommit/installer.rb
CHANGED
@@ -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
|
|
data/lib/overcommit/logger.rb
CHANGED
data/lib/overcommit/printer.rb
CHANGED
@@ -43,16 +43,14 @@ module Overcommit
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def interrupt_triggered
|
46
|
-
log.
|
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
|
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
|
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)
|
data/lib/overcommit/version.rb
CHANGED
@@ -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
|
-
|
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 =>
|
39
|
-
puts "Problem loading '#{gemfile}': #{
|
40
|
-
puts "Try running:\nbundle install --gemfile=#{gemfile}" if
|
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 =>
|
84
|
-
puts
|
90
|
+
rescue Overcommit::Exceptions::ConfigurationError => e
|
91
|
+
puts e
|
85
92
|
exit 78 # EX_CONFIG
|
86
|
-
rescue Overcommit::Exceptions::HookContextLoadError =>
|
87
|
-
puts
|
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 =>
|
92
|
-
puts
|
93
|
-
puts
|
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 =>
|
97
|
-
puts
|
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 =>
|
103
|
-
puts
|
109
|
+
rescue Overcommit::Exceptions::InvalidGitRepo => e
|
110
|
+
puts e
|
104
111
|
exit 64 # EX_USAGE
|
105
|
-
rescue Overcommit::Exceptions::ConfigurationSignatureChanged =>
|
106
|
-
puts
|
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 =>
|
112
|
-
puts
|
113
|
-
puts
|
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
|