overcommit 0.43.0 → 0.44.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7d0cda7604db99089da1104e74e50dddb00119f6
4
- data.tar.gz: 97ac88f0a6772146b35cbc5e4cf93e1a16a6a024
2
+ SHA256:
3
+ metadata.gz: 757f60633c3904f1c63681afc14f3a3e7874f05ad3bef92af6c9d9351ea45d29
4
+ data.tar.gz: fb3126490d063d44c9c1e27fdd67a84de2bcb87359b3db619e50f6f2f634ab6d
5
5
  SHA512:
6
- metadata.gz: 92478e619197b1707b9646f809c8fa0bc102f6fb44106015f91e32e4707b6585518c0d41ede75ed17bee6dfb27aaf3c52cd64fafd9ea1e80180a67362d1a5503
7
- data.tar.gz: 7b9cdc771310e3b140f254d7bf7b0472f9e5b5587627584bf140f7fed2fcd72fbf8312da85138909f12677bbf904105850d8db89e3e10b11fdef7d6928e3a53f
6
+ metadata.gz: 839e44ead515bfb13c13fab2e0e4b0859a1fb691d67c7ddb958bdbb3533b4945731cda5bb81b5c90d2e345ff08e069760d4dcfb4c099cd5798a380f24cef126d
7
+ data.tar.gz: ffc50fa2e8b3aa5c8be0ae8e73745062f465c4379bb07fbd4f8166378a2237bb0c32a9ab3c7f2e66f6cdec02ae4ce6fa275f858ec31edf4c13f0ded6e15fb956
@@ -14,7 +14,7 @@ module Overcommit
14
14
  def hooks_path
15
15
  path = `git config --get core.hooksPath`.chomp
16
16
  return File.join(Overcommit::Utils.git_dir, 'hooks') if path.empty?
17
- File.absolute_path(path)
17
+ File.absolute_path(path, Dir.pwd)
18
18
  end
19
19
  end
20
20
  end
@@ -236,7 +236,7 @@ module Overcommit
236
236
  ref = options[:ref]
237
237
 
238
238
  modules = []
239
- IniParse.parse(`git show #{ref}:.gitmodules`).each do |section|
239
+ IniParse.parse(`git show #{ref}:.gitmodules 2> #{File::NULL}`).each do |section|
240
240
  # git < 1.8.5 does not update the .gitmodules file with submodule
241
241
  # changes, so when we are looking at the current state of the work tree,
242
242
  # we need to check if the submodule actually exists via another method,
@@ -1,4 +1,5 @@
1
1
  require 'forwardable'
2
+ require 'overcommit/utils/messages_utils'
2
3
 
3
4
  module Overcommit::Hook::PreCommit
4
5
  # Functionality common to all pre-commit hooks.
@@ -9,71 +10,8 @@ module Overcommit::Hook::PreCommit
9
10
 
10
11
  private
11
12
 
