overcommit 0.73.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: 887ad3a2999ba4744c926ad05bc61e453901822b378645d1dfbc10d4be0a0648
4
- data.tar.gz: 66d06d2f6216a1e480c3e5ec053ea4fb967b6e8a80a7302d70a0cdd1a05207ef
3
+ metadata.gz: 429fa7e31530c84fe84b624201dfb77296f31fd34be4e1fb10a354b3dc4ce9ff
4
+ data.tar.gz: ab2319699f8e677cab7ed3dc24854e12a7b6cfe7a911b9bcab3b8c2a82bead10
5
5
  SHA512:
6
- metadata.gz: 189138eaa9cf531fa861c87014ec420e9580c1d11f1492243050c542c32a8762e1f5d58ac82bdf18fc7526d257f0bb428192d9f8b6901c2b38a8717f0fd30a8a
7
- data.tar.gz: 917260eb13fc2f85e828fbebdbd1f04c30c6acbaeb7e02b594452d35d8974dede978d8e882c41e35348e529e09d94e0ab54aa046087c9bbf80d62437eaf7e798
6
+ metadata.gz: 3d7967d9579fb937a29a851157f4d74d620fe7e4fc3841b63a33bff84809038a49326a1d148fbe57872b1e90e42558b04027901d0193968626d74e72230ba3f5
7
+ data.tar.gz: a21c06966bdf3817034b98f4d7f06a0810a522d9234534402fc3ec77abbf26d22278e25fc42741c88d9a693ef27d0fab8c7d029e6a979e596710d7cf1952abd6
@@ -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
@@ -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.73.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.73.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'