overcommit 0.14.1 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/config/starter.yml +31 -0
  3. data/lib/overcommit/configuration_loader.rb +2 -2
  4. data/lib/overcommit/constants.rb +1 -0
  5. data/lib/overcommit/exceptions.rb +3 -0
  6. data/lib/overcommit/hook/base.rb +27 -0
  7. data/lib/overcommit/hook/commit_msg/gerrit_change_id.rb +2 -2
  8. data/lib/overcommit/hook/commit_msg/hard_tabs.rb +1 -1
  9. data/lib/overcommit/hook/commit_msg/russian_novel.rb +1 -1
  10. data/lib/overcommit/hook/commit_msg/single_line_subject.rb +1 -1
  11. data/lib/overcommit/hook/commit_msg/text_width.rb +3 -3
  12. data/lib/overcommit/hook/commit_msg/trailing_period.rb +1 -1
  13. data/lib/overcommit/hook/post_checkout/bundle_check.rb +2 -2
  14. data/lib/overcommit/hook/post_checkout/index_tags.rb +3 -3
  15. data/lib/overcommit/hook/pre_commit/author_email.rb +6 -5
  16. data/lib/overcommit/hook/pre_commit/author_name.rb +4 -4
  17. data/lib/overcommit/hook/pre_commit/berksfile_check.rb +3 -3
  18. data/lib/overcommit/hook/pre_commit/brakeman.rb +2 -2
  19. data/lib/overcommit/hook/pre_commit/bundle_check.rb +4 -4
  20. data/lib/overcommit/hook/pre_commit/chamber_security.rb +2 -2
  21. data/lib/overcommit/hook/pre_commit/coffee_lint.rb +2 -2
  22. data/lib/overcommit/hook/pre_commit/css_lint.rb +2 -2
  23. data/lib/overcommit/hook/pre_commit/go_lint.rb +2 -2
  24. data/lib/overcommit/hook/pre_commit/haml_lint.rb +2 -2
  25. data/lib/overcommit/hook/pre_commit/hard_tabs.rb +2 -2
  26. data/lib/overcommit/hook/pre_commit/image_optim.rb +3 -3
  27. data/lib/overcommit/hook/pre_commit/js_hint.rb +2 -2
  28. data/lib/overcommit/hook/pre_commit/jscs.rb +2 -2
  29. data/lib/overcommit/hook/pre_commit/json_syntax.rb +2 -2
  30. data/lib/overcommit/hook/pre_commit/jsx_hint.rb +2 -2
  31. data/lib/overcommit/hook/pre_commit/local_paths_in_gemfile.rb +1 -1
  32. data/lib/overcommit/hook/pre_commit/merge_conflicts.rb +2 -2
  33. data/lib/overcommit/hook/pre_commit/pry_binding.rb +2 -2
  34. data/lib/overcommit/hook/pre_commit/python_flake8.rb +2 -2
  35. data/lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb +4 -4
  36. data/lib/overcommit/hook/pre_commit/rubocop.rb +2 -2
  37. data/lib/overcommit/hook/pre_commit/scss_lint.rb +2 -2
  38. data/lib/overcommit/hook/pre_commit/trailing_whitespace.rb +2 -2
  39. data/lib/overcommit/hook/pre_commit/travis_lint.rb +2 -2
  40. data/lib/overcommit/hook/pre_commit/yaml_syntax.rb +2 -2
  41. data/lib/overcommit/hook_context/pre_commit.rb +16 -4
  42. data/lib/overcommit/hook_runner.rb +6 -6
  43. data/lib/overcommit/installer.rb +10 -0
  44. data/lib/overcommit/printer.rb +22 -5
  45. data/lib/overcommit/version.rb +1 -1
  46. data/template-dir/hooks/commit-msg +4 -1
  47. data/template-dir/hooks/overcommit-hook +4 -1
  48. data/template-dir/hooks/post-checkout +4 -1
  49. data/template-dir/hooks/pre-commit +4 -1
  50. metadata +5 -5
  51. data/config/templates.yml +0 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe8456581eecc5b4f317667847ef8fbd1584f1db
4
- data.tar.gz: dd15307f76b68cb942311d50b3c8263fc246e511
3
+ metadata.gz: 043d9e4f69b46108c0de597ecf9640f31149c98e
4
+ data.tar.gz: 9b61ce0b7846dae6580ec4d8934b4f2ec6484eab
5
5
  SHA512:
6
- metadata.gz: e20922efd93d40a9085233a95f6eae0b945965328b12bf4652ac787b90ae729a856d56278f9ed5d0987065834723bd87be400767cc7a338b35b4f853ad349ee3
7
- data.tar.gz: 6dc2b6b044f372951ba79b9802d68557160fcf86fa1be811185f167083263d3e8898fb2862deec96f254f02b6479c71c9d557f7ede669cf68b8499fcb27c2ac8
6
+ metadata.gz: c4f4dc8af420e79565d242caf90eb37148fe7cbc4f1cd015627a4f8863a16f8237da519ed738c7620dff9c35b0a6f86614e5fae0923f0a4f1cb2c3f9f1fc2876
7
+ data.tar.gz: e1fd1a72991e8e708503cf870c68f333c4321eab536e010bc80eb2cff2b1f116c10f8710a540697d3d4ecd202e3e16e4a326ab8f37ede4762d800323c5d8af71
@@ -0,0 +1,31 @@
1
+ # Use this file to configure the Overcommit hooks you wish to use. This will
2
+ # extend the default configuration defined in:
3
+ # https://github.com/causes/overcommit/blob/master/config/default.yml
4
+ #
5
+ # At the topmost level of this YAML file is a key representing type of hook
6
+ # being run (e.g. pre-commit, commit-msg, etc.). Within each type you can
7
+ # customize each hook, such as whether to only run it on certain files (via
8
+ # `include`), whether to only display output if it fails (via `quiet`), etc.
9
+ #
10
+ # For a complete list of hooks, see:
11
+ # https://github.com/causes/overcommit/tree/master/lib/overcommit/hook
12
+ #
13
+ # For a complete list of options that you can use to customize hooks, see:
14
+ # https://github.com/causes/overcommit#configuration
15
+ #
16
+ # Uncomment the following lines to make the configuration take effect.
17
+
18
+ #PreCommit:
19
+ # Rubocop:
20
+ # on_warn: fail # Treat all warnings as failures
21
+ #
22
+ # TrailingWhitespace:
23
+ # exclude:
24
+ # - '**/db/structure.sql' # Ignore trailing whitespace in generated files
25
+ #
26
+ #PostCheckout:
27
+ # ALL: # Special hook name that customizes all hooks of this type
28
+ # quiet: true # Change all post-checkout hooks to only display output on failure
29
+ #
30
+ # IndexTags:
31
+ # enabled: true # Generate a tags file with `ctags` each time HEAD changes
@@ -4,11 +4,11 @@ module Overcommit
4
4
  # Manages configuration file loading.
5
5
  class ConfigurationLoader
6
6
  DEFAULT_CONFIG_PATH = File.join(OVERCOMMIT_HOME, 'config', 'default.yml')
7
- FILE_NAME = '.overcommit.yml'
8
7
 
9
8
  class << self
10
9
  def load_repo_config
11
- overcommit_yml = File.join(Overcommit::Utils.repo_root, FILE_NAME)
10
+ overcommit_yml = File.join(Overcommit::Utils.repo_root,
11
+ OVERCOMMIT_CONFIG_FILE_NAME)
12
12
 
13
13
  if File.exist?(overcommit_yml)
14
14
  load_file(overcommit_yml)
@@ -1,6 +1,7 @@
1
1
  # Global application constants.
2
2
  module Overcommit
3
3
  OVERCOMMIT_HOME = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
4
+ OVERCOMMIT_CONFIG_FILE_NAME = '.overcommit.yml'
4
5
 
5
6
  REPO_URL = 'https://github.com/causes/overcommit'
6
7
  BUG_REPORT_URL = "#{REPO_URL}/issues"
@@ -5,6 +5,9 @@ module Overcommit::Exceptions
5
5
  # Raised when trying to read/write to/from the local repo git config fails.
6
6
  class GitConfigError < StandardError; end
7
7
 
8
+ # Raised when a {HookContext} is unable to setup the environment before a run.
9
+ class HookSetupFailed < StandardError; end
10
+
8
11
  # Raised when a hook run was cancelled by the user.
9
12
  class HookCancelled < StandardError; end
10
13
 
@@ -6,6 +6,7 @@ module Overcommit::Hook
6
6
  extend Forwardable
7
7
 
8
8
  def_delegators :@context, :modified_files
9
+ attr_reader :config
9
10
 
10
11
  def initialize(config, context)
11
12
  @config = config.for_hook(self)
@@ -17,6 +18,18 @@ module Overcommit::Hook
17
18
  raise NotImplementedError, 'Hook must define `run`'
18
19
  end
19
20
 
21
+ # Runs the hook and transforms the status returned based on the hook's
22
+ # configuration.
23
+ #
24
+ # Poorly named because we already have a bunch of hooks in the wild that
25
+ # implement `#run`, and we needed a wrapper step to transform the status
26
+ # based on any custom configuration.
27
+ def run_and_transform
28
+ status, output = run
29
+
30
+ [transform_status(status), output]
31
+ end
32
+
20
33
  def name
21
34
  self.class.name.split('::').last
22
35
  end
@@ -93,5 +106,19 @@ module Overcommit::Hook
93
106
  File::FNM_DOTMATCH # Wildcards match dotfiles
94
107
  )
95
108
  end
109
+
110
+ # Transforms the hook's status based on custom configuration.
111
+ #
112
+ # This allows users to change failures into warnings, or vice versa.
113
+ def transform_status(status)
114
+ case status
115
+ when :fail, :bad
116
+ @config.fetch('on_fail', :fail).to_sym
117
+ when :warn
118
+ @config.fetch('on_warn', :warn).to_sym
119
+ else
120
+ status
121
+ end
122
+ end
96
123
  end
97
124
  end
@@ -10,9 +10,9 @@ module Overcommit::Hook::CommitMsg
10
10
 
11
11
  def run
12
12
  result = execute([SCRIPT_LOCATION, commit_message_file])
13
- return :good if result.success?
13
+ return :pass if result.success?
14
14
 
15
- [:bad, result.stdout]
15
+ [:fail, result.stdout]
16
16
  end
