overcommit 0.73.0 → 0.75.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: 825a9ffd0ad7bacf35ecb3901ead1f1249085cad5536314434e89ce5ff802d15
4
+ data.tar.gz: f4d3ea4ecbc7d2fe7d2c35e1dd4d44f86e30a2e31ba241366735937952a95c30
5
5
  SHA512:
6
- metadata.gz: 189138eaa9cf531fa861c87014ec420e9580c1d11f1492243050c542c32a8762e1f5d58ac82bdf18fc7526d257f0bb428192d9f8b6901c2b38a8717f0fd30a8a
7
- data.tar.gz: 917260eb13fc2f85e828fbebdbd1f04c30c6acbaeb7e02b594452d35d8974dede978d8e882c41e35348e529e09d94e0ab54aa046087c9bbf80d62437eaf7e798
6
+ metadata.gz: 590bcf4bdb5bb506425bbc41050adaa16311baa45f37071d1ffc0a9d96412f508f552eeea2278946bbab622af3aa0a6d216d388c520e41804a4f4dc7ee69e381
7
+ data.tar.gz: 73222064a9fcc44930ae9c027c19bb851004d5d1000303854b52c2650ef52ef29177f783e9faa5e064717be3ea03e676512a1dd631ddf68f459acbeb46e08df4
@@ -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
@@ -161,10 +163,10 @@ module Overcommit
161
163
  end
162
164
 
163
165
  merge_mode_file = Overcommit::Utils.git_path('MERGE_MODE')
164
- @merge_mode = File.open(merge_mode_file).read if File.exist?(merge_mode_file)
166
+ @merge_mode = File.read(merge_mode_file) if File.exist?(merge_mode_file)
165
167
 
166
168
  merge_msg_file = Overcommit::Utils.git_path('MERGE_MSG')
167
- @merge_msg = File.open(merge_msg_file).read if File.exist?(merge_msg_file)
169
+ @merge_msg = File.read(merge_msg_file) if File.exist?(merge_msg_file)
168
170
  end
169
171
 
170
172
  # Store any relevant files that are present when repo is in the middle of a
@@ -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)
@@ -1,70 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'overcommit/os'
4
- require 'overcommit/subprocess'
5
-
6
3
  module Overcommit::Utils
7
4
  # Utility functions for file IO.
8
5
  module FileUtils
9
6
  class << self
10
- # When the host OS is Windows, uses the `mklink` command to create an
11
- # NTFS symbolic link from `new_name` to `old_name`. Otherwise delegates
12
- # to `File.symlink`
13
7
  def symlink(old_name, new_name)
14
- return File.symlink(old_name, new_name) unless Overcommit::OS.windows?
15
-
16
- result = win32_mklink_cmd(old_name, new_name)
17
- result.status
8
+ File.symlink(old_name, new_name)
18
9
  end
19
10
 
20
- # When the host OS is Windows, uses the `dir` command to check whether
21
- # `file_name` is an NTFS symbolic link. Otherwise delegates to
22
- # `File.symlink`.
23
11
  def symlink?(file_name)
24
- return File.symlink?(file_name) unless Overcommit::OS.windows?
25
-
26
- result = win32_dir_cmd(file_name)
27
- win32_symlink?(result.stdout)
12
+ File.symlink?(file_name)
28
13
  end
29
14
 
30
- # When the host OS is Windows, uses the `dir` command to check whether
31
- # `link_name` is an NTFS symbolic link. If so, it parses the target from
32
- # the command output. Otherwise raises an `ArgumentError`. Delegates to
33
- # `File.readlink` if the host OS is not Windows.
34
15
  def readlink(link_name)
35
- return File.readlink(link_name) unless Overcommit::OS.windows?
36
-
37
- result = win32_dir_cmd(link_name)
38
-
39
- unless win32_symlink?(result.stdout)
40
- raise ArgumentError, "#{link_name} is not a symlink"
41
- end
42
-
43
- # Extract symlink target from output, which looks like:
44
- # 11/13/2012 12:53 AM <SYMLINK> mysymlink [C:\Windows\Temp\somefile.txt]
45
- result.stdout[/\[(.+)\]/, 1]
46
- end
47
-
48
- private
49
-
50
- def win32_dir_cmd(file_name)
51
- Overcommit::Subprocess.spawn(
52
- %W[dir #{win32_fix_pathsep(file_name)}]
53
- )
54
- end
55
-
56
- def win32_mklink_cmd(old_name, new_name)
57
- Overcommit::Subprocess.spawn(
58
- %W[mklink #{win32_fix_pathsep(new_name)} #{win32_fix_pathsep(old_name)}]
59
- )
60
- end
61
-
62
- def win32_fix_pathsep(path)
63
- path.tr(File::SEPARATOR, Overcommit::OS::SEPARATOR)
64
- end
65
-
66
- def win32_symlink?(dir_output)
67
- !(dir_output =~ /<SYMLINK>/).nil?
16
+ File.readlink(link_name)
68
17
  end
69
18
  end
70
19
  end
@@ -166,9 +166,12 @@ module Overcommit
166
166
  return if Process.ppid.zero?
167
167
 
168
168
  if OS.windows?
169
- `wmic process where ProcessId=#{Process.ppid} get CommandLine /FORMAT:VALUE`.
170
- strip.
171
- slice(/(?<=CommandLine=).+/)
169
+ result = execute([
170
+ 'powershell.exe', '-NoProfile', '-NonInteractive', '-Command',
171
+ "(Get-CimInstance Win32_Process -Filter 'ProcessId = #{Process.ppid}').CommandLine",
172
+ ])
173
+ command = result.stdout.strip
174
+ command if result.success? && !command.empty?
172
175
  elsif OS.cygwin?
173
176
  # Cygwin's `ps` command behaves differently than the traditional
174
177
  # Linux version, but a comparable `procps` is provided to compensate.
@@ -176,7 +179,7 @@ module Overcommit
176
179
  else
177
180
  `ps -ocommand= -p #{Process.ppid}`.chomp
178
181
  end
179
- rescue Errno::EPERM, Errno::ENOENT
182
+ rescue Errno::EPERM, Errno::ENOENT, ChildProcess::LaunchError
180
183
  # Process information may not be available, such as inside sandboxed environments
181
184
  nil
182
185
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  module Overcommit
5
- VERSION = '0.73.0'
5
+ VERSION = '0.75.0'
6
6
  end
@@ -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
@@ -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.73.0
4
+ version: 0.75.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'