overcommit 0.63.0 → 0.67.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e9a2e23f1b830d2d9e8e500024cd01a1d368678b1f24039367ae88c90dc154a
4
- data.tar.gz: 9c3fada758490c58d2341125315a988fe73fb9d4dc31c5167a400eddbff28846
3
+ metadata.gz: e81508d0f9854d0ad04bb88a192e479efd14d2dcb72520656e96ffbd42d2a10c
4
+ data.tar.gz: 58cf91765bfd9b4fc13f287f7d8d0fc5de9abdd5f4306e8c06a6e98b49df005e
5
5
  SHA512:
6
- metadata.gz: 2773a91d43bf69aa97c9f65fab59934502c2b948ad5264a7dd0def628d6d9bb21b78ebfd868b3a5e0c9457f609ede41fa11fdd1e92708dc27bb87fc433361b91
7
- data.tar.gz: 79e8e222951cbaea5875fbd2bab3268d47ead4dde32fad029e76b46bd4823546d8beee1473b42df1575879c64a7ae7bdc7e8da2e970f4ec6766b5b85163409dc
6
+ metadata.gz: 87650f7f66f4f2d1b652154f44a853aa6486e57befbc91c520f05ac28cce74ca291a7cb5681efcde73436f3bbc7bc7fa0c6eceb9fc8f4abeea44de94c54cd7f0
7
+ data.tar.gz: e9872666ee60dc587668c17331e476d3287e22a2b2ca3ddf656f9bf863d1c315f208458c2c5c21c0e0d7ae779e1cbd7357ebe5fd361be1812799b7018095257a
data/config/default.yml CHANGED
@@ -32,6 +32,10 @@
32
32
  # your repository, and then set the `gemfile` option below to the name you gave
33
33
  # the file.
34
34
  # (Generate lock file by running `bundle install --gemfile=.overcommit_gems.rb`)
35
+ #
36
+ # NOTE: the following line will be parsed by a regexp rather than a proper YAML
37
+ # parser, so avoid any values other than false or a string, and don't use inline
38
+ # comments
35
39
  gemfile: false
36
40
 
37
41
  # Where to store hook plugins specific to a repository. These are loaded in
@@ -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
@@ -17,7 +17,7 @@ module Overcommit
17
17
  path = `git config --get core.hooksPath`.chomp
18
18
  return File.join(Overcommit::Utils.git_dir, 'hooks') if path.empty?
19
19
 
20
- File.absolute_path(path, Dir.pwd)
20
+ File.expand_path(path, Dir.pwd)
21
21
  end
22
22
  end
23
23
  end
@@ -12,7 +12,7 @@ module Overcommit::Hook::PreCommit
12
12
 
13
13
  def run
14
14
  result = execute(command, args: applicable_files)
15
- output = result.stdout.chomp
15
+ output = result.stdout + result.stderr.chomp
16
16
  return :pass if result.success? && output.empty?
17
17
 