17
17
  end
18
18
  end
@@ -7,7 +7,7 @@ module Overcommit::Hook::CommitMsg
7
7
  return :warn, "Don't use hard tabs in commit messages"
8
8
  end
9
9
 
10
- :good
10
+ :pass
11
11
  end
12
12
  end
13
13
  end
@@ -8,7 +8,7 @@ module Overcommit::Hook::CommitMsg
8
8
  return :warn, 'You seem to have authored a Russian novel; congratulations!'
9
9
  end
10
10
 
11
- :good
11
+ :pass
12
12
  end
13
13
  end
14
14
  end
@@ -6,7 +6,7 @@ module Overcommit::Hook::CommitMsg
6
6
  return :warn, 'Subject should be one line and followed by a blank line'
7
7
  end
8
8
 
9
- :good
9
+ :pass
10
10
  end
11
11
  end
12
12
  end
@@ -5,8 +5,8 @@ module Overcommit::Hook::CommitMsg
5
5
  def run
6
6
  errors = []
7
7
 
8
- max_subject_width = @config['max_subject_width']
9
- max_body_width = @config['max_body_width']
8
+ max_subject_width = config['max_subject_width']
9
+ max_body_width = config['max_body_width']
10
10
 
11
11
  if commit_message_lines.first.size > max_subject_width
12
12
  errors << "Please keep the subject <= #{max_subject_width} characters"
@@ -25,7 +25,7 @@ module Overcommit::Hook::CommitMsg
25
25
 
26
26
  return :warn, errors.join("\n") if errors.any?
27
27
 
28
- :good
28
+ :pass
29
29
  end
30
30
  end
31
31
  end
@@ -6,7 +6,7 @@ module Overcommit::Hook::CommitMsg
6
6
  return :warn, 'Please omit trailing period from commit message subject'
7
7
  end
8
8
 
9
- :good
9
+ :pass
10
10
  end
11
11
  end
12
12
  end
@@ -11,7 +11,7 @@ module Overcommit::Hook::PostCheckout
11
11
  return :warn, "#{LOCK_FILE} is not up-to-date -- run `bundle check`"
12
12
  end
13
13
 
14
- :good
14
+ :pass
15
15
  end
16
16
 
17
17
  private
@@ -22,7 +22,7 @@ module Overcommit::Hook::PostCheckout
22
22
  result = execute(%w[git diff --exit-code --name-only] + [new_head, previous_head])
23
23
 
24
24
  result.stdout.split("\n").any? do |file|
25
- Array(@config['include']).any? { |glob| Dir[glob].include?(file) }
25
+ Array(config['include']).any? { |glob| Dir[glob].include?(file) }
26
26
  end
27
27
  end
28
28
 
@@ -4,12 +4,12 @@ module Overcommit::Hook::PostCheckout
4
4
  class IndexTags < Base
5
5
  def run
6
6
  unless in_path?('ctags')
7
- return :good # Silently ignore
7
+ return :pass # Silently ignore
8
8
  end
9
9
 
10
10
  index_tags_in_background
11
11
 
12
- :good
12
+ :pass
13
13
  end
14
14
 
15
15
  private
@@ -17,7 +17,7 @@ module Overcommit::Hook::PostCheckout
17
17
  SCRIPT_LOCATION = Overcommit::Utils.script_path('index-tags')
18
18
 
19
19
  def index_tags_in_background
20
- ctags_args = @config['ctags_arguments']
20
+ ctags_args = config['ctags_arguments']
21
21
 
22
22
  # TODO: come up with Ruby 1.8-friendly way to do this
23
23
  Process.detach(Process.spawn("#{SCRIPT_LOCATION} #{ctags_args}"))
@@ -5,13 +5,14 @@ module Overcommit::Hook::PreCommit
5
5
  result = execute(%w[git config --get user.email])
6
6
  email = result.stdout.chomp
7
7
 
8
- unless email =~ /#{@config['pattern']}/
9
- return :bad, "Author has an invalid email address: '#{email}'\n" \
10
- 'Set your email with ' \
11
- '`git config --global user.email your_email@example.com`'
8
+ unless email =~ /#{config['pattern']}/
9
+ return :fail,
10
+ "Author has an invalid email address: '#{email}'\n" \
11
+ 'Set your email with ' \
12
+ '`git config --global user.email your_email@example.com`'
12
13
  end
13
14
 
14
- :good
15
+ :pass
15
16
  end
16
17
  end
17
18
  end
@@ -6,12 +6,12 @@ module Overcommit::Hook::PreCommit
6
6
  name = result.stdout.chomp
7
7
 
8
8
  unless name.split(' ').count >= 2
9
- return :bad, 'Author must have at least first and last name, but ' \
10
- "was: '#{name}'.\nSet your name with " \
11
- "`git config --global user.name 'Your Name'`"
9
+ return :fail,
10
+ "Author must have at least first and last name, but was: #{name}." \
11
+ "\nSet your name with `git config --global user.name 'Your Name'`"
12
12
  end
13
13
 
14
- :good
14
+ :pass
15
15
  end
16
16
  end
17
17
  end
@@ -11,14 +11,14 @@ module Overcommit::Hook::PreCommit
11
11
 
