rabbitt-githooks 1.5.1 → 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -4
- data/lib/githooks.rb +2 -1
- data/lib/githooks/action.rb +13 -5
- data/lib/githooks/core_ext/rainbow.rb +4 -0
- data/lib/githooks/error.rb +4 -0
- data/lib/githooks/hook.rb +20 -10
- data/lib/githooks/repository.rb +31 -12
- data/lib/githooks/repository/limiter.rb +1 -1
- data/lib/githooks/section.rb +9 -4
- data/lib/githooks/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc92115463443ffe80792a5f569a4242e905d21b
|
4
|
+
data.tar.gz: 466abff7748a7204939a894cc8adfda9ec927b50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9390cef0e16c4574f9908f47ca1de0e4ceb842fa0dafaeed923e57568be96b09e73db566ed292df66a439b057a9ad5107ad3ccb5d4b8e86c342679262bfa6d62
|
7
|
+
data.tar.gz: 601aa784254ca0c9b1c3831c724ef90cfaa9a000e80fdc022d76c16e157aefe58d08323c97fbfdd84304dcf60e9d369914f8223be40ae5360dbdba27d8ae2d4b
|
data/Gemfile.lock
CHANGED
data/lib/githooks.rb
CHANGED
@@ -76,7 +76,8 @@ module GitHooks
|
|
76
76
|
SUCCESS_SYMBOL = '✓'.color_success! unless defined? SUCCESS_SYMBOL
|
77
77
|
FAILURE_SYMBOL = 'X'.color_failure! unless defined? FAILURE_SYMBOL
|
78
78
|
UNKNOWN_SYMBOL = '?'.color_unknown! unless defined? UNKNOWN_SYMBOL
|
79
|
-
WARNING_SYMBOL = '
|
79
|
+
WARNING_SYMBOL = 'W'.color_warning! unless defined? WARNING_SYMBOL
|
80
|
+
SKIPPED_SYMBOL = 'S'.color_skipped! unless defined? SKIPPED_SYMBOL
|
80
81
|
|
81
82
|
LIB_PATH = Pathname.new(__FILE__).dirname.realpath unless defined? LIB_PATH
|
82
83
|
GEM_PATH = LIB_PATH.parent unless defined? GEM_PATH
|
data/lib/githooks/action.rb
CHANGED
@@ -22,7 +22,7 @@ require 'stringio'
|
|
22
22
|
require_relative 'repository'
|
23
23
|
|
24
24
|
module GitHooks
|
25
|
-
class Action
|
25
|
+
class Action
|
26
26
|
attr_reader :title, :section, :on, :limiters
|
27
27
|
attr_reader :success, :errors, :warnings, :benchmark
|
28
28
|
private :section, :on
|
@@ -50,26 +50,30 @@ module GitHooks
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def colored_title
|
53
|
+
return title.color_skipped! if skipped?
|
53
54
|
return title.color_unknown! unless finished?
|
54
55
|
success? ? title.color_success! : title.color_failure!
|
55
56
|
end
|
56
57
|
|
57
58
|
def status_symbol
|
59
|
+
return GitHooks::SKIPPED_SYMBOL if skipped?
|
58
60
|
return GitHooks::UNKNOWN_SYMBOL unless finished?
|
59
61
|
success? ? GitHooks::SUCCESS_SYMBOL : GitHooks::FAILURE_SYMBOL
|
60
62
|
end
|
61
63
|
|
62
|
-
%w
|
64
|
+
%w[finished running waiting skipped].each do |method|
|
63
65
|
define_method(:"#{method}?") { @status == method.to_sym }
|
64
66
|
define_method(:"#{method}!") { @status = method.to_sym }
|
65
67
|
end
|
66
68
|
|
67
|
-
def run # rubocop:disable MethodLength
|
69
|
+
def run # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
68
70
|
running!
|
69
71
|
with_benchmark do
|
70
72
|
with_captured_output {
|
71
73
|
begin
|
72
|
-
|
74
|
+
was_skipped = catch(:skip) do
|
75
|
+
@success &= @on.call
|
76
|
+
end
|
73
77
|
rescue StandardError => e
|
74
78
|
$stderr.puts "Exception thrown during action call: #{e.class.name}: #{e.message}"
|
75
79
|
if GitHooks.debug?
|
@@ -81,7 +85,7 @@ module GitHooks
|
|
81
85
|
end
|
82
86
|
@success = false
|
83
87
|
ensure
|
84
|
-
finished!
|
88
|
+
was_skipped ? skipped! : finished!
|
85
89
|
end
|
86
90
|
}
|
87
91
|
end
|
@@ -124,6 +128,10 @@ module GitHooks
|
|
124
128
|
|
125
129
|
# DSL Methods
|
126
130
|
|
131
|
+
def skip!
|
132
|
+
throw :skip, true
|
133
|
+
end
|
134
|
+
|
127
135
|
def config_path
|
128
136
|
GitHooks.hooks_root.join('configs')
|
129
137
|
end
|
data/lib/githooks/error.rb
CHANGED
data/lib/githooks/hook.rb
CHANGED
@@ -108,7 +108,7 @@ module GitHooks
|
|
108
108
|
private :setup_command
|
109
109
|
|
110
110
|
def find_command(name)
|
111
|
-
@commands.
|
111
|
+
@commands.find { |command| command.name == name.to_s }
|
112
112
|
end
|
113
113
|
|
114
114
|
def sections
|
@@ -169,22 +169,32 @@ module GitHooks
|
|
169
169
|
@hook = hook
|
170
170
|
end
|
171
171
|
|
172
|
-
def
|
172
|
+
def repository
|
173
173
|
@hook.repository
|
174
174
|
end
|
175
175
|
|
176
|
-
def
|
177
|
-
@files ||=
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
176
|
+
def files
|
177
|
+
@files ||= begin
|
178
|
+
options = {
|
179
|
+
staged: hook.staged,
|
180
|
+
tracked: hook.tracked,
|
181
|
+
untracked: hook.untracked
|
182
|
+
}
|
183
|
+
|
184
|
+
if %w[ commit-msg pre-push ].include? hook.phase
|
185
|
+
if (parent_sha = repository.last_unpushed_commit_parent)
|
186
|
+
options.merge!(ref: parent_sha)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
repository.manifest(options)
|
191
|
+
end
|
182
192
|
end
|
183
193
|
|
184
194
|
def filter(limiters)
|
185
|
-
|
195
|
+
files.dup.tap do |files|
|
186
196
|
limiters.each do |type, limiter|
|
187
|
-
puts "Limiter [#{type}] -> (#{limiter.only.inspect}) match against: " if GitHooks.debug?
|
197
|
+
STDERR.puts "Limiter [#{type}] -> (#{limiter.only.inspect}) match against: " if GitHooks.debug?
|
188
198
|
limiter.limit(files)
|
189
199
|
end
|
190
200
|
end
|
data/lib/githooks/repository.rb
CHANGED
@@ -21,7 +21,7 @@ require 'set'
|
|
21
21
|
require 'singleton'
|
22
22
|
|
23
23
|
module GitHooks
|
24
|
-
class Repository
|
24
|
+
class Repository
|
25
25
|
extend SystemUtils
|
26
26
|
|
27
27
|
command :git
|
@@ -75,23 +75,20 @@ module GitHooks
|
|
75
75
|
git(*%w(stash pop -q)).status.success?
|
76
76
|
end
|
77
77
|
|
78
|
-
def manifest(options = {})
|
78
|
+
def manifest(options = {})
|
79
79
|
ref = options.delete(:ref)
|
80
|
+
|
80
81
|
return staged_manifest(ref: ref) if options.delete(:staged)
|
81
82
|
|
82
83
|
manifest_list = unstaged_manifest(ref: ref)
|
83
84
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
end
|
88
|
-
end
|
85
|
+
tracked_manifest(ref: ref).each_with_object(manifest_list) do |file, list|
|
86
|
+
list << file
|
87
|
+
end if options.delete(:tracked)
|
89
88
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
end
|
94
|
-
end
|
89
|
+
untracked_manifest(ref: ref).each_with_object(manifest_list) do |file, list|
|
90
|
+
list << file
|
91
|
+
end if options.delete(:untracked)
|
95
92
|
|
96
93
|
manifest_list.sort
|
97
94
|
end
|
@@ -121,6 +118,28 @@ module GitHooks
|
|
121
118
|
}.compact
|
122
119
|
end
|
123
120
|
|
121
|
+
def unpushed_commits
|
122
|
+
result = git('log', '--format=%H', '@{upstream}..')
|
123
|
+
if result.failure?
|
124
|
+
if result.error =~ /^fatal: no upstream configured for branch '([^']+)'/
|
125
|
+
fail Error::RemoteNotSet, "No upstream remote configured for '#{$1}'"
|
126
|
+
else
|
127
|
+
fail Error::CommandExecutionFailure, result.error
|
128
|
+
end
|
129
|
+
end
|
130
|
+
result.output.split(/\s*\n\s*/).collect(&:strip)
|
131
|
+
end
|
132
|
+
|
133
|
+
def revision_parent(revision)
|
134
|
+
return unless (result = git('rev-parse', "#{revision}~1")).status.success?
|
135
|
+
result.output.strip
|
136
|
+
end
|
137
|
+
|
138
|
+
def last_unpushed_commit_parent
|
139
|
+
oldest_sha = unpushed_commits.last
|
140
|
+
revision_parent(oldest_sha) unless oldest_sha.nil?
|
141
|
+
end
|
142
|
+
|
124
143
|
private
|
125
144
|
|
126
145
|
def diff_index(options = {}) # rubocop:disable AbcSize
|
@@ -44,7 +44,7 @@ module GitHooks
|
|
44
44
|
match_file(file, @only).tap do |result|
|
45
45
|
if GitHooks.debug?
|
46
46
|
result = (result ? 'success' : 'failure')
|
47
|
-
puts " #{file.path} (#{file.attribute_value(@type).inspect}) was a #{result}"
|
47
|
+
STDERR.puts " #{file.path} (#{file.attribute_value(@type).inspect}) was a #{result}"
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
data/lib/githooks/section.rb
CHANGED
@@ -48,7 +48,6 @@ module GitHooks
|
|
48
48
|
# overrides previous action method to only return
|
49
49
|
# actions that have a non-empty manifest
|
50
50
|
def actions
|
51
|
-
return @actions unless @hook.phase == 'pre-commit'
|
52
51
|
@actions.reject { |action| action.manifest.empty? }
|
53
52
|
end
|
54
53
|
alias_method :__getobj__, :actions
|
@@ -57,7 +56,7 @@ module GitHooks
|
|
57
56
|
@actions << action
|
58
57
|
end
|
59
58
|
|
60
|
-
%w(finished running waiting).each do |method|
|
59
|
+
%w(finished running waiting skipped).each do |method|
|
61
60
|
define_method(:"#{method}?") { @status == method.to_sym }
|
62
61
|
define_method(:"#{method}!") { @status = method.to_sym }
|
63
62
|
end
|
@@ -67,7 +66,7 @@ module GitHooks
|
|
67
66
|
end
|
68
67
|
|
69
68
|
def wait_count
|
70
|
-
@actions.
|
69
|
+
@actions.count(&:waiting?)
|
71
70
|
end
|
72
71
|
|
73
72
|
def name(phase = GitHooks::HOOK_NAME)
|
@@ -76,6 +75,7 @@ module GitHooks
|
|
76
75
|
|
77
76
|
def colored_name(phase = GitHooks::HOOK_NAME)
|
78
77
|
title = name(phase)
|
78
|
+
return title.color_skipped! if @actions.all?(&:skipped?)
|
79
79
|
return title.color_unknown! unless finished? && completed?
|
80
80
|
success? ? title.color_success! : title.color_failure!
|
81
81
|
end
|
@@ -88,7 +88,12 @@ module GitHooks
|
|
88
88
|
running!
|
89
89
|
begin
|
90
90
|
time_start = Time.now
|
91
|
-
actions.collect { |action|
|
91
|
+
actions.collect { |action|
|
92
|
+
catch(:skip) do
|
93
|
+
@success &= action.run
|
94
|
+
end
|
95
|
+
@success
|
96
|
+
}.all?
|
92
97
|
ensure
|
93
98
|
@benchmark = Time.now - time_start
|
94
99
|
finished!
|
data/lib/githooks/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rabbitt-githooks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carl P. Corliss
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rainbow
|
@@ -209,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
209
209
|
version: '0'
|
210
210
|
requirements: []
|
211
211
|
rubyforge_project:
|
212
|
-
rubygems_version: 2.
|
212
|
+
rubygems_version: 2.2.2
|
213
213
|
signing_key:
|
214
214
|
specification_version: 4
|
215
215
|
summary: framework for building git hooks tests
|