18
18
  extract_messages(
@@ -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
- def initialize(config, args, input)
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,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'overcommit/git_repo'
4
+
5
+ require 'set'
6
+
7
+ module Overcommit::HookContext
8
+ # Simulates a pre-commit context based on the diff with another git ref.
9
+ #
10
+ # This results in pre-commit hooks running against the changes between the current
11
+ # and another ref, which is useful for automated CI scripts.
12
+ class Diff < Base
13
+ def modified_files
14
+ @modified_files ||= Overcommit::GitRepo.modified_files(refs: @options[:diff])
15
+ end
16
+
17
+ def modified_lines_in_file(file)
18
+ @modified_lines ||= {}
19
+ @modified_lines[file] ||= Overcommit::GitRepo.extract_modified_lines(file,
20
+ refs: @options[:diff])
21
+ end
22
+
23
+ def hook_class_name
24
+ 'PreCommit'
25
+ end
26
+
27
+ def hook_type_name
28
+ 'pre_commit'
29
+ end
30
+
31
+ def hook_script_name
32
+ 'pre-commit'
33
+ end
34
+
35
+ def initial_commit?
36
+ @initial_commit ||= Overcommit::GitRepo.initial_commit?
37
+ end
38
+ end
39
+ 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.
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  module Overcommit
5
- VERSION = '0.63.0'
5
+ VERSION = '0.67.1'
6
6
  end
@@ -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
- require 'yaml'
31
- # rubocop:disable Style/RescueModifier
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
+ File.read('.overcommit.yml') =~ /gemfile: (?:false|['"]?(.*)['"]?)/
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
- require 'yaml'
31
- # rubocop:disable Style/RescueModifier
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
+ File.read('.overcommit.yml') =~ /gemfile: (?:false|['"]?(.*)['"]?)/
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
- require 'yaml'
31
- # rubocop:disable Style/RescueModifier
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
+ File.read('.overcommit.yml') =~ /gemfile: (?:false|['"]?(.*)['"]?)/
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
- require 'yaml'
31
- # rubocop:disable Style/RescueModifier
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
+ File.read('.overcommit.yml') =~ /gemfile: (?:false|['"]?(.*)['"]?)/
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
- require 'yaml'
31
- # rubocop:disable Style/RescueModifier
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
+ File.read('.overcommit.yml') =~ /gemfile: (?:false|['"]?(.*)['"]?)/
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
- require 'yaml'
31
- # rubocop:disable Style/RescueModifier
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
+ File.read('.overcommit.yml') =~ /gemfile: (?:false|['"]?(.*)['"]?)/
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
- require 'yaml'
31
- # rubocop:disable Style/RescueModifier
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
+ File.read('.overcommit.yml') =~ /gemfile: (?:false|['"]?(.*)['"]?)/
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
- require 'yaml'
31
- # rubocop:disable Style/RescueModifier
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
+ File.read('.overcommit.yml') =~ /gemfile: (?:false|['"]?(.*)['"]?)/
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
- require 'yaml'
31
- # rubocop:disable Style/RescueModifier
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
+ File.read('.overcommit.yml') =~ /gemfile: (?:false|['"]?(.*)['"]?)/
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
- require 'yaml'
31
- # rubocop:disable Style/RescueModifier
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
+ File.read('.overcommit.yml') =~ /gemfile: (?:false|['"]?(.*)['"]?)/
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.63.0
4
+ version: 0.67.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane da Silva
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-02-25 00:00:00.000000000 Z
10
+ date: 2025-03-03 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: childprocess
@@ -48,16 +47,16 @@ dependencies:
48
47
  name: rexml
49
48
  requirement: !ruby/object:Gem::Requirement
50
49
  requirements:
51
- - - "~>"
50
+ - - ">="
52
51
  - !ruby/object:Gem::Version
53
- version: '3.2'
52
+ version: 3.3.9
54
53
  type: :runtime
55
54
  prerelease: false
56
55
  version_requirements: !ruby/object:Gem::Requirement
57
56
  requirements:
58
- - - "~>"
57
+ - - ">="
59
58
  - !ruby/object:Gem::Version
60
- version: '3.2'
59
+ version: 3.3.9
61
60
  description: Utility to install, configure, and extend Git hooks
62
61
  email:
63
62
  - shane@dasilva.io
@@ -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
@@ -304,7 +304,8 @@ files:
304
304
  homepage: https://github.com/sds/overcommit
305
305
  licenses:
306
306
  - MIT
307
- metadata: {}
307
+ metadata:
308
+ changelog_uri: https://github.com/sds/overcommit/blob/main/CHANGELOG.md
308
309
  post_install_message: Install hooks by running `overcommit --install` in your Git
309
310
  repository
310
311
  rdoc_options: []
@@ -321,8 +322,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
321
322
  - !ruby/object:Gem::Version
322
323
  version: '0'
323
324
  requirements: []
324
- rubygems_version: 3.4.10
325
- signing_key:
325
+ rubygems_version: 3.6.2
326
326
  specification_version: 4
327
327
  summary: Git hook manager
328
328
  test_files: []