12
12
  # Ignore if Berksfile.lock is not tracked by git
13
13
  ignored_files = execute(%w[git ls-files -o -i --exclude-standard]).stdout.split("\n")
14
- return :good if ignored_files.include?(LOCK_FILE)
14
+ return :pass if ignored_files.include?(LOCK_FILE)
15
15
 
16
16
  result = execute(%w[berks list --quiet])
17
17
  unless result.success?
18
- return :bad, result.stderr
18
+ return :fail, result.stderr
19
19
  end
20
20
 
21
- :good
21
+ :pass
22
22
  end
23
23
  end
24
24
  end
@@ -8,9 +8,9 @@ module Overcommit::Hook::PreCommit
8
8
 
9
9
  result = execute(%w[brakeman --exit-on-warn --quiet --summary --only-files] +
10
10
  applicable_files)
11
- return :good if result.success?
11
+ return :pass if result.success?
12
12
 
13
- [:bad, result.stdout]
13
+ [:fail, result.stdout]
14
14
  end
15
15
  end
16
16
  end
@@ -11,19 +11,19 @@ module Overcommit::Hook::PreCommit
11
11
 
12
12
  # Ignore if Gemfile.lock is not tracked by git
13
13
  ignored_files = execute(%w[git ls-files -o -i --exclude-standard]).stdout.split("\n")
14
- return :good if ignored_files.include?(LOCK_FILE)
14
+ return :pass if ignored_files.include?(LOCK_FILE)
15
15
 
16
16
  result = execute(%w[bundle check])
17
17
  unless result.success?
18
- return :bad, result.stdout
18
+ return :fail, result.stdout
19
19
  end
20
20
 
21
21
  result = execute(%w[git diff --quiet --] + [LOCK_FILE])
22
22
  unless result.success?
23
- return :bad, "#{LOCK_FILE} is not up-to-date -- run `bundle check`"
23
+ return :fail, "#{LOCK_FILE} is not up-to-date -- run `bundle check`"
24
24
  end
25
25
 
26
- :good
26
+ :pass
27
27
  end
28
28
  end
29
29
  end
@@ -8,8 +8,8 @@ module Overcommit::Hook::PreCommit
8
8
 
9
9
  result = execute(%w[chamber secure --echo --files] + applicable_files)
10
10
 
11
- return :good if result.stdout.empty?
12
- [:bad, "These settings appear to need to be secured but were not: #{result.stdout}"]
11
+ return :pass if result.stdout.empty?
12
+ [:fail, "These settings appear to need to be secured but were not: #{result.stdout}"]
13
13
  end
14
14
  end
15
15
  end
@@ -7,9 +7,9 @@ module Overcommit::Hook::PreCommit
7
7
  end
8
8
 
9
9
  result = execute(%w[coffeelint --quiet] + applicable_files)
10
- return :good if result.success?
10
+ return :pass if result.success?
11
11
 
12
- [:bad, result.stdout]
12
+ [:fail, result.stdout]
13
13
  end
14
14
  end
15
15
  end
@@ -7,9 +7,9 @@ module Overcommit::Hook::PreCommit
7
7
  end
8
8
 
9
9
  result = execute(%w[csslint --quiet --format=compact] + applicable_files)
10
- return :good if result.stdout !~ /Error - (?!Unknown @ rule)/
10
+ return :pass if result.stdout !~ /Error - (?!Unknown @ rule)/
11
11
 
12
- [:bad, result.stdout]
12
+ [:fail, result.stdout]
13
13
  end
14
14
  end
15
15
  end
@@ -8,9 +8,9 @@ module Overcommit::Hook::PreCommit
8
8
 
9
9
  result = execute(%w[golint] + applicable_files)
10
10
  # Unfortunately the exit code is always 0
11
- return :good if result.stdout.empty?
11
+ return :pass if result.stdout.empty?
12
12
 
13
- [:bad, result.stdout]
13
+ [:fail, result.stdout]
14
14
  end
15
15
  end
16
16
  end
@@ -7,7 +7,7 @@ module Overcommit::Hook::PreCommit
7
7
  end
8
8
 
9
9
  result = execute(%w[haml-lint] + applicable_files)
10
- return :good if result.success?
10
+ return :pass if result.success?
11
11
 
12
12
  # Keep lines from the output for files that we actually modified
13
13
  error_lines, warning_lines = result.stdout.split("\n").partition do |output_line|
@@ -18,7 +18,7 @@ module Overcommit::Hook::PreCommit
18
18
  modified_lines(file).include?(line.to_i)
19
19
  end
20
20
 
21
- return :bad, error_lines.join("\n") unless error_lines.empty?
21
+ return :fail, error_lines.join("\n") unless error_lines.empty?
22
22
 
23
23
  [:warn, "Modified files have lints (on lines you didn't modify)\n" <<
24
24
  warning_lines.join("\n")]
@@ -5,10 +5,10 @@ module Overcommit::Hook::PreCommit
5
5
  # Catches hard tabs
6
6
  result = execute(%w[grep -IHn] + ["\t"] + applicable_files)
7
7
  unless result.stdout.empty?
8
- return :bad, "Hard tabs detected:\n#{result.stdout}"
8
+ return :fail, "Hard tabs detected:\n#{result.stdout}"
9
9
  end
