overcommit 0.51.0 → 0.52.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 +4 -4
- data/config/default.yml +31 -0
- data/lib/overcommit/hook/base.rb +13 -0
- data/lib/overcommit/hook/pre_commit/go_fmt.rb +17 -0
- data/lib/overcommit/hook/pre_commit/golangci_lint.rb +21 -0
- data/lib/overcommit/hook/pre_commit/mdl.rb +3 -3
- data/lib/overcommit/hook/pre_push/base.rb +16 -0
- data/lib/overcommit/hook/pre_push/go_test.rb +14 -0
- data/lib/overcommit/hook/pre_push/golangci_lint.rb +16 -0
- data/lib/overcommit/hook/pre_push/protected_branches.rb +40 -15
- data/lib/overcommit/hook_context/pre_push.rb +9 -0
- data/lib/overcommit/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d272167cf4a2702f9a368d4c4cb0ade3236256c13166d2e18e4bfc9a1f52dd4
|
4
|
+
data.tar.gz: 2241202866ac631d15ee8925364db27794342badd181d18a7effd8a0cbe5a60f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc3efeeb6257f78b5fb490613808375ce52281b4f250bce2275a90a7105f9ce88191de56ab985b00944abffa04650b1cb700d3ecc7bbba0ddae9da139561b7dc
|
7
|
+
data.tar.gz: ee4d8d6006e42c77b936adc2efe62d93742ce461dd2f117165feadfd82dcebde152b1531a984ea91370ec0005a6b108f1e1f5b683641a5d5d2fe90f4ae63a498
|
data/config/default.yml
CHANGED
@@ -337,6 +337,23 @@ PreCommit:
|
|
337
337
|
flags: ['-IEHnw']
|
338
338
|
keywords: ['FContext','FDescribe','FIt','FMeasure','FSpecify','FWhen']
|
339
339
|
|
340
|
+
GoFmt:
|
341
|
+
enabled: true
|
342
|
+
description: 'Fix with go fmt'
|
343
|
+
required_executable: 'go'
|
344
|
+
command: ['go', 'fmt']
|
345
|
+
parallelize: false
|
346
|
+
include: '**/*.go'
|
347
|
+
|
348
|
+
GolangciLint:
|
349
|
+
enabled: false
|
350
|
+
description: 'Analyze with golangci-lint'
|
351
|
+
required_executable: 'golangci-lint'
|
352
|
+
install_command: 'go get github.com/golangci/golangci-lint/cmd/golangci-lint'
|
353
|
+
flags: ['--out-format=line-number', '--print-issued-lines=false']
|
354
|
+
command: ['golangci-lint', 'run']
|
355
|
+
include: '**/*.go'
|
356
|
+
|
340
357
|
GoLint:
|
341
358
|
enabled: false
|
342
359
|
description: 'Analyze with golint'
|
@@ -1253,6 +1270,20 @@ PrePush:
|
|
1253
1270
|
required_executable: 'git-lfs'
|
1254
1271
|
install_command: 'brew install git-lfs'
|
1255
1272
|
|
1273
|
+
GolangciLint:
|
1274
|
+
enabled: false
|
1275
|
+
description: 'Analyze with golangci-lint'
|
1276
|
+
required_executable: 'golangci-lint'
|
1277
|
+
install_command: 'go get github.com/golangci/golangci-lint/cmd/golangci-lint'
|
1278
|
+
flags: ['--out-format=line-number', '--print-issued-lines=false']
|
1279
|
+
command: ['golangci-lint', 'run']
|
1280
|
+
|
1281
|
+
GoTest:
|
1282
|
+
enabled: false
|
1283
|
+
description: 'Run go test suite'
|
1284
|
+
required_executable: 'go'
|
1285
|
+
command: ['go', 'test', './...']
|
1286
|
+
|
1256
1287
|
Minitest:
|
1257
1288
|
enabled: false
|
1258
1289
|
description: 'Run Minitest test suite'
|
data/lib/overcommit/hook/base.rb
CHANGED
@@ -79,12 +79,17 @@ module Overcommit::Hook
|
|
79
79
|
@config['enabled'] != false
|
80
80
|
end
|
81
81
|
|
82
|
+
def excluded?
|
83
|
+
exclude_branches.any? { |p| File.fnmatch(p, current_branch) }
|
84
|
+
end
|
85
|
+
|
82
86
|
def skip?
|
83
87
|
@config['skip']
|
84
88
|
end
|
85
89
|
|
86
90
|
def run?
|
87
91
|
enabled? &&
|
92
|
+
!excluded? &&
|
88
93
|
!(@config['requires_files'] && applicable_files.empty?)
|
89
94
|
end
|
90
95
|
|
@@ -276,5 +281,13 @@ module Overcommit::Hook
|
|
276
281
|
status
|
277
282
|
end
|
278
283
|
end
|
284
|
+
|
285
|
+
def exclude_branches
|
286
|
+
@config['exclude_branches'] || []
|
287
|
+
end
|
288
|
+
|
289
|
+
def current_branch
|
290
|
+
@current_branch ||= Overcommit::GitRepo.current_branch
|
291
|
+
end
|
279
292
|
end
|
280
293
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Overcommit::Hook::PreCommit
|
4
|
+
# Runs go fmt for all modified Go files
|
5
|
+
class GoFmt < Base
|
6
|
+
def run
|
7
|
+
errors = []
|
8
|
+
applicable_files.each do |file|
|
9
|
+
result = execute(command, args: [file])
|
10
|
+
errors << (result.stdout + result.stderr) unless result.success?
|
11
|
+
end
|
12
|
+
return :pass if errors.empty?
|
13
|
+
|
14
|
+
[:fail, errors.join("\n")]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Overcommit::Hook::PreCommit
|
4
|
+
# Runs `golangci-lint run` against any modified packages
|
5
|
+
#
|
6
|
+
# @see https://github.com/golangci/golangci-lint
|
7
|
+
class GolangciLint < Base
|
8
|
+
def run
|
9
|
+
packages = applicable_files.map { |f| File.dirname(f) }.uniq
|
10
|
+
result = execute(command, args: packages)
|
11
|
+
return :pass if result.success?
|
12
|
+
return [:fail, result.stderr] unless result.stderr.empty?
|
13
|
+
|
14
|
+
extract_messages(
|
15
|
+
result.stdout.split("\n"),
|
16
|
+
/^(?<file>(?:\w:)?[^:]+):(?<line>\d+)/,
|
17
|
+
nil
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -19,9 +19,9 @@ module Overcommit::Hook::PreCommit
|
|
19
19
|
json_messages.map do |message|
|
20
20
|
Overcommit::Hook::Message.new(
|
21
21
|
:error,
|
22
|
-
message[
|
23
|
-
message[
|
24
|
-
message[
|
22
|
+
message['filename'],
|
23
|
+
message['line'],
|
24
|
+
"#{message['filename']}:#{message['line']} #{message['rule']} #{message['description']}"
|
25
25
|
)
|
26
26
|
end
|
27
27
|
end
|
@@ -8,5 +8,21 @@ module Overcommit::Hook::PrePush
|
|
8
8
|
extend Forwardable
|
9
9
|
|
10
10
|
def_delegators :@context, :remote_name, :remote_url, :pushed_refs
|
11
|
+
|
12
|
+
def run?
|
13
|
+
super &&
|
14
|
+
!exclude_remotes.include?(remote_name) &&
|
15
|
+
(include_remote_ref_deletions? || !@context.remote_ref_deletion?)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def exclude_remotes
|
21
|
+
@config['exclude_remotes'] || []
|
22
|
+
end
|
23
|
+
|
24
|
+
def include_remote_ref_deletions?
|
25
|
+
@config['include_remote_ref_deletions']
|
26
|
+
end
|
11
27
|
end
|
12
28
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Overcommit::Hook::PrePush
|
4
|
+
# Runs `go test ./...` command on prepush
|
5
|
+
class GoTest < Base
|
6
|
+
def run
|
7
|
+
result = execute(command)
|
8
|
+
return :pass if result.success?
|
9
|
+
|
10
|
+
output = result.stdout + result.stderr
|
11
|
+
[:fail, output]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Overcommit::Hook::PrePush
|
4
|
+
# Runs golangci-lint
|
5
|
+
#
|
6
|
+
# @see https://github.com/golangci/golangci-lint
|
7
|
+
class GolangciLint < Base
|
8
|
+
def run
|
9
|
+
result = execute(command)
|
10
|
+
return :pass if result.success?
|
11
|
+
|
12
|
+
output = result.stdout + result.stderr
|
13
|
+
[:fail, output]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Overcommit::Hook::PrePush
|
4
|
-
# Prevents
|
4
|
+
# Prevents updates to specified branches.
|
5
|
+
# Accepts a 'destructive_only' option globally or per branch
|
6
|
+
# to only prevent destructive updates.
|
5
7
|
class ProtectedBranches < Base
|
6
8
|
def run
|
7
9
|
return :pass unless illegal_pushes.any?
|
@@ -17,32 +19,55 @@ module Overcommit::Hook::PrePush
|
|
17
19
|
|
18
20
|
def illegal_pushes
|
19
21
|
@illegal_pushes ||= pushed_refs.select do |pushed_ref|
|
20
|
-
protected?(pushed_ref
|
22
|
+
protected?(pushed_ref)
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
24
|
-
def protected?(
|
26
|
+
def protected?(ref)
|
27
|
+
find_pattern(ref.remote_ref)&.destructive?(ref)
|
28
|
+
end
|
29
|
+
|
30
|
+
def find_pattern(remote_ref)
|
25
31
|
ref_name = remote_ref[%r{refs/heads/(.*)}, 1]
|
26
|
-
return
|
27
|
-
|
28
|
-
|
32
|
+
return if ref_name.nil?
|
33
|
+
|
34
|
+
patterns.find do |pattern|
|
35
|
+
File.fnmatch(pattern.to_s, ref_name)
|
29
36
|
end
|
30
37
|
end
|
31
38
|
|
32
|
-
def
|
33
|
-
@
|
34
|
-
concat(Array(config['branch_patterns']))
|
39
|
+
def patterns
|
40
|
+
@patterns ||= fetch_patterns
|
35
41
|
end
|
36
42
|
|
37
|
-
def
|
43
|
+
def fetch_patterns
|
44
|
+
branch_configurations.map do |pattern|
|
45
|
+
if pattern.is_a?(Hash)
|
46
|
+
Pattern.new(pattern.keys.first, pattern['destructive_only'])
|
47
|
+
else
|
48
|
+
Pattern.new(pattern, global_destructive_only?)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def branch_configurations
|
54
|
+
config['branches'].to_a + config['branch_patterns'].to_a
|
55
|
+
end
|
56
|
+
|
57
|
+
def global_destructive_only?
|
38
58
|
config['destructive_only'].nil? || config['destructive_only']
|
39
59
|
end
|
40
60
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
61
|
+
Pattern = Struct.new('Pattern', :name, :destructive_only) do
|
62
|
+
alias_method :to_s, :name
|
63
|
+
alias_method :destructive_only?, :destructive_only
|
64
|
+
|
65
|
+
def destructive?(ref)
|
66
|
+
if destructive_only?
|
67
|
+
ref.destructive?
|
68
|
+
else
|
69
|
+
true
|
70
|
+
end
|
46
71
|
end
|
47
72
|
end
|
48
73
|
end
|
@@ -13,6 +13,15 @@ module Overcommit::HookContext
|
|
13
13
|
@args[1]
|
14
14
|
end
|
15
15
|
|
16
|
+
def remote_ref_deletion?
|
17
|
+
return @remote_ref_deletion if defined?(@remote_ref_deletion)
|
18
|
+
|
19
|
+
@remote_ref_deletion ||= input_lines.
|
20
|
+
first.
|
21
|
+
split(' ').
|
22
|
+
first == '(deleted)'
|
23
|
+
end
|
24
|
+
|
16
25
|
def pushed_refs
|
17
26
|
input_lines.map do |line|
|
18
27
|
PushedRef.new(*line.split(' '))
|
data/lib/overcommit/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: overcommit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.52.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shane da Silva
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: childprocess
|
@@ -139,8 +139,10 @@ files:
|
|
139
139
|
- lib/overcommit/hook/pre_commit/foodcritic.rb
|
140
140
|
- lib/overcommit/hook/pre_commit/forbidden_branches.rb
|
141
141
|
- lib/overcommit/hook/pre_commit/ginkgo_focus.rb
|
142
|
+
- lib/overcommit/hook/pre_commit/go_fmt.rb
|
142
143
|
- lib/overcommit/hook/pre_commit/go_lint.rb
|
143
144
|
- lib/overcommit/hook/pre_commit/go_vet.rb
|
145
|
+
- lib/overcommit/hook/pre_commit/golangci_lint.rb
|
144
146
|
- lib/overcommit/hook/pre_commit/hadolint.rb
|
145
147
|
- lib/overcommit/hook/pre_commit/haml_lint.rb
|
146
148
|
- lib/overcommit/hook/pre_commit/hard_tabs.rb
|
@@ -210,6 +212,8 @@ files:
|
|
210
212
|
- lib/overcommit/hook/pre_push/base.rb
|
211
213
|
- lib/overcommit/hook/pre_push/brakeman.rb
|
212
214
|
- lib/overcommit/hook/pre_push/cargo_test.rb
|
215
|
+
- lib/overcommit/hook/pre_push/go_test.rb
|
216
|
+
- lib/overcommit/hook/pre_push/golangci_lint.rb
|
213
217
|
- lib/overcommit/hook/pre_push/minitest.rb
|
214
218
|
- lib/overcommit/hook/pre_push/php_unit.rb
|
215
219
|
- lib/overcommit/hook/pre_push/protected_branches.rb
|