overcommit-jeygeethanmedia 0.53.1 → 0.58.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 +37 -5
- 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/exceptions.rb +19 -16
- data/lib/overcommit/git_config.rb +1 -0
- data/lib/overcommit/git_repo.rb +14 -13
- 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/author_name.rb +2 -2
- 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 +38 -4
- 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 +7 -3
- data/lib/overcommit/hook/shared/yarn_install.rb +1 -0
- data/lib/overcommit/hook_context/commit_msg.rb +7 -0
- data/lib/overcommit/hook_context/helpers/file_modifications.rb +79 -0
- data/lib/overcommit/hook_context/helpers/stash_unstaged_changes.rb +144 -0
- data/lib/overcommit/hook_context/post_commit.rb +1 -0
- data/lib/overcommit/hook_context/pre_commit.rb +5 -199
- 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 +4 -4
- 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/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 +27 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: af53afa68bd06acbd1570164e817629065c5d2935f826a2ae8512709522b0fc2
|
|
4
|
+
data.tar.gz: 6123ee4c1d89fc980066584b7ab739049f7b7c54c9509d94e3af17a5c2c96977
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3e01d3e98266d437f287cc2dfae5800d0383ee2ab473bb545df48aed9e3d3945af7077c64fffa7daff589cd13ffe1d122414e4d950663c48547ce089380adead
|
|
7
|
+
data.tar.gz: 182af7527af2ca83ea8ae78d411086619f67ff520fabb653368df76a27ea29139cd5c58548089026ffb4785558f61be87deed66454501ea02d4af4bdcbdcba10
|
data/bin/overcommit
CHANGED
|
@@ -18,15 +18,16 @@ if gemfile = YAML.load_file('.overcommit.yml')['gemfile'] rescue nil
|
|
|
18
18
|
ensure
|
|
19
19
|
$stderr = old_stderr
|
|
20
20
|
end
|
|
21
|
-
rescue Bundler::BundlerError =>
|
|
22
|
-
puts "Problem loading '#{gemfile}': #{
|
|
23
|
-
puts "Try running:\nbundle install --gemfile=#{gemfile}" if
|
|
21
|
+
rescue Bundler::BundlerError => e
|
|
22
|
+
puts "Problem loading '#{gemfile}': #{e.message}"
|
|
23
|
+
puts "Try running:\nbundle install --gemfile=#{gemfile}" if e.is_a?(Bundler::GemNotFound)
|
|
24
24
|
exit 78 # EX_CONFIG
|
|
25
|
-
rescue Gem::LoadError =>
|
|
25
|
+
rescue Gem::LoadError => e
|
|
26
26
|
# Handle case where user is executing overcommit without `bundle exec` and
|
|
27
27
|
# whose local Gemfile has a gem requirement that does not match a gem
|
|
28
28
|
# requirement of the installed version of Overcommit.
|
|
29
|
-
raise unless
|
|
29
|
+
raise unless e.message =~ /already activated/i
|
|
30
|
+
|
|
30
31
|
exec('bundle', 'exec', $0, *ARGV)
|
|
31
32
|
end
|
|
32
33
|
end
|
data/config/default.yml
CHANGED
|
@@ -266,6 +266,14 @@ PreCommit:
|
|
|
266
266
|
install_command: 'npm install -g csslint'
|
|
267
267
|
include: '**/*.css'
|
|
268
268
|
|
|
269
|
+
DartAnalyzer:
|
|
270
|
+
enabled: false
|
|
271
|
+
description: 'Analyze with dartanalyzer'
|
|
272
|
+
required_executable: 'dartanalyzer'
|
|
273
|
+
flags: []
|
|
274
|
+
include:
|
|
275
|
+
- '**/*.dart'
|
|
276
|
+
|
|
269
277
|
Dogma:
|
|
270
278
|
enabled: false
|
|
271
279
|
description: 'Analyze with dogma'
|
|
@@ -275,6 +283,13 @@ PreCommit:
|
|
|
275
283
|
- '**/*.ex'
|
|
276
284
|
- '**/*.exs'
|
|
277
285
|
|
|
286
|
+
ErbLint:
|
|
287
|
+
enabled: false
|
|
288
|
+
description: 'Analyze with ERB Lint'
|
|
289
|
+
required_executable: 'erblint'
|
|
290
|
+
install_command: 'bundle install erb_lint'
|
|
291
|
+
include: '**/*.html.erb'
|
|
292
|
+
|
|
278
293
|
EsLint:
|
|
279
294
|
enabled: false
|
|
280
295
|
description: 'Analyze with ESLint'
|
|
@@ -338,7 +353,7 @@ PreCommit:
|
|
|
338
353
|
keywords: ['FContext','FDescribe','FIt','FMeasure','FSpecify','FWhen']
|
|
339
354
|
|
|
340
355
|
GoFmt:
|
|
341
|
-
enabled:
|
|
356
|
+
enabled: false
|
|
342
357
|
description: 'Fix with go fmt'
|
|
343
358
|
required_executable: 'go'
|
|
344
359
|
command: ['go', 'fmt']
|
|
@@ -688,7 +703,7 @@ PreCommit:
|
|
|
688
703
|
enabled: false
|
|
689
704
|
description: 'Analyze with RuboCop'
|
|
690
705
|
required_executable: 'rubocop'
|
|
691
|
-
flags: ['--format=emacs', '--force-exclusion', '--display-cop-names']
|
|
706
|
+
flags: ['--format=emacs', '--force-exclusion', '--display-cop-names', '--disable-pending-cops']
|
|
692
707
|
install_command: 'gem install rubocop'
|
|
693
708
|
include:
|
|
694
709
|
- '**/*.gemspec'
|
|
@@ -885,7 +900,7 @@ PreCommit:
|
|
|
885
900
|
enabled: false
|
|
886
901
|
description: 'Analyze with YAMLlint'
|
|
887
902
|
required_executable: 'yamllint'
|
|
888
|
-
flags: ['--format=parsable']
|
|
903
|
+
flags: ['--format=parsable', '--strict']
|
|
889
904
|
install_command: 'pip install yamllint'
|
|
890
905
|
include:
|
|
891
906
|
- '**/*.yaml'
|
|
@@ -1237,9 +1252,14 @@ PrepareCommitMsg:
|
|
|
1237
1252
|
ReplaceBranch:
|
|
1238
1253
|
enabled: false
|
|
1239
1254
|
description: 'Prepends the commit message with text based on the branch name'
|
|
1240
|
-
branch_pattern: '\A
|
|
1255
|
+
branch_pattern: '\A(\d+)-(\w+).*\z'
|
|
1241
1256
|
replacement_text: '[#\1]'
|
|
1242
|
-
skipped_commit_types:
|
|
1257
|
+
skipped_commit_types:
|
|
1258
|
+
- 'message' # if message is given via `-m`, `-F`
|
|
1259
|
+
- 'template' # if `-t` is given or `commit.template` is set
|
|
1260
|
+
- 'commit' # if `-c`, `-C`, or `--amend` is given
|
|
1261
|
+
- 'merge' # if merging
|
|
1262
|
+
- 'squash' # if squashing
|
|
1243
1263
|
on_fail: warn
|
|
1244
1264
|
|
|
1245
1265
|
# Hooks that run during `git push`, after remote refs have been updated but
|
|
@@ -1264,6 +1284,12 @@ PrePush:
|
|
|
1264
1284
|
flags: ['test']
|
|
1265
1285
|
include: 'src/**/*.rs'
|
|
1266
1286
|
|
|
1287
|
+
FlutterTest:
|
|
1288
|
+
enabled: false
|
|
1289
|
+
description: 'Run flutter test suite'
|
|
1290
|
+
required_executable: 'flutter'
|
|
1291
|
+
flags: ['test']
|
|
1292
|
+
|
|
1267
1293
|
GitLfs:
|
|
1268
1294
|
enabled: false
|
|
1269
1295
|
description: 'Upload files tracked by Git LFS'
|
|
@@ -1310,6 +1336,12 @@ PrePush:
|
|
|
1310
1336
|
destructive_only: true
|
|
1311
1337
|
branches: ['master']
|
|
1312
1338
|
|
|
1339
|
+
PubTest:
|
|
1340
|
+
enabled: false
|
|
1341
|
+
description: 'Run pub test suite'
|
|
1342
|
+
required_executable: 'pub'
|
|
1343
|
+
flags: ['run', 'test']
|
|
1344
|
+
|
|
1313
1345
|
Pytest:
|
|
1314
1346
|
enabled: false
|
|
1315
1347
|
description: 'Run pytest test suite'
|
data/lib/overcommit/cli.rb
CHANGED
|
@@ -6,7 +6,7 @@ require 'optparse'
|
|
|
6
6
|
module Overcommit
|
|
7
7
|
# Responsible for parsing command-line options and executing appropriate
|
|
8
8
|
# application logic based on those options.
|
|
9
|
-
class CLI # rubocop:disable ClassLength
|
|
9
|
+
class CLI # rubocop:disable Metrics/ClassLength
|
|
10
10
|
def initialize(arguments, input, logger)
|
|
11
11
|
@arguments = arguments
|
|
12
12
|
@input = input
|
|
@@ -29,11 +29,11 @@ module Overcommit
|
|
|
29
29
|
when :run_all
|
|
30
30
|
run_all
|
|
31
31
|
end
|
|
32
|
-
rescue Overcommit::Exceptions::ConfigurationSignatureChanged =>
|
|
33
|
-
puts
|
|
32
|
+
rescue Overcommit::Exceptions::ConfigurationSignatureChanged => e
|
|
33
|
+
puts e
|
|
34
34
|
exit 78 # EX_CONFIG
|
|
35
|
-
rescue Overcommit::Exceptions::HookContextLoadError =>
|
|
36
|
-
puts
|
|
35
|
+
rescue Overcommit::Exceptions::HookContextLoadError => e
|
|
36
|
+
puts e
|
|
37
37
|
exit 64 # EX_USAGE
|
|
38
38
|
end
|
|
39
39
|
|
|
@@ -52,8 +52,8 @@ module Overcommit
|
|
|
52
52
|
|
|
53
53
|
# Unconsumed arguments are our targets
|
|
54
54
|
@options[:targets] = @arguments
|
|
55
|
-
rescue OptionParser::InvalidOption =>
|
|
56
|
-
print_help @parser.help,
|
|
55
|
+
rescue OptionParser::InvalidOption => e
|
|
56
|
+
print_help @parser.help, e
|
|
57
57
|
end
|
|
58
58
|
end
|
|
59
59
|
|
|
@@ -94,8 +94,9 @@ module Overcommit
|
|
|
94
94
|
@options[:force] = true
|
|
95
95
|
end
|
|
96
96
|
|
|
97
|
-
opts.on('-r', '--run', 'Run
|
|
97
|
+
opts.on('-r [hook]', '--run [hook]', 'Run specified hook against all git tracked files. Defaults to `pre_commit`.') do |arg| # rubocop:disable Layout/LineLength
|
|
98
98
|
@options[:action] = :run_all
|
|
99
|
+
@options[:hook_to_run] = arg ? arg.to_s : 'run-all'
|
|
99
100
|
end
|
|
100
101
|
end
|
|
101
102
|
|
|
@@ -125,11 +126,11 @@ module Overcommit
|
|
|
125
126
|
@options[:targets].each do |target|
|
|
126
127
|
begin
|
|
127
128
|
Installer.new(log).run(target, @options)
|
|
128
|
-
rescue Overcommit::Exceptions::InvalidGitRepo =>
|
|
129
|
-
log.warning "Invalid repo #{target}: #{
|
|
129
|
+
rescue Overcommit::Exceptions::InvalidGitRepo => e
|
|
130
|
+
log.warning "Invalid repo #{target}: #{e}"
|
|
130
131
|
halt 69 # EX_UNAVAILABLE
|
|
131
|
-
rescue Overcommit::Exceptions::PreExistingHooks =>
|
|
132
|
-
log.warning "Unable to install into #{target}: #{
|
|
132
|
+
rescue Overcommit::Exceptions::PreExistingHooks => e
|
|
133
|
+
log.warning "Unable to install into #{target}: #{e}"
|
|
133
134
|
halt 73 # EX_CANTCREAT
|
|
134
135
|
end
|
|
135
136
|
end
|
|
@@ -199,7 +200,7 @@ module Overcommit
|
|
|
199
200
|
|
|
200
201
|
def run_all
|
|
201
202
|
empty_stdin = File.open(File::NULL) # pre-commit hooks don't take input
|
|
202
|
-
context = Overcommit::HookContext.create(
|
|
203
|
+
context = Overcommit::HookContext.create(@options[:hook_to_run], config, @arguments, empty_stdin) # rubocop:disable Layout/LineLength
|
|
203
204
|
config.apply_environment!(context, ENV)
|
|
204
205
|
|
|
205
206
|
printer = Overcommit::Printer.new(config, log, context)
|
|
@@ -5,7 +5,7 @@ require 'json'
|
|
|
5
5
|
|
|
6
6
|
module Overcommit
|
|
7
7
|
# Stores configuration for Overcommit and the hooks it runs.
|
|
8
|
-
class Configuration # rubocop:disable ClassLength
|
|
8
|
+
class Configuration # rubocop:disable Metrics/ClassLength
|
|
9
9
|
# Creates a configuration from the given hash.
|
|
10
10
|
#
|
|
11
11
|
# @param hash [Hash] loaded YAML config file as a hash
|
|
@@ -24,13 +24,16 @@ module Overcommit
|
|
|
24
24
|
# @option logger [Overcommit::Logger]
|
|
25
25
|
# @return [Overcommit::Configuration]
|
|
26
26
|
def load_from_file(file, options = {})
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
# Psych 4 introduced breaking behavior that doesn't support aliases by
|
|
28
|
+
# default. Explicitly enable aliases if the option is available.
|
|
29
|
+
yaml =
|
|
30
|
+
begin
|
|
31
|
+
YAML.load_file(file, aliases: true)
|
|
32
|
+
rescue ArgumentError
|
|
33
|
+
YAML.load_file(file)
|
|
32
34
|
end
|
|
33
35
|
|
|
36
|
+
hash = yaml ? yaml.to_hash : {}
|
|
34
37
|
Overcommit::Configuration.new(hash, options)
|
|
35
38
|
end
|
|
36
39
|
end
|
|
@@ -72,10 +75,10 @@ module Overcommit
|
|
|
72
75
|
config
|
|
73
76
|
rescue Overcommit::Exceptions::ConfigurationSignatureChanged
|
|
74
77
|
raise
|
|
75
|
-
rescue StandardError =>
|
|
78
|
+
rescue StandardError => e
|
|
76
79
|
raise Overcommit::Exceptions::ConfigurationError,
|
|
77
|
-
"Unable to load configuration from '#{file}': #{
|
|
78
|
-
|
|
80
|
+
"Unable to load configuration from '#{file}': #{e}",
|
|
81
|
+
e.backtrace
|
|
79
82
|
end
|
|
80
83
|
|
|
81
84
|
private
|
|
@@ -1,52 +1,55 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Overcommit::Exceptions
|
|
4
|
+
# Base error class.
|
|
5
|
+
class Error < StandardError; end
|
|
6
|
+
|
|
4
7
|
# Raised when a {Configuration} could not be loaded from a file.
|
|
5
|
-
class ConfigurationError <
|
|
8
|
+
class ConfigurationError < Error; end
|
|
6
9
|
|
|
7
10
|
# Raised when the Overcommit configuration file signature has changed.
|
|
8
|
-
class ConfigurationSignatureChanged <
|
|
11
|
+
class ConfigurationSignatureChanged < Error; end
|
|
9
12
|
|
|
10
13
|
# Raised when trying to read/write to/from the local repo git config fails.
|
|
11
|
-
class GitConfigError <
|
|
14
|
+
class GitConfigError < Error; end
|
|
12
15
|
|
|
13
16
|
# Raised when there was a problem reading submodule information for a repo.
|
|
14
|
-
class GitSubmoduleError <
|
|
17
|
+
class GitSubmoduleError < Error; end
|
|
15
18
|
|
|
16
19
|
# Raised when there was a problem reading git revision information with `rev-list`.
|
|
17
|
-
class GitRevListError <
|
|
20
|
+
class GitRevListError < Error; end
|
|
18
21
|
|
|
19
22
|
# Raised when a {HookContext} is unable to setup the environment before a run.
|
|
20
|
-
class HookSetupFailed <
|
|
23
|
+
class HookSetupFailed < Error; end
|
|
21
24
|
|
|
22
25
|
# Raised when a {HookContext} is unable to clean the environment after a run.
|
|
23
|
-
class HookCleanupFailed <
|
|
26
|
+
class HookCleanupFailed < Error; end
|
|
24
27
|
|
|
25
28
|
# Raised when a hook run was cancelled by the user.
|
|
26
|
-
class HookCancelled <
|
|
29
|
+
class HookCancelled < Error; end
|
|
27
30
|
|
|
28
31
|
# Raised when a hook could not be loaded by a {HookRunner}.
|
|
29
|
-
class HookLoadError <
|
|
32
|
+
class HookLoadError < Error; end
|
|
30
33
|
|
|
31
34
|
# Raised when a {HookRunner} could not be loaded.
|
|
32
|
-
class HookContextLoadError <
|
|
35
|
+
class HookContextLoadError < Error; end
|
|
33
36
|
|
|
34
37
|
# Raised when a pipe character is used in the `execute` helper, as this was
|
|
35
38
|
# likely used in error.
|
|
36
|
-
class InvalidCommandArgs <
|
|
39
|
+
class InvalidCommandArgs < Error; end
|
|
37
40
|
|
|
38
41
|
# Raised when an installation target is not a valid git repository.
|
|
39
|
-
class InvalidGitRepo <
|
|
42
|
+
class InvalidGitRepo < Error; end
|
|
40
43
|
|
|
41
44
|
# Raised when a hook was defined incorrectly.
|
|
42
|
-
class InvalidHookDefinition <
|
|
45
|
+
class InvalidHookDefinition < Error; end
|
|
43
46
|
|
|
44
47
|
# Raised when one or more hook plugin signatures have changed.
|
|
45
|
-
class InvalidHookSignature <
|
|
48
|
+
class InvalidHookSignature < Error; end
|
|
46
49
|
|
|
47
50
|
# Raised when there is a problem processing output into {Hook::Messages}s.
|
|
48
|
-
class MessageProcessingError <
|
|
51
|
+
class MessageProcessingError < Error; end
|
|
49
52
|
|
|
50
53
|
# Raised when an installation target already contains non-Overcommit hooks.
|
|
51
|
-
class PreExistingHooks <
|
|
54
|
+
class PreExistingHooks < Error; end
|
|
52
55
|
end
|
data/lib/overcommit/git_repo.rb
CHANGED
|
@@ -14,7 +14,7 @@ module Overcommit
|
|
|
14
14
|
[^\s]+\s # Ignore old file range
|
|
15
15
|
\+(\d+)(?:,(\d+))? # Extract range of hunk containing start line and number of lines
|
|
16
16
|
\s@@.*$
|
|
17
|
-
/x
|
|
17
|
+
/x.freeze
|
|
18
18
|
|
|
19
19
|
# Regular expression used to extract information from lines of
|
|
20
20
|
# `git submodule status` output
|
|
@@ -22,7 +22,7 @@ module Overcommit
|
|
|
22
22
|
^\s*(?<prefix>[-+U]?)(?<sha1>\w+)
|
|
23
23
|
\s(?<path>[^\s]+?)
|
|
24
24
|
(?:\s\((?<describe>.+)\))?$
|
|
25
|
-
/x
|
|
25
|
+
/x.freeze
|
|
26
26
|
|
|
27
27
|
# Struct encapsulating submodule information extracted from the
|
|
28
28
|
# output of `git submodule status`
|
|
@@ -109,15 +109,16 @@ module Overcommit
|
|
|
109
109
|
# @return [Array<String>] list of absolute file paths
|
|
110
110
|
def list_files(paths = [], options = {})
|
|
111
111
|
ref = options[:ref] || 'HEAD'
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
112
|
+
|
|
113
|
+
result = Overcommit::Utils.execute(%W[git ls-tree --name-only #{ref}], args: paths)
|
|
114
|
+
unless result.success?
|
|
115
|
+
raise Overcommit::Exceptions::Error,
|
|
116
|
+
"Error listing files. EXIT STATUS(es): #{result.statuses}.\n" \
|
|
117
|
+
"STDOUT(s): #{result.stdouts}.\n" \
|
|
118
|
+
"STDERR(s): #{result.stderrs}."
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
result.stdout.split(/\n/).
|
|
121
122
|
map { |relative_file| File.expand_path(relative_file) }.
|
|
122
123
|
reject { |file| File.directory?(file) } # Exclude submodule directories
|
|
123
124
|
end
|
|
@@ -261,9 +262,9 @@ module Overcommit
|
|
|
261
262
|
end
|
|
262
263
|
|
|
263
264
|
modules
|
|
264
|
-
rescue IniParse::IniParseError =>
|
|
265
|
+
rescue IniParse::IniParseError => e
|
|
265
266
|
raise Overcommit::Exceptions::GitSubmoduleError,
|
|
266
|
-
"Unable to read submodule information from #{ref}:.gitmodules file: #{
|
|
267
|
+
"Unable to read submodule information from #{ref}:.gitmodules file: #{e.message}"
|
|
267
268
|
end
|
|
268
269
|
|
|
269
270
|
# Returns the names of all branches containing the given commit.
|
|
@@ -9,7 +9,7 @@ module Overcommit::Hook::CommitMsg
|
|
|
9
9
|
class SpellCheck < Base
|
|
10
10
|
Misspelling = Struct.new(:word, :suggestions)
|
|
11
11
|
|
|
12
|
-
MISSPELLING_REGEX = /^[&#]\s(?<word>\w+)(?:.+?:\s(?<suggestions>.*))
|
|
12
|
+
MISSPELLING_REGEX = /^[&#]\s(?<word>\w+)(?:.+?:\s(?<suggestions>.*))?/.freeze
|
|
13
13
|
|
|
14
14
|
def run
|
|
15
15
|
result = execute(command + [uncommented_commit_msg_file])
|
|
@@ -5,12 +5,13 @@ module Overcommit::Hook::PostCommit
|
|
|
5
5
|
#
|
|
6
6
|
# @see https://www.npmjs.com/package/git-guilt
|
|
7
7
|
class GitGuilt < Base
|
|
8
|
-
PLUS_MINUS_REGEX = /^(.*?)(?:(\++)|(-+))
|
|
8
|
+
PLUS_MINUS_REGEX = /^(.*?)(?:(\++)|(-+))$/.freeze
|
|
9
9
|
GREEN = 32
|
|
10
10
|
RED = 31
|
|
11
11
|
|
|
12
12
|
def run
|
|
13
13
|
return :pass if initial_commit?
|
|
14
|
+
|
|
14
15
|
result = execute(command)
|
|
15
16
|
return :fail, result.stderr unless result.success?
|
|
16
17
|
|
|
@@ -12,9 +12,9 @@ module Overcommit::Hook::PreCommit
|
|
|
12
12
|
result.stdout.chomp
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
if name.empty?
|
|
16
16
|
return :fail,
|
|
17
|
-
"Author must
|
|
17
|
+
"Author name must be non-0 in length.\n" \
|
|
18
18
|
'Set your name with `git config --global user.name "Your Name"` ' \
|
|
19
19
|
'or via the GIT_AUTHOR_NAME environment variable'
|
|
20
20
|
end
|
|
@@ -14,11 +14,11 @@ module Overcommit::Hook::PreCommit
|
|
|
14
14
|
next unless second
|
|
15
15
|
|
|
16
16
|
result = execute(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
command,
|
|
18
|
+
args: [
|
|
19
|
+
"--first=#{first.join(' ')}",
|
|
20
|
+
"--second=#{second.join(' ')}",
|
|
21
|
+
],
|
|
22
22
|
)
|
|
23
23
|
|
|
24
24
|
unless result.stdout.empty?
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PreCommit
|
|
4
|
+
# Runs `dartanalyzer` against modified Dart files.
|
|
5
|
+
# @see https://dart.dev/tools/dartanalyzer
|
|
6
|
+
class DartAnalyzer < Base
|
|
7
|
+
MESSAGE_REGEX = /(?<type>.*)•\ (?<message>[^•]+)•\ (?<file>[^:]+):(?<line>\d+):(\d+)\.*/.freeze
|
|
8
|
+
|
|
9
|
+
def run
|
|
10
|
+
result = execute(command, args: applicable_files)
|
|
11
|
+
return :pass if result.success?
|
|
12
|
+
|
|
13
|
+
extract_messages(
|
|
14
|
+
result.stdout.split("\n").grep(MESSAGE_REGEX),
|
|
15
|
+
MESSAGE_REGEX,
|
|
16
|
+
lambda do |type|
|
|
17
|
+
type.include?('error') ? :error : :warning
|
|
18
|
+
end
|
|
19
|
+
)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PreCommit
|
|
4
|
+
# Runs `erblint` against any modified ERB files.
|
|
5
|
+
#
|
|
6
|
+
# @see https://github.com/Shopify/erb-lint
|
|
7
|
+
class ErbLint < Base
|
|
8
|
+
MESSAGE_REGEX = /(?<message>.+)\nIn file: (?<file>.+):(?<line>\d+)/.freeze
|
|
9
|
+
|
|
10
|
+
def run
|
|
11
|
+
result = execute(command, args: applicable_files)
|
|
12
|
+
return :pass if result.success?
|
|
13
|
+
|
|
14
|
+
extract_messages(
|
|
15
|
+
result.stdout.split("\n\n")[1..-1],
|
|
16
|
+
MESSAGE_REGEX
|
|
17
|
+
)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -19,20 +19,17 @@ module Overcommit::Hook::PreCommit
|
|
|
19
19
|
# @see http://eslint.org/
|
|
20
20
|
class EsLint < Base
|
|
21
21
|
def run
|
|
22
|
+
eslint_regex = /^(?<file>[^\s](?:\w:)?[^:]+):[^\d]+(?<line>\d+).*?(?<type>Error|Warning)/
|
|
22
23
|
result = execute(command, args: applicable_files)
|
|
23
24
|
output = result.stdout.chomp
|
|
24
|
-
messages = output.split("\n").grep(
|
|
25
|
+
messages = output.split("\n").grep(eslint_regex)
|
|
25
26
|
|
|
26
27
|
return [:fail, result.stderr] if messages.empty? && !result.success?
|
|
27
28
|
return :pass if result.success? && output.empty?
|
|
28
29
|
|
|
29
30
|
# example message:
|
|
30
31
|
# path/to/file.js: line 1, col 0, Error - Error message (ruleName)
|
|
31
|
-
extract_messages(
|
|
32
|
-
messages,
|
|
33
|
-
/^(?<file>(?:\w:)?[^:]+):[^\d]+(?<line>\d+).*?(?<type>Error|Warning)/,
|
|
34
|
-
lambda { |type| type.downcase.to_sym }
|
|
35
|
-
)
|
|
32
|
+
extract_messages(messages, eslint_regex, lambda { |type| type.downcase.to_sym })
|
|
36
33
|
end
|
|
37
34
|
end
|
|
38
35
|
end
|
|
@@ -102,7 +102,7 @@ module Overcommit::Hook::PreCommit
|
|
|
102
102
|
if result.success?
|
|
103
103
|
:pass
|
|
104
104
|
else
|
|
105
|
-
|
|
105
|
+
[:warn, result.stderr + result.stdout]
|
|
106
106
|
end
|
|
107
107
|
end
|
|
108
108
|
|
|
@@ -137,12 +137,14 @@ module Overcommit::Hook::PreCommit
|
|
|
137
137
|
|
|
138
138
|
def modified(type)
|
|
139
139
|
return [] if !config["#{type}_directory"] || config["#{type}_directory"].empty?
|
|
140
|
+
|
|
140
141
|
@modified ||= {}
|
|
141
142
|
@modified[type] ||= directories_changed(full_directory_path("#{type}_directory"))
|
|
142
143
|
end
|
|
143
144
|
|
|
144
145
|
def full_directory_path(config_option)
|
|
145
146
|
return config[config_option] if config[config_option].start_with?(File::SEPARATOR)
|
|
147
|
+
|
|
146
148
|
File.absolute_path(File.join(Overcommit::Utils.repo_root, config[config_option]))
|
|
147
149
|
end
|
|
148
150
|
end
|
|
@@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit
|
|
|
5
5
|
#
|
|
6
6
|
# @see http://checkstyle.sourceforge.net/
|
|
7
7
|
class JavaCheckstyle < Base
|
|
8
|
-
MESSAGE_REGEX = /^(\[(?<type>[^\]]+)\]\s+)?(?<file>(?:\w:)?[^:]+):(?<line>\d+)
|
|
8
|
+
MESSAGE_REGEX = /^(\[(?<type>[^\]]+)\]\s+)?(?<file>(?:\w:)?[^:]+):(?<line>\d+)/.freeze
|
|
9
9
|
|
|
10
10
|
MESSAGE_TYPE_CATEGORIZER = lambda do |type|
|
|
11
11
|
%w[WARN INFO].include?(type.to_s) ? :warning : :error
|