10
10
 
11
- :good
11
+ :pass
12
12
  end
13
13
  end
14
14
  end
@@ -12,17 +12,17 @@ module Overcommit::Hook::PreCommit
12
12
  begin
13
13
  optimize_images(applicable_files)
14
14
  rescue ::ImageOptim::BinNotFoundError => e
15
- return :bad, "#{e.message}. The image_optim gem is dependendent on this binary."
15
+ return :fail, "#{e.message}. The image_optim gem is dependendent on this binary."
16
16
  end
17
17
 
18
18
  if optimized_images.any?
19
- return :bad,
19
+ return :fail,
20
20
  "The following images are optimizable:\n#{optimized_images.join("\n")}" \
21
21
  "\n\nOptimize them by running:\n" \
22
22
  " image_optim #{optimized_images.join(' ')}"
23
23
  end
24
24
 
25
- :good
25
+ :pass
26
26
  end
27
27
 
28
28
  private
@@ -9,9 +9,9 @@ module Overcommit::Hook::PreCommit
9
9
  result = execute(%w[jshint] + applicable_files)
10
10
  output = result.stdout
11
11
 
12
- return :good if output.empty?
12
+ return :pass if output.empty?
13
13
 
14
- [:bad, output]
14
+ [:fail, output]
15
15
  end
16
16
  end
17
17
  end
@@ -8,7 +8,7 @@ module Overcommit::Hook::PreCommit
8
8
  end
9
9
 
10
10
  result = execute(%w[jscs --reporter=inline] + applicable_files)
11
- return :good if result.success?
11
+ return :pass if result.success?
12
12
 
13
13
  if result.status == 1
14
14
  return :warn, result.stderr.chomp
@@ -23,7 +23,7 @@ module Overcommit::Hook::PreCommit
23
23
  modified_lines(file).include?(line.to_i)
24
24
  end
25
25
 
26
- return :bad, error_lines.join("\n") unless error_lines.empty?
26
+ return :fail, error_lines.join("\n") unless error_lines.empty?
27
27
 
28
28
  [:warn, "Modified files have lints (on lines you didn't modify)\n" <<
29
29
  warning_lines.join("\n")]
@@ -14,9 +14,9 @@ module Overcommit::Hook::PreCommit
14
14
  end
15
15
  end
16
16
 
17
- return :good if output.empty?
17
+ return :pass if output.empty?
18
18
 
19
- [:bad, output]
19
+ [:fail, output]
20
20
  end
21
21
  end
22
22
  end
@@ -9,9 +9,9 @@ module Overcommit::Hook::PreCommit
9
9
  result = execute(%w[jsxhint] + applicable_files)
10
10
  output = result.stdout
11
11
 
12
- return :good if output.empty?
12
+ return :pass if output.empty?
13
13
 
14
- [:bad, output]
14
+ [:fail, output]
15
15
  end
16
16
  end
17
17
  end
@@ -8,7 +8,7 @@ module Overcommit::Hook::PreCommit
8
8
  return :warn, "Avoid pointing to local paths in Gemfiles:\n#{result.stdout}"
9
9
  end
10
10
 
11
- :good
11
+ :pass
12
12
  end
13
13
  end
14
14
  end
@@ -5,10 +5,10 @@ module Overcommit::Hook::PreCommit
5
5
  result = execute(%w[grep -IHn ^<<<<<<<\s] + applicable_files)
6
6
 
7
7
  unless result.stdout.empty?
8
- return :bad, "Merge conflict markers detected:\n#{result.stdout}"
8
+ return :fail, "Merge conflict markers detected:\n#{result.stdout}"
9
9
  end
10
10
 
11
- :good
11
+ :pass
12
12
  end
13
13
  end
14
14
  end
@@ -5,10 +5,10 @@ module Overcommit::Hook::PreCommit
5
5
  result = execute(%w[grep -IHnE ^\s*binding\.pry] + applicable_files)
6
6
 
7
7
  unless result.stdout.empty?
8
- return :bad, "Found a `binding.pry` call left in:\n#{result.stdout}"
8
+ return :fail, "Found a `binding.pry` call left in:\n#{result.stdout}"
9
9
  end
10
10
 
11
- :good
11
+ :pass
12
12
  end
13
13
  end
14
14
  end
@@ -7,9 +7,9 @@ module Overcommit::Hook::PreCommit
7
7
  end
8
8
 
9
9
  result = execute(%w[flake8] + applicable_files)
10
- return :good if result.success?
10
+ return :pass if result.success?
11
11
 
12
- [:bad, result.stdout]
12
+ [:fail, result.stdout]
13
13
  end
14
14
  end
15
15
  end
@@ -3,22 +3,22 @@ module Overcommit::Hook::PreCommit
3
3
  class RailsSchemaUpToDate < Base
4
4
  def run # rubocop:disable CyclomaticComplexity
5
5
  if migration_files.any? && schema_files.none?
6
- return :bad, "It looks like you're adding a migration, but did not update the schema file"
6
+ return :fail, "It looks like you're adding a migration, but did not update the schema file"
7
7
  elsif migration_files.none? && schema_files.any?
