overcommit 0.57.0 → 0.59.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/bin/overcommit +6 -5
  3. data/config/default.yml +20 -0
  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 +11 -8
  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 +22 -0
  20. data/lib/overcommit/hook/pre_commit/erb_lint.rb +1 -1
  21. data/lib/overcommit/hook/pre_commit/es_lint.rb +3 -6
  22. data/lib/overcommit/hook/pre_commit/fasterer.rb +1 -1
  23. data/lib/overcommit/hook/pre_commit/foodcritic.rb +3 -1
  24. data/lib/overcommit/hook/pre_commit/hlint.rb +1 -1
  25. data/lib/overcommit/hook/pre_commit/html_tidy.rb +1 -1
  26. data/lib/overcommit/hook/pre_commit/java_checkstyle.rb +1 -1
  27. data/lib/overcommit/hook/pre_commit/js_lint.rb +1 -1
  28. data/lib/overcommit/hook/pre_commit/jsl.rb +1 -1
  29. data/lib/overcommit/hook/pre_commit/kt_lint.rb +1 -1
  30. data/lib/overcommit/hook/pre_commit/license_finder.rb +1 -0
  31. data/lib/overcommit/hook/pre_commit/line_endings.rb +3 -2
  32. data/lib/overcommit/hook/pre_commit/nginx_test.rb +1 -1
  33. data/lib/overcommit/hook/pre_commit/php_cs.rb +1 -1
  34. data/lib/overcommit/hook/pre_commit/php_cs_fixer.rb +1 -1
  35. data/lib/overcommit/hook/pre_commit/php_lint.rb +3 -3
  36. data/lib/overcommit/hook/pre_commit/php_stan.rb +1 -1
  37. data/lib/overcommit/hook/pre_commit/puppet_lint.rb +1 -1
  38. data/lib/overcommit/hook/pre_commit/puppet_metadata_json_lint.rb +1 -1
  39. data/lib/overcommit/hook/pre_commit/pyflakes.rb +1 -1
  40. data/lib/overcommit/hook/pre_commit/pylint.rb +1 -1
  41. data/lib/overcommit/hook/pre_commit/python_flake8.rb +1 -1
  42. data/lib/overcommit/hook/pre_commit/rails_best_practices.rb +1 -1
  43. data/lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb +2 -2
  44. data/lib/overcommit/hook/pre_commit/rst_lint.rb +1 -1
  45. data/lib/overcommit/hook/pre_commit/scalariform.rb +1 -1
  46. data/lib/overcommit/hook/pre_commit/scalastyle.rb +1 -1
  47. data/lib/overcommit/hook/pre_commit/scss_lint.rb +3 -3
  48. data/lib/overcommit/hook/pre_commit/semi_standard.rb +1 -1
  49. data/lib/overcommit/hook/pre_commit/sqlint.rb +1 -1
  50. data/lib/overcommit/hook/pre_commit/standard.rb +1 -1
  51. data/lib/overcommit/hook/pre_commit/stylelint.rb +2 -1
  52. data/lib/overcommit/hook/pre_commit/swift_lint.rb +1 -1
  53. data/lib/overcommit/hook/pre_commit/ts_lint.rb +4 -4
  54. data/lib/overcommit/hook/pre_commit/w3c_css.rb +4 -4
  55. data/lib/overcommit/hook/pre_commit/w3c_html.rb +4 -4
  56. data/lib/overcommit/hook/pre_commit/xml_lint.rb +1 -1
  57. data/lib/overcommit/hook/pre_commit/yaml_lint.rb +25 -4
  58. data/lib/overcommit/hook/pre_commit/yaml_syntax.rb +7 -3
  59. data/lib/overcommit/hook/pre_commit/yard_coverage.rb +0 -1
  60. data/lib/overcommit/hook/pre_push/cargo_test.rb +1 -0
  61. data/lib/overcommit/hook/pre_push/flutter_test.rb +16 -0
  62. data/lib/overcommit/hook/pre_push/pub_test.rb +16 -0
  63. data/lib/overcommit/hook/prepare_commit_msg/base.rb +1 -0
  64. data/lib/overcommit/hook/prepare_commit_msg/replace_branch.rb +1 -1
  65. data/lib/overcommit/hook/shared/bower_install.rb +1 -0
  66. data/lib/overcommit/hook/shared/bundle_install.rb +1 -0
  67. data/lib/overcommit/hook/shared/composer_install.rb +1 -0
  68. data/lib/overcommit/hook/shared/npm_install.rb +1 -0
  69. data/lib/overcommit/hook/shared/pronto.rb +16 -4
  70. data/lib/overcommit/hook/shared/yarn_install.rb +1 -0
  71. data/lib/overcommit/hook_context/helpers/file_modifications.rb +1 -0
  72. data/lib/overcommit/hook_context/helpers/stash_unstaged_changes.rb +4 -1
  73. data/lib/overcommit/hook_context/post_commit.rb +1 -0
  74. data/lib/overcommit/hook_context/pre_push.rb +1 -0
  75. data/lib/overcommit/hook_context/run_all.rb +1 -0
  76. data/lib/overcommit/hook_context.rb +3 -3
  77. data/lib/overcommit/hook_loader/base.rb +3 -3
  78. data/lib/overcommit/hook_loader/plugin_hook_loader.rb +3 -3
  79. data/lib/overcommit/hook_runner.rb +8 -7
  80. data/lib/overcommit/hook_signer.rb +1 -0
  81. data/lib/overcommit/installer.rb +2 -1
  82. data/lib/overcommit/logger.rb +5 -0
  83. data/lib/overcommit/printer.rb +3 -4
  84. data/lib/overcommit/subprocess.rb +2 -1
  85. data/lib/overcommit/utils/messages_utils.rb +1 -0
  86. data/lib/overcommit/version.rb +1 -1
  87. data/libexec/index-tags +6 -4
  88. data/template-dir/hooks/commit-msg +27 -20
  89. data/template-dir/hooks/overcommit-hook +27 -20
  90. data/template-dir/hooks/post-checkout +27 -20
  91. data/template-dir/hooks/post-commit +27 -20
  92. data/template-dir/hooks/post-merge +27 -20
  93. data/template-dir/hooks/post-rewrite +27 -20
  94. data/template-dir/hooks/pre-commit +27 -20
  95. data/template-dir/hooks/pre-push +27 -20
  96. data/template-dir/hooks/pre-rebase +27 -20
  97. data/template-dir/hooks/prepare-commit-msg +27 -20
  98. metadata +20 -3
@@ -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.sort.last
21
+ end.max
22
22
 
23
23
  up_to_date = schema.include?(latest_version)
24
24
 
@@ -7,7 +7,7 @@ module Overcommit::Hook::PreCommit
7
7
  class RstLint < Base
8
8
  MESSAGE_REGEX = /
9
9
  ^(?<type>INFO|WARNING|ERROR|SEVERE)(?<file>(?:\w:)?[^:]+):(?<line>\d+)\s(?<msg>.+)
10
- /x
10
+ /x.freeze
11
11
 
12
12
  def run
13
13
  result = execute(command, args: applicable_files)
@@ -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)
@@ -10,7 +10,7 @@ module Overcommit::Hook::PreCommit
10
10
  file=(?<file>(?:\w:)?.+)\s
11
11
  message=.+\s*
12
12
  (line=(?<line>\d+))?
13
- /x
13
+ /x.freeze
14
14
 
15
15
  def run
16
16
  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 => ex
22
- return :fail, "Unable to parse JSON returned by SCSS-Lint: #{ex.message}\n" \
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>.+):\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)
@@ -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
- if result.success?
12
- :pass
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, 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
@@ -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
@@ -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
@@ -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 --quiet])
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:" \
@@ -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.