overcommit 0.74.0 → 0.76.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/config/default.yml +56 -0
- data/lib/overcommit/cli.rb +7 -1
- data/lib/overcommit/configuration.rb +27 -34
- data/lib/overcommit/configuration_loader.rb +2 -2
- data/lib/overcommit/configuration_validator.rb +17 -3
- data/lib/overcommit/exceptions.rb +3 -0
- data/lib/overcommit/gem_plugin.rb +165 -0
- data/lib/overcommit/git_config.rb +18 -0
- data/lib/overcommit/git_repo.rb +15 -4
- data/lib/overcommit/hook/base.rb +1 -1
- data/lib/overcommit/hook/commit_msg/spell_check.rb +5 -8
- data/lib/overcommit/hook/pre_commit/bundle_audit.rb +6 -1
- data/lib/overcommit/hook/pre_commit/line_endings.rb +1 -2
- data/lib/overcommit/hook/pre_commit/yaml_syntax.rb +1 -1
- data/lib/overcommit/hook/prepare_commit_msg/replace_branch.rb +52 -3
- data/lib/overcommit/hook_context/base.rb +4 -1
- data/lib/overcommit/hook_context/commit_msg.rb +10 -4
- data/lib/overcommit/hook_context/helpers/stash_unstaged_changes.rb +25 -3
- data/lib/overcommit/hook_loader/base.rb +43 -11
- data/lib/overcommit/hook_loader/built_in_hook_loader.rb +2 -1
- data/lib/overcommit/hook_loader/plugin_hook_loader.rb +61 -18
- data/lib/overcommit/hook_runner.rb +1 -1
- data/lib/overcommit/hook_signer.rb +9 -29
- data/lib/overcommit/signature.rb +71 -0
- data/lib/overcommit/subprocess.rb +2 -1
- data/lib/overcommit/utils/file_utils.rb +3 -54
- data/lib/overcommit/utils/messages_utils.rb +14 -0
- data/lib/overcommit/utils.rb +65 -4
- data/lib/overcommit/version.rb +1 -1
- data/lib/overcommit.rb +2 -0
- data/libexec/overcommit-parent-command.js +19 -0
- data/template-dir/hooks/commit-msg +1 -1
- data/template-dir/hooks/overcommit-hook +1 -1
- data/template-dir/hooks/post-checkout +1 -1
- data/template-dir/hooks/post-commit +1 -1
- data/template-dir/hooks/post-merge +1 -1
- data/template-dir/hooks/post-rewrite +1 -1
- data/template-dir/hooks/pre-commit +1 -1
- data/template-dir/hooks/pre-push +1 -1
- data/template-dir/hooks/pre-rebase +1 -1
- data/template-dir/hooks/prepare-commit-msg +1 -1
- metadata +4 -1
data/lib/overcommit/utils.rb
CHANGED
|
@@ -166,9 +166,7 @@ module Overcommit
|
|
|
166
166
|
return if Process.ppid.zero?
|
|
167
167
|
|
|
168
168
|
if OS.windows?
|
|
169
|
-
|
|
170
|
-
strip.
|
|
171
|
-
slice(/(?<=CommandLine=).+/)
|
|
169
|
+
windows_parent_command
|
|
172
170
|
elsif OS.cygwin?
|
|
173
171
|
# Cygwin's `ps` command behaves differently than the traditional
|
|
174
172
|
# Linux version, but a comparable `procps` is provided to compensate.
|
|
@@ -176,7 +174,7 @@ module Overcommit
|
|
|
176
174
|
else
|
|
177
175
|
`ps -ocommand= -p #{Process.ppid}`.chomp
|
|
178
176
|
end
|
|
179
|
-
rescue Errno::EPERM, Errno::ENOENT
|
|
177
|
+
rescue Errno::EPERM, Errno::ENOENT, ChildProcess::LaunchError
|
|
180
178
|
# Process information may not be available, such as inside sandboxed environments
|
|
181
179
|
nil
|
|
182
180
|
end
|
|
@@ -291,6 +289,69 @@ module Overcommit
|
|
|
291
289
|
|
|
292
290
|
private
|
|
293
291
|
|
|
292
|
+
def windows_parent_command
|
|
293
|
+
native_windows_parent_command
|
|
294
|
+
rescue LoadError, StandardError
|
|
295
|
+
# win32ole is optional and absent from newer Ruby distributions.
|
|
296
|
+
# Use Script Host when it is unavailable or the COM query is denied.
|
|
297
|
+
scripted_windows_parent_command
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
def scripted_windows_parent_command
|
|
301
|
+
begin
|
|
302
|
+
result = execute([
|
|
303
|
+
'cscript.exe', '//nologo', '//B', '//U',
|
|
304
|
+
File.expand_path('../../libexec/overcommit-parent-command.js', __dir__),
|
|
305
|
+
Process.ppid.to_s,
|
|
306
|
+
])
|
|
307
|
+
if result.success?
|
|
308
|
+
command = result.stdout.dup.force_encoding('UTF-16LE').encode('UTF-8').
|
|
309
|
+
delete_prefix("\uFEFF").strip
|
|
310
|
+
return command.empty? ? nil : command
|
|
311
|
+
end
|
|
312
|
+
rescue Errno::ENOENT, ChildProcess::LaunchError, EncodingError
|
|
313
|
+
# Preserve PowerShell when Script Host is disabled or unavailable.
|
|
314
|
+
end
|
|
315
|
+
powershell_windows_parent_command
|
|
316
|
+
end
|
|
317
|
+
|
|
318
|
+
def powershell_windows_parent_command
|
|
319
|
+
result = execute([
|
|
320
|
+
'powershell.exe', '-NoProfile', '-NonInteractive', '-Command',
|
|
321
|
+
<<~POWERSHELL,
|
|
322
|
+
$parentId = #{Process.ppid}
|
|
323
|
+
for ($level = 0; $level -lt 4; $level++) {
|
|
324
|
+
$process = Get-CimInstance Win32_Process -Filter "ProcessId = $parentId"
|
|
325
|
+
if (!$process) { break }
|
|
326
|
+
if ($process.Name -ine 'env.exe') { $process.CommandLine; break }
|
|
327
|
+
$parentId = $process.ParentProcessId
|
|
328
|
+
}
|
|
329
|
+
POWERSHELL
|
|
330
|
+
])
|
|
331
|
+
command = result.stdout.strip
|
|
332
|
+
command if result.success? && !command.empty?
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
# Avoid starting PowerShell for every query when Ruby provides COM support.
|
|
336
|
+
def native_windows_parent_command
|
|
337
|
+
require 'win32ole'
|
|
338
|
+
service = WIN32OLE.connect('winmgmts:root/cimv2')
|
|
339
|
+
parent_id = Process.ppid
|
|
340
|
+
# Git for Windows' /usr/bin/env launcher remains between Git and Ruby.
|
|
341
|
+
4.times do
|
|
342
|
+
processes = service.ExecQuery(
|
|
343
|
+
'SELECT Name, CommandLine, ParentProcessId FROM Win32_Process ' \
|
|
344
|
+
"WHERE ProcessId = #{parent_id}"
|
|
345
|
+
)
|
|
346
|
+
process = processes.to_enum.first
|
|
347
|
+
return unless process
|
|
348
|
+
return process.CommandLine unless process.Name.to_s.casecmp?('env.exe')
|
|
349
|
+
|
|
350
|
+
parent_id = process.ParentProcessId
|
|
351
|
+
end
|
|
352
|
+
nil
|
|
353
|
+
end
|
|
354
|
+
|
|
294
355
|
# Log debug output.
|
|
295
356
|
#
|
|
296
357
|
# This is necessary since some specs indirectly call utility functions but
|
data/lib/overcommit/version.rb
CHANGED
data/lib/overcommit.rb
CHANGED
|
@@ -15,6 +15,7 @@ require 'overcommit/hook_context'
|
|
|
15
15
|
require 'overcommit/git_config'
|
|
16
16
|
require 'overcommit/git_repo'
|
|
17
17
|
require 'overcommit/hook_signer'
|
|
18
|
+
require 'overcommit/gem_plugin'
|
|
18
19
|
require 'overcommit/hook_loader/base'
|
|
19
20
|
require 'overcommit/hook_loader/built_in_hook_loader'
|
|
20
21
|
require 'overcommit/hook_loader/plugin_hook_loader'
|
|
@@ -24,3 +25,4 @@ require 'overcommit/hook_runner'
|
|
|
24
25
|
require 'overcommit/installer'
|
|
25
26
|
require 'overcommit/logger'
|
|
26
27
|
require 'overcommit/version'
|
|
28
|
+
require 'overcommit/signature'
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Query WMI without PowerShell's startup overhead.
|
|
2
|
+
// cscript //U writes redirected output as UTF-16LE.
|
|
3
|
+
var pid = String(WScript.Arguments(0));
|
|
4
|
+
if (!/^\d+$/.test(pid)) WScript.Quit(2);
|
|
5
|
+
var service = GetObject('winmgmts:root/cimv2');
|
|
6
|
+
// Git for Windows keeps an env.exe launcher between Git and the Ruby hook.
|
|
7
|
+
for (var level = 0; level < 4; level++) {
|
|
8
|
+
var processes = service.ExecQuery(
|
|
9
|
+
'SELECT Name, CommandLine, ParentProcessId FROM Win32_Process WHERE ProcessId = ' + pid
|
|
10
|
+
);
|
|
11
|
+
var items = new Enumerator(processes);
|
|
12
|
+
if (items.atEnd()) break;
|
|
13
|
+
var process = items.item();
|
|
14
|
+
if (String(process.Name).toLowerCase() !== 'env.exe') {
|
|
15
|
+
if (process.CommandLine !== null) WScript.StdOut.WriteLine(process.CommandLine);
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
pid = String(process.ParentProcessId);
|
|
19
|
+
}
|
|
@@ -27,7 +27,7 @@ if hook_type == 'overcommit-hook'
|
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
# Check if Overcommit should invoke a Bundler context for loading gems
|
|
30
|
-
File.read('.overcommit.yml') =~ /gemfile: (?:false|['"]?(.*)['"]?)/
|
|
30
|
+
File.read('.overcommit.yml', encoding: 'UTF-8') =~ /gemfile: (?:false|['"]?(.*)['"]?)/
|
|
31
31
|
gemfile = Regexp.last_match(1)
|
|
32
32
|
|
|
33
33
|
if gemfile
|
|
@@ -27,7 +27,7 @@ if hook_type == 'overcommit-hook'
|
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
# Check if Overcommit should invoke a Bundler context for loading gems
|
|
30
|
-
File.read('.overcommit.yml') =~ /gemfile: (?:false|['"]?(.*)['"]?)/
|
|
30
|
+
File.read('.overcommit.yml', encoding: 'UTF-8') =~ /gemfile: (?:false|['"]?(.*)['"]?)/
|
|
31
31
|
gemfile = Regexp.last_match(1)
|
|
32
32
|
|
|
33
33
|
if gemfile
|
|
@@ -27,7 +27,7 @@ if hook_type == 'overcommit-hook'
|
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
# Check if Overcommit should invoke a Bundler context for loading gems
|
|
30
|
-
File.read('.overcommit.yml') =~ /gemfile: (?:false|['"]?(.*)['"]?)/
|
|
30
|
+
File.read('.overcommit.yml', encoding: 'UTF-8') =~ /gemfile: (?:false|['"]?(.*)['"]?)/
|
|
31
31
|
gemfile = Regexp.last_match(1)
|
|
32
32
|
|
|
33
33
|
if gemfile
|
|
@@ -27,7 +27,7 @@ if hook_type == 'overcommit-hook'
|
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
# Check if Overcommit should invoke a Bundler context for loading gems
|
|
30
|
-
File.read('.overcommit.yml') =~ /gemfile: (?:false|['"]?(.*)['"]?)/
|
|
30
|
+
File.read('.overcommit.yml', encoding: 'UTF-8') =~ /gemfile: (?:false|['"]?(.*)['"]?)/
|
|
31
31
|
gemfile = Regexp.last_match(1)
|
|
32
32
|
|
|
33
33
|
if gemfile
|
|
@@ -27,7 +27,7 @@ if hook_type == 'overcommit-hook'
|
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
# Check if Overcommit should invoke a Bundler context for loading gems
|
|
30
|
-
File.read('.overcommit.yml') =~ /gemfile: (?:false|['"]?(.*)['"]?)/
|
|
30
|
+
File.read('.overcommit.yml', encoding: 'UTF-8') =~ /gemfile: (?:false|['"]?(.*)['"]?)/
|
|
31
31
|
gemfile = Regexp.last_match(1)
|
|
32
32
|
|
|
33
33
|
if gemfile
|
|
@@ -27,7 +27,7 @@ if hook_type == 'overcommit-hook'
|
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
# Check if Overcommit should invoke a Bundler context for loading gems
|
|
30
|
-
File.read('.overcommit.yml') =~ /gemfile: (?:false|['"]?(.*)['"]?)/
|
|
30
|
+
File.read('.overcommit.yml', encoding: 'UTF-8') =~ /gemfile: (?:false|['"]?(.*)['"]?)/
|
|
31
31
|
gemfile = Regexp.last_match(1)
|
|
32
32
|
|
|
33
33
|
if gemfile
|
|
@@ -27,7 +27,7 @@ if hook_type == 'overcommit-hook'
|
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
# Check if Overcommit should invoke a Bundler context for loading gems
|
|
30
|
-
File.read('.overcommit.yml') =~ /gemfile: (?:false|['"]?(.*)['"]?)/
|
|
30
|
+
File.read('.overcommit.yml', encoding: 'UTF-8') =~ /gemfile: (?:false|['"]?(.*)['"]?)/
|
|
31
31
|
gemfile = Regexp.last_match(1)
|
|
32
32
|
|
|
33
33
|
if gemfile
|
data/template-dir/hooks/pre-push
CHANGED
|
@@ -27,7 +27,7 @@ if hook_type == 'overcommit-hook'
|
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
# Check if Overcommit should invoke a Bundler context for loading gems
|
|
30
|
-
File.read('.overcommit.yml') =~ /gemfile: (?:false|['"]?(.*)['"]?)/
|
|
30
|
+
File.read('.overcommit.yml', encoding: 'UTF-8') =~ /gemfile: (?:false|['"]?(.*)['"]?)/
|
|
31
31
|
gemfile = Regexp.last_match(1)
|
|
32
32
|
|
|
33
33
|
if gemfile
|
|
@@ -27,7 +27,7 @@ if hook_type == 'overcommit-hook'
|
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
# Check if Overcommit should invoke a Bundler context for loading gems
|
|
30
|
-
File.read('.overcommit.yml') =~ /gemfile: (?:false|['"]?(.*)['"]?)/
|
|
30
|
+
File.read('.overcommit.yml', encoding: 'UTF-8') =~ /gemfile: (?:false|['"]?(.*)['"]?)/
|
|
31
31
|
gemfile = Regexp.last_match(1)
|
|
32
32
|
|
|
33
33
|
if gemfile
|
|
@@ -27,7 +27,7 @@ if hook_type == 'overcommit-hook'
|
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
# Check if Overcommit should invoke a Bundler context for loading gems
|
|
30
|
-
File.read('.overcommit.yml') =~ /gemfile: (?:false|['"]?(.*)['"]?)/
|
|
30
|
+
File.read('.overcommit.yml', encoding: 'UTF-8') =~ /gemfile: (?:false|['"]?(.*)['"]?)/
|
|
31
31
|
gemfile = Regexp.last_match(1)
|
|
32
32
|
|
|
33
33
|
if gemfile
|
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.
|
|
4
|
+
version: 0.76.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Shane da Silva
|
|
@@ -76,6 +76,7 @@ files:
|
|
|
76
76
|
- lib/overcommit/configuration_validator.rb
|
|
77
77
|
- lib/overcommit/constants.rb
|
|
78
78
|
- lib/overcommit/exceptions.rb
|
|
79
|
+
- lib/overcommit/gem_plugin.rb
|
|
79
80
|
- lib/overcommit/git_config.rb
|
|
80
81
|
- lib/overcommit/git_repo.rb
|
|
81
82
|
- lib/overcommit/git_version.rb
|
|
@@ -288,6 +289,7 @@ files:
|
|
|
288
289
|
- lib/overcommit/message_processor.rb
|
|
289
290
|
- lib/overcommit/os.rb
|
|
290
291
|
- lib/overcommit/printer.rb
|
|
292
|
+
- lib/overcommit/signature.rb
|
|
291
293
|
- lib/overcommit/subprocess.rb
|
|
292
294
|
- lib/overcommit/utils.rb
|
|
293
295
|
- lib/overcommit/utils/file_utils.rb
|
|
@@ -295,6 +297,7 @@ files:
|
|
|
295
297
|
- lib/overcommit/version.rb
|
|
296
298
|
- libexec/gerrit-change-id
|
|
297
299
|
- libexec/index-tags
|
|
300
|
+
- libexec/overcommit-parent-command.js
|
|
298
301
|
- template-dir/hooks/commit-msg
|
|
299
302
|
- template-dir/hooks/overcommit-hook
|
|
300
303
|
- template-dir/hooks/post-checkout
|