8
- return :bad, "You're trying to change the schema without adding a migration file"
8
+ return :fail, "You're trying to change the schema without adding a migration file"
9
9
  elsif migration_files.any? && schema_files.any?
10
10
  latest_version = migration_files.map { |file| file[/\d+/] }.sort.last
11
11
  schema = schema_files.map { |file| File.read(file) }.join
12
12
  up_to_date = schema.include?(latest_version)
13
13
 
14
14
  unless up_to_date
15
- return :bad, "The latest migration version you're committing is " \
15
+ return :fail, "The latest migration version you're committing is " \
16
16
  "#{latest_version}, but your schema file " \
17
17
  "#{schema_files.join(' or ')} is on a different version."
18
18
  end
19
19
  end
20
20
 
21
- :good
21
+ :pass
22
22
  end
23
23
 
24
24
  private
@@ -7,7 +7,7 @@ module Overcommit::Hook::PreCommit
7
7
  end
8
8
 
9
9
  result = execute(%w[rubocop --format=emacs --force-exclusion] + applicable_files)
10
- return :good if result.success?
10
+ return :pass if result.success?
11
11
 
12
12
  output = result.stdout + result.stderr
13
13
 
@@ -20,7 +20,7 @@ module Overcommit::Hook::PreCommit
20
20
  modified_lines(file).include?(line.to_i)
21
21
  end
22
22
 
23
- return :bad, error_lines.join("\n") unless error_lines.empty?
23
+ return :fail, error_lines.join("\n") unless error_lines.empty?
24
24
 
25
25
  [:warn, "Modified files have lints (on lines you didn't modify)\n" <<
26
26
  warning_lines.join("\n")]
@@ -7,7 +7,7 @@ module Overcommit::Hook::PreCommit
7
7
  end
8
8
 
9
9
  result = execute(%w[scss-lint] + applicable_files)
10
- return :good if result.success?
10
+ return :pass if result.success?
11
11
 
12
12
  # Keep lines from the output for files that we actually modified
13
13
  error_lines, warning_lines = result.stdout.split("\n").partition do |output_line|
@@ -18,7 +18,7 @@ module Overcommit::Hook::PreCommit
18
18
  modified_lines(file).include?(line.to_i)
19
19
  end
20
20
 
21
- return :bad, error_lines.join("\n") unless error_lines.empty?
21
+ return :fail, error_lines.join("\n") unless error_lines.empty?
22
22
 
23
23
  [:warn, "Modified files have lints (on lines you didn't modify)\n" <<
24
24
  warning_lines.join("\n")]
@@ -4,10 +4,10 @@ module Overcommit::Hook::PreCommit
4
4
  def run
5
5
  result = execute(%w[grep -IHn \s$] + applicable_files)
6
6
  unless result.stdout.empty?
7
- return :bad, "Trailing whitespace detected:\n#{result.stdout}"
7
+ return :fail, "Trailing whitespace detected:\n#{result.stdout}"
8
8
  end
9
9
 
10
- :good
10
+ :pass
11
11
  end
12
12
  end
13
13
  end
@@ -7,9 +7,9 @@ module Overcommit::Hook::PreCommit
7
7
  end
8
8
 
9
9
  result = execute(%w[travis-lint] + applicable_files)
10
- return :good if result.success?
10
+ return :pass if result.success?
11
11
 
12
- [:bad, result.stdout.strip]
12
+ [:fail, result.stdout.strip]
13
13
  end
14
14
  end
15
15
  end
@@ -14,9 +14,9 @@ module Overcommit::Hook::PreCommit
14
14
  end
15
15
  end
16
16
 
17
- return :good if output.empty?
17
+ return :pass if output.empty?
18
18
 
19
- [:bad, output]
19
+ [:fail, output]
20
20
  end
21
21
  end
22
22
  end
@@ -16,10 +16,22 @@ module Overcommit::HookContext
16
16
  Overcommit::GitRepo.store_cherry_pick_state
17
17
 
18
18
  if !initial_commit? && any_changes?
19
+ @stash_attempted = true
20
+
21
+ result = Overcommit::Utils.execute(
22
+ %w[git stash save --keep-index --quiet] +
23
+ ["Overcommit: Stash of repo state before hook run at #{Time.now}"]
24
+ )
25
+
26
+ unless result.success?
27
+ # Failure to stash in this case is likely due to a configuration
28
+ # issue (e.g. author/email not set or GPG signing key incorrect)
29
+ raise Overcommit::Exceptions::HookSetupFailed,
30
+ "Unable to setup environment for #{hook_script_name} hook run:" \
31
+ "\n#{result.stderr}"
32
+ end
33
+
19
34
  @changes_stashed = true
20
- `git stash save --keep-index --quiet #{<<-MSG}`
21
- "Overcommit: Stash of repo state before hook run at #{Time.now}"
22
- MSG
23
35
  end
24
36
 
25
37
  # While running the hooks make it appear as if nothing changed
@@ -29,7 +41,7 @@ module Overcommit::HookContext
29
41
  # Restore unstaged changes and reset file modification times so it appears
30
42
  # as if nothing ever changed.
31
43
  def cleanup_environment
32
- unless initial_commit?
44
+ unless initial_commit? || (@stash_attempted && !@changes_stashed)
33
45
  `git reset --hard &> /dev/null` # Ensure working tree is clean before popping stash
