Skip to content

Commit bc48619

Browse files
jawshooahsds
authored andcommitted
Use GitRepo#submodule_statuses in SubmoduleStatus hooks
1 parent a22f8db commit bc48619

File tree

4 files changed

+8
-108
lines changed

4 files changed

+8
-108
lines changed

lib/overcommit/hook/post_checkout/submodule_status.rb

+2-27
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,7 @@ module Overcommit::Hook::PostCheckout
33
# notifies the user if any are uninitialized, out of date with
44
# the current index, or contain merge conflicts.
55
class SubmoduleStatus < Base
6-
SUBMODULE_STATUS_REGEX = /
7-
^\s*(?<prefix>[-+U]?)(?<sha1>\w+)
8-
\s(?<path>[^\s]+?)
9-
(?:\s\((?<describe>.+)\))?$
10-
/x
11-
12-
SubmoduleStatus = Struct.new(:prefix, :sha1, :path, :describe) do
13-
def uninitialized?
14-
prefix == '-'
15-
end
16-
17-
def outdated?
18-
prefix == '+'
19-
end
20-
21-
def merge_conflict?
22-
prefix == 'U'
23-
end
24-
end
25-
266
def run
27-
result = execute(command)
28-
submodule_statuses = parse_submodule_statuses(result.stdout)
29-
307
messages = []
318
submodule_statuses.each do |submodule_status|
329
path = submodule_status.path
@@ -46,10 +23,8 @@ def run
4623

4724
private
4825

49-
def parse_submodule_statuses(output)
50-
output.scan(SUBMODULE_STATUS_REGEX).map do |prefix, sha1, path, describe|
51-
SubmoduleStatus.new(prefix, sha1, path, describe)
52-
end
26+
def submodule_statuses
27+
Overcommit::GitRepo.submodule_statuses(recursive: config['recursive'])
5328
end
5429
end
5530
end

lib/overcommit/hook/post_commit/submodule_status.rb

+2-27
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,7 @@ module Overcommit::Hook::PostCommit
33
# notifies the user if any are uninitialized, out of date with
44
# the current index, or contain merge conflicts.
55
class SubmoduleStatus < Base
6-
SUBMODULE_STATUS_REGEX = /
7-
^\s*(?<prefix>[-+U]?)(?<sha1>\w+)
8-
\s(?<path>[^\s]+?)
9-
(?:\s\((?<describe>.+)\))?$
10-
/x
11-
12-
SubmoduleStatus = Struct.new(:prefix, :sha1, :path, :describe) do
13-
def uninitialized?
14-
prefix == '-'
15-
end
16-
17-
def outdated?
18-
prefix == '+'
19-
end
20-
21-
def merge_conflict?
22-
prefix == 'U'
23-
end
24-
end
25-
266
def run
27-
result = execute(command)
28-
submodule_statuses = parse_submodule_statuses(result.stdout)
29-
307
messages = []
318
submodule_statuses.each do |submodule_status|
329
path = submodule_status.path
@@ -46,10 +23,8 @@ def run
4623

4724
private
4825

49-
def parse_submodule_statuses(output)
50-
output.scan(SUBMODULE_STATUS_REGEX).map do |prefix, sha1, path, describe|
51-
SubmoduleStatus.new(prefix, sha1, path, describe)
52-
end
26+
def submodule_statuses
27+
Overcommit::GitRepo.submodule_statuses(recursive: config['recursive'])
5328
end
5429
end
5530
end

lib/overcommit/hook/post_merge/submodule_status.rb

+2-27
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,7 @@ module Overcommit::Hook::PostMerge
33
# notifies the user if any are uninitialized, out of date with
44
# the current index, or contain merge conflicts.
55
class SubmoduleStatus < Base
6-
SUBMODULE_STATUS_REGEX = /
7-
^\s*(?<prefix>[-+U]?)(?<sha1>\w+)
8-
\s(?<path>[^\s]+?)
9-
(?:\s\((?<describe>.+)\))?$
10-
/x
11-
12-
SubmoduleStatus = Struct.new(:prefix, :sha1, :path, :describe) do
13-
def uninitialized?
14-
prefix == '-'
15-
end
16-
17-
def outdated?
18-
prefix == '+'
19-
end
20-
21-
def merge_conflict?
22-
prefix == 'U'
23-
end
24-
end
25-
266
def run
27-
result = execute(command)
28-
submodule_statuses = parse_submodule_statuses(result.stdout)
29-
307
messages = []
318
submodule_statuses.each do |submodule_status|
329
path = submodule_status.path
@@ -46,10 +23,8 @@ def run
4623

4724
private
4825

49-
def parse_submodule_statuses(output)
50-
output.scan(SUBMODULE_STATUS_REGEX).map do |prefix, sha1, path, describe|
51-
SubmoduleStatus.new(prefix, sha1, path, describe)
52-
end
26+
def submodule_statuses
27+
Overcommit::GitRepo.submodule_statuses(recursive: config['recursive'])
5328
end
5429
end
5530
end

lib/overcommit/hook/post_rewrite/submodule_status.rb

+2-27
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,7 @@ module Overcommit::Hook::PostRewrite
33
# notifies the user if any are uninitialized, out of date with
44
# the current index, or contain merge conflicts.
55
class SubmoduleStatus < Base
6-
SUBMODULE_STATUS_REGEX = /
7-
^\s*(?<prefix>[-+U]?)(?<sha1>\w+)
8-
\s(?<path>[^\s]+?)
9-
(?:\s\((?<describe>.+)\))?$
10-
/x
11-
12-
SubmoduleStatus = Struct.new(:prefix, :sha1, :path, :describe) do
13-
def uninitialized?
14-
prefix == '-'
15-
end
16-
17-
def outdated?
18-
prefix == '+'
19-
end
20-
21-
def merge_conflict?
22-
prefix == 'U'
23-
end
24-
end
25-
266
def run
27-
result = execute(command)
28-
submodule_statuses = parse_submodule_statuses(result.stdout)
29-
307
messages = []
318
submodule_statuses.each do |submodule_status|
329
path = submodule_status.path
@@ -46,10 +23,8 @@ def run
4623

4724
private
4825

49-
def parse_submodule_statuses(output)
50-
output.scan(SUBMODULE_STATUS_REGEX).map do |prefix, sha1, path, describe|
51-
SubmoduleStatus.new(prefix, sha1, path, describe)
52-
end
26+
def submodule_statuses
27+
Overcommit::GitRepo.submodule_statuses(recursive: config['recursive'])
5328
end
5429
end
5530
end

0 commit comments

Comments
 (0)