overcommit 0.64.1 → 0.66.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/overcommit/cli.rb +22 -1
- data/lib/overcommit/hook_context/base.rb +3 -1
- data/lib/overcommit/hook_context/diff.rb +37 -0
- data/lib/overcommit/hook_context.rb +2 -2
- data/lib/overcommit/version.rb +1 -1
- data/template-dir/hooks/commit-msg +2 -8
- data/template-dir/hooks/overcommit-hook +2 -8
- data/template-dir/hooks/post-checkout +2 -8
- data/template-dir/hooks/post-commit +2 -8
- data/template-dir/hooks/post-merge +2 -8
- data/template-dir/hooks/post-rewrite +2 -8
- data/template-dir/hooks/pre-commit +2 -8
- data/template-dir/hooks/pre-push +2 -8
- data/template-dir/hooks/pre-rebase +2 -8
- data/template-dir/hooks/prepare-commit-msg +2 -8
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4144beeaafe295f3b4e5ea046378b5027fb2bf661c1675ccbe8a479caa608de
|
4
|
+
data.tar.gz: 640349096a637cc94e04c0848bedda4b9c32c7e7a1bad0b68d2337b42cab3ebc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 865f9c330bccfb537d2eedbfd1d67e02b925950273d1965103a1234a3fb54368d6a34f4241d18569f7c4e0fe61153af29f8c8915588b8026e4d0e20702649d01
|
7
|
+
data.tar.gz: b45c66fc03f4911105a4a98c15bf5f42e54bf5466ea6f465f47104ce12a94117a6ba410c405a999371449c73688197e308a34dfdf427ae5ae0c6018020f72eac
|
data/lib/overcommit/cli.rb
CHANGED
@@ -9,6 +9,7 @@ module Overcommit
|
|
9
9
|
class CLI # rubocop:disable Metrics/ClassLength
|
10
10
|
def initialize(arguments, input, logger)
|
11
11
|
@arguments = arguments
|
12
|
+
@cli_options = {}
|
12
13
|
@input = input
|
13
14
|
@log = logger
|
14
15
|
@options = {}
|
@@ -28,6 +29,8 @@ module Overcommit
|
|
28
29
|
sign
|
29
30
|
when :run_all
|
30
31
|
run_all
|
32
|
+
when :diff
|
33
|
+
diff
|
31
34
|
end
|
32
35
|
rescue Overcommit::Exceptions::ConfigurationSignatureChanged => e
|
33
36
|
puts e
|
@@ -45,7 +48,7 @@ module Overcommit
|
|
45
48
|
@parser = create_option_parser
|
46
49
|
|
47
50
|
begin
|
48
|
-
@parser.parse!(@arguments)
|
51
|
+
@parser.parse!(@arguments, into: @cli_options)
|
49
52
|
|
50
53
|
# Default action is to install
|
51
54
|
@options[:action] ||= :install
|
@@ -98,6 +101,11 @@ module Overcommit
|
|
98
101
|
@options[:action] = :run_all
|
99
102
|
@options[:hook_to_run] = arg ? arg.to_s : 'run-all'
|
100
103
|
end
|
104
|
+
|
105
|
+
opts.on('--diff [ref]', 'Run pre_commit hooks against the diff between a given ref. Defaults to `main`.') do |arg| # rubocop:disable Layout/LineLength
|
106
|
+
@options[:action] = :diff
|
107
|
+
arg
|
108
|
+
end
|
101
109
|
end
|
102
110
|
|
103
111
|
def add_other_options(opts)
|
@@ -209,6 +217,19 @@ module Overcommit
|
|
209
217
|
halt(status ? 0 : 65)
|
210
218
|
end
|
211
219
|
|
220
|
+
def diff
|
221
|
+
empty_stdin = File.open(File::NULL) # pre-commit hooks don't take input
|
222
|
+
context = Overcommit::HookContext.create('diff', config, @arguments, empty_stdin, **@cli_options) # rubocop:disable Layout/LineLength
|
223
|
+
config.apply_environment!(context, ENV)
|
224
|
+
|
225
|
+
printer = Overcommit::Printer.new(config, log, context)
|
226
|
+
runner = Overcommit::HookRunner.new(config, log, context, printer)
|
227
|
+
|
228
|
+
status = runner.run
|
229
|
+
|
230
|
+
halt(status ? 0 : 65)
|
231
|
+
end
|
232
|
+
|
212
233
|
# Used for ease of stubbing in tests
|
213
234
|
def halt(status = 0)
|
214
235
|
exit status
|
@@ -18,10 +18,12 @@ module Overcommit::HookContext
|
|
18
18
|
# @param config [Overcommit::Configuration]
|
19
19
|
# @param args [Array<String>]
|
20
20
|
# @param input [IO] standard input stream
|
21
|
-
|
21
|
+
# @param options [Hash] cli options
|
22
|
+
def initialize(config, args, input, **options)
|
22
23
|
@config = config
|
23
24
|
@args = args
|
24
25
|
@input = input
|
26
|
+
@options = options
|
25
27
|
end
|
26
28
|
|
27
29
|
# Executes a command as if it were a regular git hook, passing all
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'overcommit/git_repo'
|
4
|
+
|
5
|
+
module Overcommit::HookContext
|
6
|
+
# Simulates a pre-commit context based on the diff with another git ref.
|
7
|
+
#
|
8
|
+
# This results in pre-commit hooks running against the changes between the current
|
9
|
+
# and another ref, which is useful for automated CI scripts.
|
10
|
+
class Diff < Base
|
11
|
+
def modified_files
|
12
|
+
@modified_files ||= Overcommit::GitRepo.modified_files(refs: @options[:diff])
|
13
|
+
end
|
14
|
+
|
15
|
+
def modified_lines_in_file(file)
|
16
|
+
@modified_lines ||= {}
|
17
|
+
@modified_lines[file] ||= Overcommit::GitRepo.extract_modified_lines(file,
|
18
|
+
refs: @options[:diff])
|
19
|
+
end
|
20
|
+
|
21
|
+
def hook_class_name
|
22
|
+
'PreCommit'
|
23
|
+
end
|
24
|
+
|
25
|
+
def hook_type_name
|
26
|
+
'pre_commit'
|
27
|
+
end
|
28
|
+
|
29
|
+
def hook_script_name
|
30
|
+
'pre-commit'
|
31
|
+
end
|
32
|
+
|
33
|
+
def initial_commit?
|
34
|
+
@initial_commit ||= Overcommit::GitRepo.initial_commit?
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -2,13 +2,13 @@
|
|
2
2
|
|
3
3
|
# Utility module which manages the creation of {HookContext}s.
|
4
4
|
module Overcommit::HookContext
|
5
|
-
def self.create(hook_type, config, args, input)
|
5
|
+
def self.create(hook_type, config, args, input, **cli_options)
|
6
6
|
hook_type_class = Overcommit::Utils.camel_case(hook_type)
|
7
7
|
underscored_hook_type = Overcommit::Utils.snake_case(hook_type)
|
8
8
|
|
9
9
|
require "overcommit/hook_context/#{underscored_hook_type}"
|
10
10
|
|
11
|
-
Overcommit::HookContext.const_get(hook_type_class).new(config, args, input)
|
11
|
+
Overcommit::HookContext.const_get(hook_type_class).new(config, args, input, **cli_options)
|
12
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.
|
data/lib/overcommit/version.rb
CHANGED
@@ -27,14 +27,8 @@ if hook_type == 'overcommit-hook'
|
|
27
27
|
end
|
28
28
|
|
29
29
|
# Check if Overcommit should invoke a Bundler context for loading gems
|
30
|
-
|
31
|
-
|
32
|
-
gemfile =
|
33
|
-
begin
|
34
|
-
YAML.load_file('.overcommit.yml', aliases: true)['gemfile']
|
35
|
-
rescue ArgumentError
|
36
|
-
YAML.load_file('.overcommit.yml')['gemfile']
|
37
|
-
end rescue nil
|
30
|
+
config = File.read('.overcommit.yml') =~ /gemfile: ['"]?(.*)['"]?/
|
31
|
+
gemfile = Regexp.last_match(1)
|
38
32
|
|
39
33
|
if gemfile
|
40
34
|
ENV['BUNDLE_GEMFILE'] = gemfile
|
@@ -27,14 +27,8 @@ if hook_type == 'overcommit-hook'
|
|
27
27
|
end
|
28
28
|
|
29
29
|
# Check if Overcommit should invoke a Bundler context for loading gems
|
30
|
-
|
31
|
-
|
32
|
-
gemfile =
|
33
|
-
begin
|
34
|
-
YAML.load_file('.overcommit.yml', aliases: true)['gemfile']
|
35
|
-
rescue ArgumentError
|
36
|
-
YAML.load_file('.overcommit.yml')['gemfile']
|
37
|
-
end rescue nil
|
30
|
+
config = File.read('.overcommit.yml') =~ /gemfile: ['"]?(.*)['"]?/
|
31
|
+
gemfile = Regexp.last_match(1)
|
38
32
|
|
39
33
|
if gemfile
|
40
34
|
ENV['BUNDLE_GEMFILE'] = gemfile
|
@@ -27,14 +27,8 @@ if hook_type == 'overcommit-hook'
|
|
27
27
|
end
|
28
28
|
|
29
29
|
# Check if Overcommit should invoke a Bundler context for loading gems
|
30
|
-
|
31
|
-
|
32
|
-
gemfile =
|
33
|
-
begin
|
34
|
-
YAML.load_file('.overcommit.yml', aliases: true)['gemfile']
|
35
|
-
rescue ArgumentError
|
36
|
-
YAML.load_file('.overcommit.yml')['gemfile']
|
37
|
-
end rescue nil
|
30
|
+
config = File.read('.overcommit.yml') =~ /gemfile: ['"]?(.*)['"]?/
|
31
|
+
gemfile = Regexp.last_match(1)
|
38
32
|
|
39
33
|
if gemfile
|
40
34
|
ENV['BUNDLE_GEMFILE'] = gemfile
|
@@ -27,14 +27,8 @@ if hook_type == 'overcommit-hook'
|
|
27
27
|
end
|
28
28
|
|
29
29
|
# Check if Overcommit should invoke a Bundler context for loading gems
|
30
|
-
|
31
|
-
|
32
|
-
gemfile =
|
33
|
-
begin
|
34
|
-
YAML.load_file('.overcommit.yml', aliases: true)['gemfile']
|
35
|
-
rescue ArgumentError
|
36
|
-
YAML.load_file('.overcommit.yml')['gemfile']
|
37
|
-
end rescue nil
|
30
|
+
config = File.read('.overcommit.yml') =~ /gemfile: ['"]?(.*)['"]?/
|
31
|
+
gemfile = Regexp.last_match(1)
|
38
32
|
|
39
33
|
if gemfile
|
40
34
|
ENV['BUNDLE_GEMFILE'] = gemfile
|
@@ -27,14 +27,8 @@ if hook_type == 'overcommit-hook'
|
|
27
27
|
end
|
28
28
|
|
29
29
|
# Check if Overcommit should invoke a Bundler context for loading gems
|
30
|
-
|
31
|
-
|
32
|
-
gemfile =
|
33
|
-
begin
|
34
|
-
YAML.load_file('.overcommit.yml', aliases: true)['gemfile']
|
35
|
-
rescue ArgumentError
|
36
|
-
YAML.load_file('.overcommit.yml')['gemfile']
|
37
|
-
end rescue nil
|
30
|
+
config = File.read('.overcommit.yml') =~ /gemfile: ['"]?(.*)['"]?/
|
31
|
+
gemfile = Regexp.last_match(1)
|
38
32
|
|
39
33
|
if gemfile
|
40
34
|
ENV['BUNDLE_GEMFILE'] = gemfile
|
@@ -27,14 +27,8 @@ if hook_type == 'overcommit-hook'
|
|
27
27
|
end
|
28
28
|
|
29
29
|
# Check if Overcommit should invoke a Bundler context for loading gems
|
30
|
-
|
31
|
-
|
32
|
-
gemfile =
|
33
|
-
begin
|
34
|
-
YAML.load_file('.overcommit.yml', aliases: true)['gemfile']
|
35
|
-
rescue ArgumentError
|
36
|
-
YAML.load_file('.overcommit.yml')['gemfile']
|
37
|
-
end rescue nil
|
30
|
+
config = File.read('.overcommit.yml') =~ /gemfile: ['"]?(.*)['"]?/
|
31
|
+
gemfile = Regexp.last_match(1)
|
38
32
|
|
39
33
|
if gemfile
|
40
34
|
ENV['BUNDLE_GEMFILE'] = gemfile
|
@@ -27,14 +27,8 @@ if hook_type == 'overcommit-hook'
|
|
27
27
|
end
|
28
28
|
|
29
29
|
# Check if Overcommit should invoke a Bundler context for loading gems
|
30
|
-
|
31
|
-
|
32
|
-
gemfile =
|
33
|
-
begin
|
34
|
-
YAML.load_file('.overcommit.yml', aliases: true)['gemfile']
|
35
|
-
rescue ArgumentError
|
36
|
-
YAML.load_file('.overcommit.yml')['gemfile']
|
37
|
-
end rescue nil
|
30
|
+
config = File.read('.overcommit.yml') =~ /gemfile: ['"]?(.*)['"]?/
|
31
|
+
gemfile = Regexp.last_match(1)
|
38
32
|
|
39
33
|
if gemfile
|
40
34
|
ENV['BUNDLE_GEMFILE'] = gemfile
|
data/template-dir/hooks/pre-push
CHANGED
@@ -27,14 +27,8 @@ if hook_type == 'overcommit-hook'
|
|
27
27
|
end
|
28
28
|
|
29
29
|
# Check if Overcommit should invoke a Bundler context for loading gems
|
30
|
-
|
31
|
-
|
32
|
-
gemfile =
|
33
|
-
begin
|
34
|
-
YAML.load_file('.overcommit.yml', aliases: true)['gemfile']
|
35
|
-
rescue ArgumentError
|
36
|
-
YAML.load_file('.overcommit.yml')['gemfile']
|
37
|
-
end rescue nil
|
30
|
+
config = File.read('.overcommit.yml') =~ /gemfile: ['"]?(.*)['"]?/
|
31
|
+
gemfile = Regexp.last_match(1)
|
38
32
|
|
39
33
|
if gemfile
|
40
34
|
ENV['BUNDLE_GEMFILE'] = gemfile
|
@@ -27,14 +27,8 @@ if hook_type == 'overcommit-hook'
|
|
27
27
|
end
|
28
28
|
|
29
29
|
# Check if Overcommit should invoke a Bundler context for loading gems
|
30
|
-
|
31
|
-
|
32
|
-
gemfile =
|
33
|
-
begin
|
34
|
-
YAML.load_file('.overcommit.yml', aliases: true)['gemfile']
|
35
|
-
rescue ArgumentError
|
36
|
-
YAML.load_file('.overcommit.yml')['gemfile']
|
37
|
-
end rescue nil
|
30
|
+
config = File.read('.overcommit.yml') =~ /gemfile: ['"]?(.*)['"]?/
|
31
|
+
gemfile = Regexp.last_match(1)
|
38
32
|
|
39
33
|
if gemfile
|
40
34
|
ENV['BUNDLE_GEMFILE'] = gemfile
|
@@ -27,14 +27,8 @@ if hook_type == 'overcommit-hook'
|
|
27
27
|
end
|
28
28
|
|
29
29
|
# Check if Overcommit should invoke a Bundler context for loading gems
|
30
|
-
|
31
|
-
|
32
|
-
gemfile =
|
33
|
-
begin
|
34
|
-
YAML.load_file('.overcommit.yml', aliases: true)['gemfile']
|
35
|
-
rescue ArgumentError
|
36
|
-
YAML.load_file('.overcommit.yml')['gemfile']
|
37
|
-
end rescue nil
|
30
|
+
config = File.read('.overcommit.yml') =~ /gemfile: ['"]?(.*)['"]?/
|
31
|
+
gemfile = Regexp.last_match(1)
|
38
32
|
|
39
33
|
if gemfile
|
40
34
|
ENV['BUNDLE_GEMFILE'] = gemfile
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: overcommit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.66.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shane da Silva
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-01-30 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: childprocess
|
@@ -262,6 +261,7 @@ files:
|
|
262
261
|
- lib/overcommit/hook_context.rb
|
263
262
|
- lib/overcommit/hook_context/base.rb
|
264
263
|
- lib/overcommit/hook_context/commit_msg.rb
|
264
|
+
- lib/overcommit/hook_context/diff.rb
|
265
265
|
- lib/overcommit/hook_context/helpers/file_modifications.rb
|
266
266
|
- lib/overcommit/hook_context/helpers/stash_unstaged_changes.rb
|
267
267
|
- lib/overcommit/hook_context/post_checkout.rb
|
@@ -322,8 +322,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
322
322
|
- !ruby/object:Gem::Version
|
323
323
|
version: '0'
|
324
324
|
requirements: []
|
325
|
-
rubygems_version: 3.
|
326
|
-
signing_key:
|
325
|
+
rubygems_version: 3.6.2
|
327
326
|
specification_version: 4
|
328
327
|
summary: Git hook manager
|
329
328
|
test_files: []
|