12
- # Extract file, line number, and type of message from an error/warning
13
- # messages in output.
14
- #
15
- # Assumes each element of `output` is a separate error/warning with all
16
- # information necessary to identify it.
17
- #
18
- # @param output_messages [Array<String>] unprocessed error/warning messages
19
- # @param regex [Regexp] regular expression defining `file`, `line` and
20
- # `type` capture groups used to extract file locations and error/warning
21
- # type from each line of output
22
- # @param type_categorizer [Proc] function executed against the `type`
23
- # capture group to convert it to a `:warning` or `:error` symbol. Assumes
24
- # `:error` if `nil`.
25
- # @raise [Overcommit::Exceptions::MessageProcessingError] line of output did
26
- # not match regex
27
- # @return [Array<Message>]
28
- def extract_messages(output_messages, regex, type_categorizer = nil)
29
- output_messages.map.with_index do |message, index|
30
- unless match = message.match(regex)
31
- raise Overcommit::Exceptions::MessageProcessingError,
32
- 'Unexpected output: unable to determine line number or type ' \
33
- "of error/warning for output:\n" \
34
- "#{output_messages[index..-1].join("\n")}"
35
- end
36
-
37
- file = extract_file(match, message)
38
- line = extract_line(match, message) if match.names.include?('line') && match[:line]
39
- type = extract_type(match, message, type_categorizer)
40
-
41
- Overcommit::Hook::Message.new(type, file, line, message)
42
- end
43
- end
44
-
45
- def extract_file(match, message)
46
- return unless match.names.include?('file')
47
-
48
- if match[:file].to_s.empty?
49
- raise Overcommit::Exceptions::MessageProcessingError,
50
- "Unexpected output: no file found in '#{message}'"
51
- end
52
-
53
- match[:file]
54
- end
55
-
56
- def extract_line(match, message)
57
- return unless match.names.include?('line')
58
- Integer(match[:line])
59
- rescue ArgumentError, TypeError
60
- raise Overcommit::Exceptions::MessageProcessingError,
61
- "Unexpected output: invalid line number found in '#{message}'"
62
- end
63
-
64
- def extract_type(match, message, type_categorizer)
65
- if type_categorizer
66
- type_match = match.names.include?('type') ? match[:type] : nil
67
- type = type_categorizer.call(type_match)
68
- unless Overcommit::Hook::MESSAGE_TYPES.include?(type)
69
- raise Overcommit::Exceptions::MessageProcessingError,
70
- "Invalid message type '#{type}' for '#{message}': must " \
71
- "be one of #{Overcommit::Hook::MESSAGE_TYPES.inspect}"
72
- end
73
- type
74
- else
75
- :error # Assume error since no categorizer was defined
76
- end
13
+ def extract_messages(*args)
14
+ Overcommit::Utils::MessagesUtils.extract_messages(*args)
77
15
  end
78
16
  end
79
17
  end
@@ -138,8 +138,8 @@ module Overcommit
138
138
  FileUtils.mv(hook_file, old_hooks_path)
139
139
  end
140
140
  end
141
- # Remove old-hooks directory if empty
142
- FileUtils.rmdir(old_hooks_path)
141
+ # Remove old-hooks directory if empty (i.e. no old hooks were preserved)
142
+ FileUtils.rmdir(old_hooks_path) if Dir.entries(old_hooks_path).size <= 2
143
143
  end
144
144
 
145
145
  def restore_old_hooks
@@ -43,38 +43,29 @@ module Overcommit
43
43
  def repo_root
44
44
  @repo_root ||=
45
45
  begin
46
- git_dir = Pathname.new(File.expand_path('.')).enum_for(:ascend).find do |path|
47
- File.exist?(File.join(path, '.git'))
46
+ result = execute(%w[git rev-parse --show-toplevel])
47
+ unless result.success?
48
+ raise Overcommit::Exceptions::InvalidGitRepo,
49
+ 'Unable to determine location of GIT_DIR. ' \
50
+ 'Not a recognizable Git repository!'
48
51
  end
49
-
50
- unless git_dir
51
- raise Overcommit::Exceptions::InvalidGitRepo, 'no .git directory found'
52
- end
53
-
54
- git_dir.to_s
52
+ result.stdout.chomp("\n")
55
53
  end
56
54
  end
57
55
 
58
56
  # Returns an absolute path to the .git directory for a repo.
59
57
  #
60
- # @param repo_dir [String] root directory of git repo
61
58
  # @return [String]
62
- def git_dir(repo_dir = repo_root)
59
+ def git_dir
63
60
  @git_dir ||=
64
61
  begin
65
- git_dir = File.expand_path('.git', repo_dir)
66
-
67
- # .git could also be a file that contains the location of the git directory
68
- unless File.directory?(git_dir)
69
- git_dir = File.read(git_dir)[/^gitdir: (.*)$/, 1]
70
-
71
- # Resolve relative paths
72
- unless git_dir.start_with?('/')
73
- git_dir = File.expand_path(git_dir, repo_dir)
74
- end
62
+ result = execute(%w[git rev-parse --git-common-dir])
63
+ unless result.success?
64
+ raise Overcommit::Exceptions::InvalidGitRepo,
65
+ 'Unable to determine location of GIT_DIR. ' \
66
+ 'Not a recognizable Git repository!'
75
67
  end