34
46
  end
35
47
 
@@ -40,16 +40,16 @@ module Overcommit
40
40
  @hooks.each do |hook|
41
41
  hook_status = run_hook(hook)
42
42
 
43
- run_failed = true if hook_status == :bad
43
+ run_failed = true if [:bad, :fail].include?(hook_status)
44
44
 
45
- if hook_status == :interrupted
45
+ if hook_status == :interrupt
46
46
  # Stop running any more hooks and assume a bad result
47
47
  interrupted = true
48
48
  break
49
49
  end
50
50
  end
51
51
 
52
- @printer.end_run(interrupted, run_failed)
52
+ @printer.end_run(run_failed, interrupted)
53
53
 
54
54
  !(run_failed || interrupted)
55
55
  else
@@ -68,12 +68,12 @@ module Overcommit
68
68
  # Ctrl-C actually stops the current hook from being run, but doesn't
69
69
  # halt the entire process.
70
70
  InterruptHandler.disable!
71
- status, output = hook.run
71
+ status, output = hook.run_and_transform
72
72
  rescue => ex
73
- status = :bad
73
+ status = :fail
74
74
  output = "Hook raised unexpected error\n#{ex.message}"
75
75
  rescue Interrupt
76
- status = :interrupted
76
+ status = :interrupt
77
77
  output = 'Hook was interrupted by Ctrl-C; restoring repo state...'
78
78
  ensure
79
79
  InterruptHandler.enable!
@@ -33,6 +33,7 @@ module Overcommit
33
33
  ensure_hooks_directory
34
34
  install_master_hook
35
35
  install_hook_symlinks
36
+ install_starter_config
36
37
 
37
38
  log.success "Successfully installed hooks into #{@target}"
38
39
  end
@@ -51,6 +52,8 @@ module Overcommit
51
52
  unless FileUtils.compare_file(MASTER_HOOK, master_hook_install_path)
52
53
  install_master_hook
53
54
  install_hook_symlinks
55
+
56
+ log.success "Hooks updated to Overcommit version #{Overcommit::VERSION}"
54
57
  true
55
58
  end
56
59
  end
@@ -119,6 +122,13 @@ module Overcommit
119
122
  end
120
123
  end
121
124
 
125
+ def install_starter_config
126
+ repo_config_file = File.join(@target, OVERCOMMIT_CONFIG_FILE_NAME)
127
+
128
+ return if File.exist?(repo_config_file)
129
+ FileUtils.cp(File.join(OVERCOMMIT_HOME, 'config', 'starter.yml'), repo_config_file)
130
+ end
131
+
122
132
  def overcommit_symlink?(file)
123
133
  File.symlink?(file) && File.readlink(file) == 'overcommit-hook'
124
134
  rescue Errno::ENOENT
@@ -54,7 +54,7 @@ module Overcommit
54
54
  def end_hook(hook, status, output)
55
55
  # Want to print the header for quiet hooks only if the result wasn't good
56
56
  # so that the user knows what failed
57
- print_header(hook) if hook.quiet? && status != :good
57
+ print_header(hook) if hook.quiet? && ![:good, :pass].include?(status)
58
58
 
59
59
  print_result(hook, status, output)
60
60
  end
@@ -62,23 +62,40 @@ module Overcommit
62
62
  private
63
63
 
64
64
  def print_header(hook)
65
+ hook_name = "[#{hook.name}] "
65
66
  log.partial hook.description
66
- log.partial '.' * (70 - hook.description.length)
67
+ log.partial '.' * [70 - hook.description.length - hook_name.length, 0].max
68
+ log.partial hook_name
67
69
  end
68
70
 
69
- def print_result(hook, status, output)
71
+ def print_result(hook, status, output) # rubocop:disable CyclomaticComplexity, MethodLength
70
72
  case status
71
- when :good
73
+ when :pass
72
74
  log.success 'OK' unless hook.quiet?
75
+ when :good
76
+ log.success 'OK'
77
+ log.bold_error 'Hook returned a status of `:good`. This is deprecated ' \
78
+ 'in favor of `:pass` and will be removed in a future ' \
79
+ 'version of Overcommit'
73
80
  when :warn
74
81
  log.warning 'WARNING'
75
82
  print_report(output, :bold_warning)
76
83
  when :bad
77
84
  log.error 'FAILED'
85
+ log.bold_error 'Hook returned a status of `:bad`. This is deprecated ' \
86
+ 'in favor of `:fail` and will be removed in a future ' \
87
+ 'version of Overcommit'
78
88
  print_report(output, :bold_error)
79
- when :interrupted
89
+ when :fail
90
+ log.error 'FAILED'
91
+ print_report(output, :bold_error)
92
+ when :interrupt
80
93
  log.error 'INTERRUPTED'
81
94
  print_report(output, :bold_error)
95
+ else
96
+ log.error '???'
97
+ print_report("Hook returned unknown status `#{status.inspect}` -- ignoring.",
98
+ :bold_error)
82
99
  end
83
100
  end
84
101
 
@@ -1,4 +1,4 @@
1
1
  # Defines the gem version.
2
2
  module Overcommit
3
- VERSION = '0.14.1'
3
+ VERSION = '0.15.0'
4
4
  end
