overcommit 0.56.0 → 0.59.0
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.
- checksums.yaml +4 -4
- data/bin/overcommit +6 -5
- data/config/default.yml +28 -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 +11 -8
- data/lib/overcommit/git_config.rb +1 -0
- data/lib/overcommit/git_repo.rb +4 -4
- data/lib/overcommit/hook/commit_msg/base.rb +1 -1
- 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 +22 -0
- data/lib/overcommit/hook/pre_commit/erb_lint.rb +20 -0
- data/lib/overcommit/hook/pre_commit/es_lint.rb +3 -6
- 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 +25 -4
- 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/pre_push/flutter_test.rb +16 -0
- data/lib/overcommit/hook/pre_push/pub_test.rb +16 -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 +4 -1
- 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/libexec/index-tags +6 -4
- 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 +21 -3
@@ -8,7 +8,7 @@ module Overcommit::Hook::PreCommit
|
|
8
8
|
# @see https://voxpupuli.org/blog/2014/11/06/linting-metadata-json/
|
9
9
|
#
|
10
10
|
class PuppetMetadataJsonLint < Base
|
11
|
-
MESSAGE_REGEX = /\((?<type>.*)\)
|
11
|
+
MESSAGE_REGEX = /\((?<type>.*)\).*/.freeze
|
12
12
|
|
13
13
|
MESSAGE_TYPE_CATEGORIZER = lambda do |type|
|
14
14
|
type == 'WARN' ? :warning : :error
|
@@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit
|
|
5
5
|
#
|
6
6
|
# @see https://pypi.python.org/pypi/pyflakes
|
7
7
|
class Pyflakes < 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)
|
@@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit
|
|
5
5
|
#
|
6
6
|
# @see http://www.pylint.org/
|
7
7
|
class Pylint < Base
|
8
|
-
MESSAGE_REGEX = /^(?<file>(?:\w:)?.+):(?<line>\d+):(?<type>[CEFRW])
|
8
|
+
MESSAGE_REGEX = /^(?<file>(?:\w:)?.+):(?<line>\d+):(?<type>[CEFRW])/.freeze
|
9
9
|
|
10
10
|
# Classify 'E' and 'F' message codes as errors,
|
11
11
|
# everything else as warnings.
|
@@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit
|
|
5
5
|
#
|
6
6
|
# @see https://pypi.python.org/pypi/flake8
|
7
7
|
class PythonFlake8 < Base
|
8
|
-
MESSAGE_REGEX = /^(?<file>(?:\w:)?.+):(?<line>\d+):\d+:\s(?<type>\w\d+)
|
8
|
+
MESSAGE_REGEX = /^(?<file>(?:\w:)?.+):(?<line>\d+):\d+:\s(?<type>\w\d+)/.freeze
|
9
9
|
|
10
10
|
# Classify 'Exxx' and 'Fxxx' message codes as errors,
|
11
11
|
# everything else as warnings.
|
@@ -7,7 +7,7 @@ module Overcommit
|
|
7
7
|
#
|
8
8
|
# @see https://github.com/railsbp/rails_best_practices
|
9
9
|
class RailsBestPractices < Base
|
10
|
-
ERROR_REGEXP = /^(?<file>(?:\w:)?[^:]+):(?<line>\d+)\s-\s(?<type>.+)
|
10
|
+
ERROR_REGEXP = /^(?<file>(?:\w:)?[^:]+):(?<line>\d+)\s-\s(?<type>.+)/.freeze
|
11
11
|
|
12
12
|
def run
|
13
13
|
result = execute(command, args: applicable_files)
|
@@ -6,7 +6,7 @@ module Overcommit::Hook::PreCommit
|
|
6
6
|
# failure. The exception is if the schema is at version 0 (i.e before any
|
7
7
|
# migrations have been run). In this case it is OK if there are no migrations.
|
8
8
|
class RailsSchemaUpToDate < Base
|
9
|
-
def run # rubocop:disable CyclomaticComplexity, PerceivedComplexity
|
9
|
+
def run # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
10
10
|
if migration_files.any? && schema_files.none?
|
11
11
|
return :fail, "It looks like you're adding a migration, but did not update the schema file"
|
12
12
|
elsif migration_files.none? && schema_files.any? && non_zero_schema_version?
|
@@ -18,7 +18,7 @@ module Overcommit::Hook::PreCommit
|
|
18
18
|
# their username.
|
19
19
|
latest_version = migration_files.map do |file|
|
20
20
|
File.basename(file)[/\d+/]
|
21
|
-
end.
|
21
|
+
end.max
|
22
22
|
|
23
23
|
up_to_date = schema.include?(latest_version)
|
24
24
|
|
@@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit
|
|
5
5
|
#
|
6
6
|
# @see https://github.com/mdr/scalariform
|
7
7
|
class Scalariform < Base
|
8
|
-
MESSAGE_REGEX = /^\[(?<type>FAILED|ERROR)\]\s+(?<file>(?:\w:)?.+)
|
8
|
+
MESSAGE_REGEX = /^\[(?<type>FAILED|ERROR)\]\s+(?<file>(?:\w:)?.+)/.freeze
|
9
9
|
|
10
10
|
def run
|
11
11
|
result = execute(command, args: applicable_files)
|
@@ -18,9 +18,9 @@ module Overcommit::Hook::PreCommit
|
|
18
18
|
|
19
19
|
begin
|
20
20
|
collect_lint_messages(JSON.parse(result.stdout))
|
21
|
-
rescue JSON::ParserError =>
|
22
|
-
|
23
|
-
"STDOUT: #{result.stdout}\nSTDERR: #{result.stderr}"
|
21
|
+
rescue JSON::ParserError => e
|
22
|
+
[:fail, "Unable to parse JSON returned by SCSS-Lint: #{e.message}\n" \
|
23
|
+
"STDOUT: #{result.stdout}\nSTDERR: #{result.stderr}"]
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit
|
|
5
5
|
#
|
6
6
|
# @see https://github.com/Flet/semistandard
|
7
7
|
class SemiStandard < 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)
|
@@ -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)
|
@@ -5,13 +5,34 @@ module Overcommit::Hook::PreCommit
|
|
5
5
|
#
|
6
6
|
# @see https://github.com/adrienverge/yamllint
|
7
7
|
class YamlLint < Base
|
8
|
+
MESSAGE_REGEX = /
|
9
|
+
^(?<file>.+)
|
10
|
+
:(?<line>\d+)
|
11
|
+
:(?<col>\d+)
|
12
|
+
:\s\[(?<type>\w+)\]
|
13
|
+
\s(?<msg>.+)$
|
14
|
+
/x.freeze
|
15
|
+
|
8
16
|
def run
|
9
17
|
result = execute(command, args: applicable_files)
|
18
|
+
parse_messages(result.stdout)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def parse_messages(output)
|
24
|
+
repo_root = Overcommit::Utils.repo_root
|
25
|
+
|
26
|
+
output.scan(MESSAGE_REGEX).map do |file, line, col, type, msg|
|
27
|
+
line = line.to_i
|
28
|
+
type = type.to_sym
|
29
|
+
# Obtain the path relative to the root of the repository
|
30
|
+
# for nicer output:
|
31
|
+
relpath = file.dup
|
32
|
+
relpath.slice!("#{repo_root}/")
|
10
33
|
|
11
|
-
|
12
|
-
|
13
|
-
else
|
14
|
-
return [:warn, result.stdout]
|
34
|
+
text = "#{relpath}:#{line}:#{col}:#{type} #{msg}"
|
35
|
+
Overcommit::Hook::Message.new(type, file, line, text)
|
15
36
|
end
|
16
37
|
end
|
17
38
|
end
|
@@ -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
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Overcommit::Hook::PrePush
|
4
|
+
# Runs Flutter test suite (`flutter test`) before push
|
5
|
+
#
|
6
|
+
# @see https://api.flutter.dev/flutter/flutter_test/flutter_test-library.html
|
7
|
+
class FlutterTest < Base
|
8
|
+
def run
|
9
|
+
result = execute(command)
|
10
|
+
return :pass if result.success?
|
11
|
+
|
12
|
+
output = result.stdout + result.stderr
|
13
|
+
[:fail, output]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Overcommit::Hook::PrePush
|
4
|
+
# Runs Dart test suite (`pub run test`) before push
|
5
|
+
#
|
6
|
+
# @see https://pub.dev/packages/test#running-tests
|
7
|
+
class PubTest < Base
|
8
|
+
def run
|
9
|
+
result = execute(command)
|
10
|
+
return :pass if result.success?
|
11
|
+
|
12
|
+
output = result.stdout + result.stderr
|
13
|
+
[:fail, output]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
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
|
@@ -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
|
@@ -129,7 +132,7 @@ module Overcommit::HookContext
|
|
129
132
|
|
130
133
|
# Applies the stash to the working tree to restore the user's state.
|
131
134
|
def restore_working_tree
|
132
|
-
result = Overcommit::Utils.execute(%w[git stash pop --index
|
135
|
+
result = Overcommit::Utils.execute(%w[git stash pop --index])
|
133
136
|
unless result.success?
|
134
137
|
raise Overcommit::Exceptions::HookCleanupFailed,
|
135
138
|
"Unable to restore working tree after #{hook_script_name} hooks run:" \
|
@@ -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