76
-
77
- git_dir
68
+ File.expand_path(result.stdout.chomp("\n"), Dir.pwd)
78
69
  end
79
70
  end
80
71
 
@@ -0,0 +1,75 @@
1
+ module Overcommit::Utils
2
+ # Utility to process messages
3
+ module MessagesUtils
4
+ class << self
5
+ # Extract file, line number, and type of message from an error/warning
6
+ # messages in output.
7
+ #
8
+ # Assumes each element of `output` is a separate error/warning with all
9
+ # information necessary to identify it.
10
+ #
11
+ # @param output_messages [Array<String>] unprocessed error/warning messages
12
+ # @param regex [Regexp] regular expression defining `file`, `line` and
13
+ # `type` capture groups used to extract file locations and error/warning
14
+ # type from each line of output
15
+ # @param type_categorizer [Proc] function executed against the `type`
16
+ # capture group to convert it to a `:warning` or `:error` symbol. Assumes
17
+ # `:error` if `nil`.
18
+ # @raise [Overcommit::Exceptions::MessageProcessingError] line of output did
19
+ # not match regex
20
+ # @return [Array<Message>]
21
+ def extract_messages(output_messages, regex, type_categorizer = nil)
22
+ output_messages.map.with_index do |message, index|
23
+ unless match = message.match(regex)
24
+ raise Overcommit::Exceptions::MessageProcessingError,
25
+ 'Unexpected output: unable to determine line number or type ' \
26
+ "of error/warning for output:\n" \
27
+ "#{output_messages[index..-1].join("\n")}"
28
+ end
29
+
30
+ file = extract_file(match, message)
31
+ line = extract_line(match, message) if match.names.include?('line') && match[:line]
32
+ type = extract_type(match, message, type_categorizer)
33
+
34
+ Overcommit::Hook::Message.new(type, file, line, message)
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def extract_file(match, message)
41
+ return unless match.names.include?('file')
42
+
43
+ if match[:file].to_s.empty?
44
+ raise Overcommit::Exceptions::MessageProcessingError,
45
+ "Unexpected output: no file found in '#{message}'"
46
+ end
47
+
48
+ match[:file]
49
+ end
50
+
51
+ def extract_line(match, message)
52
+ return unless match.names.include?('line')
53
+ Integer(match[:line])
54
+ rescue ArgumentError, TypeError
55
+ raise Overcommit::Exceptions::MessageProcessingError,
56
+ "Unexpected output: invalid line number found in '#{message}'"
57
+ end
58
+
59
+ def extract_type(match, message, type_categorizer)
60
+ if type_categorizer
61
+ type_match = match.names.include?('type') ? match[:type] : nil
62
+ type = type_categorizer.call(type_match)
63
+ unless Overcommit::Hook::MESSAGE_TYPES.include?(type)
64
+ raise Overcommit::Exceptions::MessageProcessingError,
65
+ "Invalid message type '#{type}' for '#{message}': must " \
66
+ "be one of #{Overcommit::Hook::MESSAGE_TYPES.inspect}"
67
+ end
68
+ type
69
+ else
70
+ :error # Assume error since no categorizer was defined
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  module Overcommit
5
- VERSION = '0.43.0'.freeze
5
+ VERSION = '0.44.0'.freeze
6
6
  end
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.43.0
4
+ version: 0.44.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brigade Engineering
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-02-12 00:00:00.000000000 Z
12
+ date: 2018-03-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: childprocess
@@ -242,6 +242,7 @@ files:
242
242
  - lib/overcommit/subprocess.rb
243
243
  - lib/overcommit/utils.rb
244
244
  - lib/overcommit/utils/file_utils.rb
245
+ - lib/overcommit/utils/messages_utils.rb
245
246
  - lib/overcommit/version.rb
246
247
  - libexec/gerrit-change-id
247
248
  - libexec/index-tags
@@ -275,7 +276,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
275
276
  version: '0'
276
277
  requirements: []
277
278
  rubyforge_project:
278
- rubygems_version: 2.5.1
279
+ rubygems_version: 2.7.5
279
280
  signing_key:
280
281
  specification_version: 4
281
282
  summary: Git hook manager