@@ -55,7 +55,7 @@ begin
55
55
  # Ensure master hook is up-to-date
56
56
  installer = Overcommit::Installer.new(logger)
57
57
  if installer.run(Overcommit::Utils.repo_root, :action => :update)
58
- exec $0 # Execute the updated hook
58
+ exec($0, *ARGV) # Execute the updated hook with all original arguments
59
59
  end
60
60
 
61
61
  config = Overcommit::ConfigurationLoader.load_repo_config
@@ -78,6 +78,9 @@ rescue Overcommit::Exceptions::HookContextLoadError => error
78
78
  puts error
79
79
  puts 'Are you running an old version of Overcommit?'
80
80
  exit 69 # EX_UNAVAILABLE
81
+ rescue Overcommit::Exceptions::HookSetupFailed => error
82
+ puts error
83
+ exit 74 # EX_IOERR
81
84
  rescue Overcommit::Exceptions::HookCancelled
82
85
  puts 'You cancelled the hook run'
83
86
  exit 1
@@ -55,7 +55,7 @@ begin
55
55
  # Ensure master hook is up-to-date
56
56
  installer = Overcommit::Installer.new(logger)
57
57
  if installer.run(Overcommit::Utils.repo_root, :action => :update)
58
- exec $0 # Execute the updated hook
58
+ exec($0, *ARGV) # Execute the updated hook with all original arguments
59
59
  end
60
60
 
61
61
  config = Overcommit::ConfigurationLoader.load_repo_config
@@ -78,6 +78,9 @@ rescue Overcommit::Exceptions::HookContextLoadError => error
78
78
  puts error
79
79
  puts 'Are you running an old version of Overcommit?'
80
80
  exit 69 # EX_UNAVAILABLE
81
+ rescue Overcommit::Exceptions::HookSetupFailed => error
82
+ puts error
83
+ exit 74 # EX_IOERR
81
84
  rescue Overcommit::Exceptions::HookCancelled
82
85
  puts 'You cancelled the hook run'
83
86
  exit 1
@@ -55,7 +55,7 @@ begin
55
55
  # Ensure master hook is up-to-date
56
56
  installer = Overcommit::Installer.new(logger)
57
57
  if installer.run(Overcommit::Utils.repo_root, :action => :update)
58
- exec $0 # Execute the updated hook
58
+ exec($0, *ARGV) # Execute the updated hook with all original arguments
59
59
  end
60
60
 
61
61
  config = Overcommit::ConfigurationLoader.load_repo_config
@@ -78,6 +78,9 @@ rescue Overcommit::Exceptions::HookContextLoadError => error
78
78
  puts error
79
79
  puts 'Are you running an old version of Overcommit?'
80
80
  exit 69 # EX_UNAVAILABLE
81
+ rescue Overcommit::Exceptions::HookSetupFailed => error
82
+ puts error
83
+ exit 74 # EX_IOERR
81
84
  rescue Overcommit::Exceptions::HookCancelled
82
85
  puts 'You cancelled the hook run'
83
86
  exit 1
@@ -55,7 +55,7 @@ begin
55
55
  # Ensure master hook is up-to-date
56
56
  installer = Overcommit::Installer.new(logger)
57
57
  if installer.run(Overcommit::Utils.repo_root, :action => :update)
58
- exec $0 # Execute the updated hook
58
+ exec($0, *ARGV) # Execute the updated hook with all original arguments
59
59
  end
60
60
 
61
61
  config = Overcommit::ConfigurationLoader.load_repo_config
@@ -78,6 +78,9 @@ rescue Overcommit::Exceptions::HookContextLoadError => error
78
78
  puts error
79
79
  puts 'Are you running an old version of Overcommit?'
80
80
  exit 69 # EX_UNAVAILABLE
81
+ rescue Overcommit::Exceptions::HookSetupFailed => error
82
+ puts error
83
+ exit 74 # EX_IOERR
81
84
  rescue Overcommit::Exceptions::HookCancelled
82
85
  puts 'You cancelled the hook run'
83
86
  exit 1
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: overcommit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.1
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Causes Engineering
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-15 00:00:00.000000000 Z
12
+ date: 2014-07-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: childprocess
@@ -31,14 +31,14 @@ dependencies:
31
31
  requirements:
32
32
  - - ~>
33
33
  - !ruby/object:Gem::Version
34
- version: 0.13.0
34
+ version: 0.14.0
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - ~>
40
40
  - !ruby/object:Gem::Version
41
- version: 0.13.0
41
+ version: 0.14.0
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: rspec
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -78,7 +78,7 @@ extra_rdoc_files: []
78
78
  files:
79
79
  - bin/overcommit
80
80
  - config/default.yml
81
- - config/templates.yml
81
+ - config/starter.yml
82
82
  - lib/overcommit.rb
83
83
  - lib/overcommit/version.rb
84
84
  - lib/overcommit/hook_context.rb
data/config/templates.yml DELETED
@@ -1,13 +0,0 @@
1
- ---
2
- default:
3
- excludes:
4
- commit_msg:
5
- - change_id
6
- - release_note
7
- pre_commit:
8
- - causes_email
9
- - image_optimization
10
- - restricted_paths
11
- - test_history
12
- all:
13
- excludes: