overcommit 0.72.0 → 0.74.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 05ab1b76d85aa96c6aac3359e74970e7dc186f2ca6ad72ef63c9cef40a0565da
4
- data.tar.gz: 863bcdc512b59ddd25c6a03bf6b1f04a6337b00d74607476d0fa6cc1e09090f0
3
+ metadata.gz: 429fa7e31530c84fe84b624201dfb77296f31fd34be4e1fb10a354b3dc4ce9ff
4
+ data.tar.gz: ab2319699f8e677cab7ed3dc24854e12a7b6cfe7a911b9bcab3b8c2a82bead10
5
5
  SHA512:
6
- metadata.gz: 2f5f4eb08a01da2c757bf7c2b1d1add5416aa9b8d7f79e3ac897986d1711b8ee2d0669d1b73cd644eb4d484b468c88cb7e21a0f3973d0535c347b3a1df4728f0
7
- data.tar.gz: 7f17b6ae21fd95a05c31715c3d9d055f4ee6059f6a027ad144e1f4e128d6179fdc40c35666821287081be839c32be35109804065aa1e1074059690a38a029113
6
+ metadata.gz: 3d7967d9579fb937a29a851157f4d74d620fe7e4fc3841b63a33bff84809038a49326a1d148fbe57872b1e90e42558b04027901d0193968626d74e72230ba3f5
7
+ data.tar.gz: a21c06966bdf3817034b98f4d7f06a0810a522d9234534402fc3ec77abbf26d22278e25fc42741c88d9a693ef27d0fab8c7d029e6a979e596710d7cf1952abd6
data/config/default.yml CHANGED
@@ -413,6 +413,12 @@ PreCommit:
413
413
  - '**/Makefile'
414
414
  - '**/*.go'
415
415
 
416
+ HerbLint:
417
+ enabled: false
418
+ description: 'Analyze with herb-lint'
419
+ required_executable: 'herb-lint'
420
+ include: '**/*.html.erb'
421
+
416
422
  Hlint:
417
423
  enabled: false
418
424
  description: 'Analyze with hlint'
@@ -569,8 +575,42 @@ PreCommit:
569
575
  enabled: false
570
576
  description: 'Analyze with oxfmt'
571
577
  required_executable: 'oxfmt'
572
- flags: ['--check']
578
+ flags: ['--check', '--no-error-on-unmatched-pattern']
573
579
  install_command: 'npm install -g oxfmt'
580
+ include:
581
+ - '**/*.js'
582
+ - '**/*.jsx'
583
+ - '**/*.mjs'
584
+ - '**/*.cjs'
585
+ - '**/*.ts'
586
+ - '**/*.tsx'
587
+ - '**/*.mts'
588
+ - '**/*.cts'
589
+ - '**/*.json'
590
+ - '**/*.jsonc'
591
+ - '**/*.json5'
592
+ - '**/*.css'
593
+ - '**/*.scss'
594
+ - '**/*.less'
595
+ - '**/*.pcss'
596
+ - '**/*.postcss'
597
+ - '**/*.graphql'
598
+ - '**/*.gql'
599
+ - '**/*.graphqls'
600
+ - '**/*.toml'
601
+ - '**/*.yml'
602
+ - '**/*.yaml'
603
+ - '**/*.html'
604
+ - '**/*.htm'
605
+ - '**/*.xhtml'
606
+ - '**/*.vue'
607
+ - '**/*.svelte'
608
+ - '**/*.md'
609
+ - '**/*.markdown'
610
+ - '**/*.mdx'
611
+ - '**/*.hbs'
612
+ - '**/*.handlebars'
613
+ - '**/*.mjml'
574
614
 
575
615
  OxLint:
576
616
  enabled: false
@@ -578,6 +618,18 @@ PreCommit:
578
618
  required_executable: 'oxlint'
579
619
  flags: ['--format=unix']
580
620
  install_command: 'npm install -g oxlint'
621
+ include:
622
+ - '**/*.js'
623
+ - '**/*.jsx'
624
+ - '**/*.mjs'
625
+ - '**/*.cjs'
626
+ - '**/*.ts'
627
+ - '**/*.tsx'
628
+ - '**/*.mts'
629
+ - '**/*.cts'
630
+ - '**/*.vue'
631
+ - '**/*.svelte'
632
+ - '**/*.astro'
581
633
 
582
634
  Pep257: # Deprecated – use Pydocstyle instead.
583
635
  enabled: false
@@ -214,8 +214,9 @@ module Overcommit
214
214
  return false if ENV['OVERCOMMIT_NO_VERIFY']
215
215
  return true if @hash['verify_signatures'] != false
216
216
 
217
+ scope = Overcommit::GitConfig.signature_scope
217
218
  result = Overcommit::Utils.execute(
218
- %W[git config --local --get #{verify_signature_config_key}]
219
+ %W[git config #{scope} --get #{verify_signature_config_key}]
219
220
  )
220
221
 
221
222
  if result.status == 1 # Key doesn't exist
@@ -232,13 +233,14 @@ module Overcommit
232
233
 
233
234
  # Update the currently stored signature for this hook.
234
235
  def update_signature!
236
+ scope = Overcommit::GitConfig.signature_scope
235
237
  result = Overcommit::Utils.execute(
236
- %w[git config --local] + [signature_config_key, signature]
238
+ %W[git config #{scope}] + [signature_config_key, signature]
237
239
  )
238
240
 
239
241
  verify_signature_value = @hash['verify_signatures'] ? 1 : 0
240
242
  result &&= Overcommit::Utils.execute(
241
- %W[git config --local #{verify_signature_config_key} #{verify_signature_value}]
243
+ %W[git config #{scope} #{verify_signature_config_key} #{verify_signature_value}]
242
244
  )
243
245
 
244
246
  unless result.success?
@@ -325,8 +327,9 @@ module Overcommit
325
327
  #
326
328
  # @return [String]
327
329
  def stored_signature
330
+ scope = Overcommit::GitConfig.signature_scope
328
331
  result = Overcommit::Utils.execute(
329
- %w[git config --local --get] + [signature_config_key]
332
+ %W[git config #{scope} --get] + [signature_config_key]
330
333
  )
331
334
 
332
335
  if result.status == 1 # Key doesn't exist
@@ -19,5 +19,13 @@ module Overcommit
19
19
 
20
20
  File.expand_path(path, Dir.pwd)
21
21
  end
22
+
23
+ # Config file option for storing hook signatures: the per-worktree file
24
+ # when extensions.worktreeConfig is on, so worktrees with different
25
+ # configurations do not overwrite each other's signatures.
26
+ def signature_scope
27
+ enabled = `git config --bool --get extensions.worktreeConfig`.chomp
28
+ enabled == 'true' ? '--worktree' : '--local'
29
+ end
22
30
  end
23
31
  end
@@ -131,12 +131,14 @@ module Overcommit
131
131
  Overcommit::Utils.execute(%W[git ls-files #{path} --error-unmatch]).success?
132
132
  end
133
133
 
134
- # Returns the names of all files that are tracked by git.
134
+ # Returns the names of all files that are tracked by git, excluding files
135
+ # that have been deleted from the working tree.
135
136
  #
136
137
  # @return [Array<String>] list of absolute file paths
137
138
  def all_files
138
- `git ls-files`.
139
- split(/\n/).
139
+ deleted_files = `git ls-files --deleted`.split(/\n/)
140
+
141
+ (`git ls-files`.split(/\n/) - deleted_files).
140
142
  map { |relative_file| File.expand_path(relative_file) }.
141
143
  reject { |file| File.directory?(file) } # Exclude submodule directories
142
144
  end
@@ -4,6 +4,11 @@ module Overcommit::Hook::CommitMsg
4
4
  # Ensures the number of columns the subject and commit message lines occupy is
5
5
  # under the preferred limits.
6
6
  class TextWidth < Base
7
+ # A line consisting only of a URL (optionally as a Markdown-style link
8
+ # reference such as `[1]: https://...`) cannot be wrapped without breaking
9
+ # the link, so it is exempt from the body width limit.
10
+ URL_ONLY_LINE = %r{\A(\[[^\]]+\]:\s*)?[a-z][a-z0-9+.-]*://\S+\z}i.freeze
11
+
7
12
  def run
8
13
  return :pass if empty_message?
9
14
 
@@ -42,13 +47,17 @@ module Overcommit::Hook::CommitMsg
42
47
  max_body_width = config['max_body_width']
43
48
 
44
49
  lines[2..].each_with_index do |line, index|
45
- if line.chomp.size > max_body_width
46
- @errors << "Line #{index + 3} of commit message has > " \
47
- "#{max_body_width} characters"
48
- end
50
+ next if line.chomp.size <= max_body_width || url_only_line?(line)
51
+
52
+ @errors << "Line #{index + 3} of commit message has > " \
53
+ "#{max_body_width} characters"
49
54
  end
50
55
  end
51
56
 
57
+ def url_only_line?(line)
58
+ URL_ONLY_LINE.match?(line.strip)
59
+ end
60
+
52
61
  def special_prefix_length(subject)
53
62
  subject.match(/^(fixup|squash)! /) { |match| match[0].length } || 0
54
63
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Overcommit::Hook::PreCommit
4
+ # Runs `herb-lint` against any modified ERB files.
5
+ #
6
+ # @see https://herb-tools.dev/projects/linter
7
+ class HerbLint < Base
8
+ def run
9
+ result = execute(command + ['--json'], args: applicable_files)
10
+ return :pass if result.success?
11
+
12
+ json_output = JSON.parse(result.stdout)
13
+ json_output['offenses'].map do |offense|
14
+ severity = offense['severity'] == 'error' ? :error : :warning
15
+ filename = offense['filename']
16
+ line = offense['location']['start']['line']
17
+ message = offense['message']
18
+ code = offense['code']
19
+
20
+ Overcommit::Hook::Message.new(
21
+ severity, filename, line,
22
+ "#{filename}:#{line} #{code} #{message}"
23
+ )
24
+ end
25
+ end
26
+ end
27
+ end
@@ -12,7 +12,9 @@ module Overcommit::HookContext
12
12
  cmd = Overcommit::Utils.parent_command
13
13
  return unless cmd
14
14
 
15
- amend_pattern = 'commit(\s.*)?\s--amend(\s|$)'
15
+ # POSIX character class rather than `\s`, which macOS git's regex
16
+ # library does not support
17
+ amend_pattern = 'commit([[:space:]].*)?[[:space:]]--amend([[:space:]]|$)'
16
18
 
17
19
  # Since the ps command can return invalid byte sequences for commands
18
20
  # containing unicode characters, we replace the offending characters,
@@ -68,8 +68,9 @@ module Overcommit
68
68
 
69
69
  # Update the current stored signature for this hook.
70
70
  def update_signature!
71
+ scope = Overcommit::GitConfig.signature_scope
71
72
  result = Overcommit::Utils.execute(
72
- %w[git config --local] + [signature_config_key, signature]
73
+ %W[git config #{scope}] + [signature_config_key, signature]
73
74
  )
74
75
 
75
76
  unless result.success?
@@ -103,8 +104,9 @@ module Overcommit
103
104
  end
104
105
 
105
106
  def stored_signature
107
+ scope = Overcommit::GitConfig.signature_scope
106
108
  result = Overcommit::Utils.execute(
107
- %w[git config --local --get] + [signature_config_key]
109
+ %W[git config #{scope} --get] + [signature_config_key]
108
110
  )
109
111
 
110
112
  if result.status == 1 # Key doesn't exist
@@ -2,7 +2,6 @@
2
2
 
3
3
  require 'childprocess'
4
4
  require 'tempfile'
5
- require 'overcommit/os'
6
5
 
7
6
  module Overcommit
8
7
  # Manages execution of a child process, collecting the exit status and
@@ -28,8 +27,6 @@ module Overcommit
28
27
  # @option options [String] input string to pass via standard input stream
29
28
  # @return [Result]
30
29
  def spawn(args, options = {})
31
- args = win32_prepare_args(args) if OS.windows?
32
-
33
30
  process = ChildProcess.build(*args)
34
31
 
35
32
  out, err = assign_output_streams(process)
@@ -53,13 +50,16 @@ module Overcommit
53
50
  out.rewind
54
51
 
55
52
  Result.new(process.exit_code, out.read, err.read)
53
+ ensure
54
+ # Delete the output files now rather than leaving it to the garbage
55
+ # collector, which on Windows fails (and prints a backtrace) if a process
56
+ # left behind by the command still has them open.
57
+ [out, err].each { |stream| stream&.close! }
56
58
  end
57
59
 
58
60
  # Spawns a new process in the background using the given array of
59
61
  # arguments (the first element is the command).
60
62
  def spawn_detached(args)
61
- args = win32_prepare_args(args) if OS.windows?
62
-
63
63
  process = ChildProcess.build(*args)
64
64
  process.detach = true
65
65
 
@@ -70,20 +70,6 @@ module Overcommit
70
70
 
71
71
  private
72
72
 
73
- # Necessary to run commands in the cmd.exe context.
74
- # Args are joined to properly handle quotes and special characters.
75
- def win32_prepare_args(args)
76
- args = args.map do |arg|
77
- # Quote args that contain whitespace
78
- arg = "\"#{arg}\"" if arg =~ /\s/
79
-
80
- # Escape cmd.exe metacharacters
81
- arg.gsub(/[()%!^"<>&|]/, '^\0')
82
- end
83
-
84
- %w[cmd.exe /c] + [args.join(' ')]
85
- end
86
-
87
73
  # @param process [ChildProcess]
88
74
  # @return [Array<IO>]
89
75
  def assign_output_streams(process)
@@ -49,13 +49,13 @@ module Overcommit::Utils
49
49
 
50
50
  def win32_dir_cmd(file_name)
51
51
  Overcommit::Subprocess.spawn(
52
- %W[dir #{win32_fix_pathsep(file_name)}]
52
+ %W[cmd.exe /c dir #{win32_fix_pathsep(file_name)}]
53
53
  )
54
54
  end
55
55
 
56
56
  def win32_mklink_cmd(old_name, new_name)
57
57
  Overcommit::Subprocess.spawn(
58
- %W[mklink #{win32_fix_pathsep(new_name)} #{win32_fix_pathsep(old_name)}]
58
+ %W[cmd.exe /c mklink #{win32_fix_pathsep(new_name)} #{win32_fix_pathsep(old_name)}]
59
59
  )
60
60
  end
61
61
 
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  module Overcommit
5
- VERSION = '0.72.0'
5
+ VERSION = '0.74.0'
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.72.0
4
+ version: 0.74.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane da Silva
@@ -15,7 +15,7 @@ dependencies:
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: 0.6.3
18
+ version: 5.0.0
19
19
  - - "<"
20
20
  - !ruby/object:Gem::Version
21
21
  version: '6'
@@ -25,7 +25,7 @@ dependencies:
25
25
  requirements:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
- version: 0.6.3
28
+ version: 5.0.0
29
29
  - - "<"
30
30
  - !ruby/object:Gem::Version
31
31
  version: '6'
@@ -161,6 +161,7 @@ files:
161
161
  - lib/overcommit/hook/pre_commit/hadolint.rb
162
162
  - lib/overcommit/hook/pre_commit/haml_lint.rb
163
163
  - lib/overcommit/hook/pre_commit/hard_tabs.rb
164
+ - lib/overcommit/hook/pre_commit/herb_lint.rb
164
165
  - lib/overcommit/hook/pre_commit/hlint.rb
165
166
  - lib/overcommit/hook/pre_commit/html_hint.rb
166
167
  - lib/overcommit/hook/pre_commit/html_tidy.rb
@@ -325,7 +326,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
325
326
  - !ruby/object:Gem::Version
326
327
  version: '0'
327
328
  requirements: []
328
- rubygems_version: 3.6.9
329
+ rubygems_version: 4.0.10
329
330
  specification_version: 4
330
331
  summary: Git hook manager
331
332
  test_files: []