captain_hoog 1.1.1 → 2.0.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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/README.md +40 -18
  4. data/bin/hoog +5 -0
  5. data/captain_hoog.gemspec +4 -2
  6. data/features/init.feature +16 -0
  7. data/features/pull.feature +11 -0
  8. data/features/support/env.rb +4 -3
  9. data/features/support/steps/hooks_steps.rb +46 -13
  10. data/features/support/world.rb +21 -1
  11. data/features/testing.feature +18 -0
  12. data/features/version.feature +3 -3
  13. data/lib/captain_hoog/cli/git.rb +26 -0
  14. data/lib/captain_hoog/cli/hoog.rb +129 -0
  15. data/lib/captain_hoog/cli/pull.rb +14 -0
  16. data/lib/captain_hoog/{templates → cli/templates}/hoogfile.erb +0 -0
  17. data/lib/captain_hoog/{templates → cli/templates}/install.erb +1 -0
  18. data/lib/captain_hoog/cli/treasury.rb +15 -0
  19. data/lib/captain_hoog/cli.rb +9 -0
  20. data/lib/captain_hoog/core_ext/hash.rb +4 -4
  21. data/lib/captain_hoog/dependencies.rb +3 -0
  22. data/lib/captain_hoog/git.rb +2 -7
  23. data/lib/captain_hoog/message.rb +31 -0
  24. data/lib/captain_hoog/pre_git.rb +31 -10
  25. data/lib/captain_hoog/test/sandbox.rb +1 -1
  26. data/lib/captain_hoog/version.rb +1 -1
  27. data/lib/captain_hoog.rb +19 -12
  28. data/spec/fixtures/neverland.git/HEAD +1 -0
  29. data/spec/fixtures/neverland.git/config +6 -0
  30. data/spec/fixtures/neverland.git/description +1 -0
  31. data/spec/fixtures/neverland.git/hooks/applypatch-msg.sample +15 -0
  32. data/spec/fixtures/neverland.git/hooks/commit-msg.sample +24 -0
  33. data/spec/fixtures/neverland.git/hooks/post-update.sample +8 -0
  34. data/spec/fixtures/neverland.git/hooks/pre-applypatch.sample +14 -0
  35. data/spec/fixtures/neverland.git/hooks/pre-commit.sample +49 -0
  36. data/spec/fixtures/neverland.git/hooks/pre-push.sample +53 -0
  37. data/spec/fixtures/neverland.git/hooks/pre-rebase.sample +169 -0
  38. data/spec/fixtures/neverland.git/hooks/pre-receive.sample +24 -0
  39. data/spec/fixtures/neverland.git/hooks/prepare-commit-msg.sample +36 -0
  40. data/spec/fixtures/neverland.git/hooks/update.sample +128 -0
  41. data/spec/fixtures/neverland.git/info/exclude +6 -0
  42. data/spec/fixtures/plugins/test_plugins/divide.rb +4 -0
  43. data/spec/fixtures/plugins/test_plugins/passing/pure/foo/foo.rb +2 -1
  44. data/spec/lib/captain_hoog/git_spec.rb +2 -2
  45. data/spec/lib/captain_hoog/plugin_spec.rb +1 -1
  46. data/spec/lib/captain_hoog/pre_git_spec.rb +36 -19
  47. metadata +75 -11
  48. data/bin/githoog +0 -118
  49. data/lib/captain_hoog/errors.rb +0 -1
@@ -0,0 +1,6 @@
1
+ # git ls-files --others --exclude-from=.git/info/exclude
2
+ # Lines that start with '#' are comments.
3
+ # For a project mostly in C, the following would be a good set of
4
+ # exclude patterns (uncomment them if you want to use them):
5
+ # *.[oa]
6
+ # *~
@@ -10,4 +10,8 @@ git.describe 'divide' do |hook|
10
10
  hook.test do
11
11
  (12/divider) == check_equal
12
12
  end
13
+
14
+ hook.message do
15
+ "Dividing fails"
16
+ end
13
17
  end
@@ -1,11 +1,12 @@
1
1
  git.describe "foo" do |pre|
2
2
 
3
3
  pre.test do
4
+ @foo = 1
4
5
  true
5
6
  end
6
7
 
7
8
  pre.message do
8
- "The what test failed. Prevent you from doing anything."
9
+ "The #{@foo} what test failed. Prevent you from doing anything."
9
10
  end
10
11
 
11
12
  end
@@ -71,7 +71,7 @@ describe CaptainHoog::Git do
71
71
  expect do
72
72
  subject.message do
73
73
  1
74
- end
74
+ end.message
75
75
  end.to raise_error(CaptainHoog::Errors::MessageResultNotValidError)
76
76
  end
77
77
  end
@@ -153,7 +153,7 @@ describe CaptainHoog::Git do
153
153
  end.to_not raise_error
154
154
 
155
155
  plugin.eval_plugin
156
- expect(plugin.execute[:message]).to eq "It's 12."
156
+ expect(plugin.execute[:message].call).to eq "It's 12."
157
157
  end
158
158
 
159
159
  end
@@ -90,7 +90,7 @@ describe CaptainHoog::Plugin do
90
90
 
91
91
  it "includes the test failure message at the :message key" do
92
92
  expect(subject).to have_key(:message)
93
- expect(subject[:message]).to eq "Test failed."
93
+ expect(subject[:message].call).to eq "Test failed."
94
94
  end
95
95
 
96
96
  end
@@ -1,6 +1,29 @@
1
1
  require 'spec_helper'
2
2
 
3
+ module PreGitConfig
4
+ def configure(plugins_dir: [])
5
+ subject.configure do |config|
6
+ config.headline_on_success = "Success!"
7
+ config.headline_on_failure = "Failure!"
8
+ config.project_dir = File.dirname(__FILE__)
9
+ config.plugins_dir = plugins_dir
10
+ config.suppress_headline = true
11
+ config.context = "pre-commit"
12
+ end
13
+ end
14
+ end
15
+
3
16
  describe CaptainHoog::PreGit do
17
+ include PreGitConfig
18
+ let(:plugins_path) do
19
+ [File.join(File.dirname(__FILE__),
20
+ "..",
21
+ "..",
22
+ "fixtures",
23
+ "plugins",
24
+ "test_plugins",
25
+ "passing")]
26
+ end
4
27
 
5
28
  describe "class methods" do
6
29
 
@@ -30,26 +53,17 @@ describe CaptainHoog::PreGit do
30
53
  expect(subject).to respond_to(:configure)
31
54
  end
32
55
 
33
- describe "#configure" do
34
- let(:plugins_path) do
35
- [File.join(File.dirname(__FILE__),
36
- "..",
37
- "..",
38
- "fixtures",
39
- "plugins",
40
- "test_plugins",
41
- "passing",
42
- "pure")]
43
- end
56
+ it "provides #context getter" do
57
+ expect(subject).to respond_to(:context)
58
+ end
44
59
 
60
+ it "provides #context setter" do
61
+ expect(subject).to respond_to(:context=)
62
+ end
63
+
64
+ describe "#configure" do
45
65
  before do
46
- subject.configure do |config|
47
- config.headline_on_success = "Success!"
48
- config.headline_on_failure = "Failure!"
49
- config.project_dir = File.dirname(__FILE__)
50
- config.plugins_dir = plugins_path
51
- config.suppress_headline = true
52
- end
66
+ configure(plugins_dir: plugins_path)
53
67
  end
54
68
 
55
69
  it "let you define the success headline message" do
@@ -65,7 +79,7 @@ describe CaptainHoog::PreGit do
65
79
  end
66
80
 
67
81
  it "let you define the plugins dir" do
68
- expect(CaptainHoog::PreGit.plugins_dir).to eq plugins_path
82
+ expect(CaptainHoog::PreGit.plugins_dir.last).to eq plugins_path.first
69
83
  end
70
84
 
71
85
  end
@@ -90,6 +104,9 @@ describe CaptainHoog::PreGit do
90
104
  end
91
105
 
92
106
  it 'affects only configured plugins' do
107
+ allow(CaptainHoog).to receive(:treasury_path)
108
+ .and_return(plugins_path.first)
109
+ configure
93
110
  pre_git = CaptainHoog::PreGit.run(plugins_list:plugins_list)
94
111
  expect(pre_git.instance_variable_get(:@results).size).to eq 1
95
112
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: captain_hoog
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Schmidt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-25 00:00:00.000000000 Z
11
+ date: 2017-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -64,6 +64,20 @@ dependencies:
64
64
  - - "~>"
65
65
  - !ruby/object:Gem::Version
66
66
  version: 1.4.5
67
+ - !ruby/object:Gem::Dependency
68
+ name: git
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: 1.2.9.1
74
+ type: :runtime
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: 1.2.9.1
67
81
  - !ruby/object:Gem::Dependency
68
82
  name: bundler
69
83
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +136,20 @@ dependencies:
122
136
  version: '0'
123
137
  - !ruby/object:Gem::Dependency
124
138
  name: aruba
139
+ requirement: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - '='
142
+ - !ruby/object:Gem::Version
143
+ version: 0.6.1
144
+ type: :development
145
+ prerelease: false
146
+ version_requirements: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - '='
149
+ - !ruby/object:Gem::Version
150
+ version: 0.6.1
151
+ - !ruby/object:Gem::Dependency
152
+ name: minitest
125
153
  requirement: !ruby/object:Gem::Requirement
126
154
  requirements:
127
155
  - - ">="
@@ -135,7 +163,7 @@ dependencies:
135
163
  - !ruby/object:Gem::Version
136
164
  version: '0'
137
165
  - !ruby/object:Gem::Dependency
138
- name: minitest
166
+ name: pry
139
167
  requirement: !ruby/object:Gem::Requirement
140
168
  requirements:
141
169
  - - ">="
@@ -152,7 +180,7 @@ description:
152
180
  email:
153
181
  - daniel.schmidt@gateprotect.com
154
182
  executables:
155
- - githoog
183
+ - hoog
156
184
  extensions: []
157
185
  extra_rdoc_files: []
158
186
  files:
@@ -162,13 +190,15 @@ files:
162
190
  - LICENSE.txt
163
191
  - README.md
164
192
  - Rakefile
165
- - bin/githoog
193
+ - bin/hoog
166
194
  - captain_hoog.gemspec
167
195
  - changelog.md
168
196
  - features/failed_hook.feature
197
+ - features/init.feature
169
198
  - features/installing_hook.feature
170
199
  - features/moving_hooks.feature
171
200
  - features/passed_hook.feature
201
+ - features/pull.feature
172
202
  - features/removing_hook.feature
173
203
  - features/support/env.rb
174
204
  - features/support/steps/hooks_steps.rb
@@ -176,23 +206,28 @@ files:
176
206
  - features/testing.feature
177
207
  - features/version.feature
178
208
  - lib/captain_hoog.rb
209
+ - lib/captain_hoog/cli.rb
210
+ - lib/captain_hoog/cli/git.rb
211
+ - lib/captain_hoog/cli/hoog.rb
212
+ - lib/captain_hoog/cli/pull.rb
213
+ - lib/captain_hoog/cli/templates/hoogfile.erb
214
+ - lib/captain_hoog/cli/templates/install.erb
215
+ - lib/captain_hoog/cli/treasury.rb
179
216
  - lib/captain_hoog/config/hook_types.yml
180
217
  - lib/captain_hoog/core_ext.rb
181
218
  - lib/captain_hoog/core_ext/hash.rb
182
219
  - lib/captain_hoog/delegatable.rb
183
220
  - lib/captain_hoog/dependencies.rb
184
221
  - lib/captain_hoog/env.rb
185
- - lib/captain_hoog/errors.rb
186
222
  - lib/captain_hoog/errors/dsl_errors.rb
187
223
  - lib/captain_hoog/git.rb
188
224
  - lib/captain_hoog/helper_table.rb
189
225
  - lib/captain_hoog/hoogfile.rb
226
+ - lib/captain_hoog/message.rb
190
227
  - lib/captain_hoog/plugin.rb
191
228
  - lib/captain_hoog/plugin_list.rb
192
229
  - lib/captain_hoog/pre_git.rb
193
230
  - lib/captain_hoog/struct/hoog_struct.rb
194
- - lib/captain_hoog/templates/hoogfile.erb
195
- - lib/captain_hoog/templates/install.erb
196
231
  - lib/captain_hoog/test.rb
197
232
  - lib/captain_hoog/test/all.rb
198
233
  - lib/captain_hoog/test/rspec.rb
@@ -202,6 +237,20 @@ files:
202
237
  - spec/fixtures/code/helper.rb
203
238
  - spec/fixtures/config/cucumber/hoogfile.yml
204
239
  - spec/fixtures/config/spec/hoogfile.yml
240
+ - spec/fixtures/neverland.git/HEAD
241
+ - spec/fixtures/neverland.git/config
242
+ - spec/fixtures/neverland.git/description
243
+ - spec/fixtures/neverland.git/hooks/applypatch-msg.sample
244
+ - spec/fixtures/neverland.git/hooks/commit-msg.sample
245
+ - spec/fixtures/neverland.git/hooks/post-update.sample
246
+ - spec/fixtures/neverland.git/hooks/pre-applypatch.sample
247
+ - spec/fixtures/neverland.git/hooks/pre-commit.sample
248
+ - spec/fixtures/neverland.git/hooks/pre-push.sample
249
+ - spec/fixtures/neverland.git/hooks/pre-rebase.sample
250
+ - spec/fixtures/neverland.git/hooks/pre-receive.sample
251
+ - spec/fixtures/neverland.git/hooks/prepare-commit-msg.sample
252
+ - spec/fixtures/neverland.git/hooks/update.sample
253
+ - spec/fixtures/neverland.git/info/exclude
205
254
  - spec/fixtures/plugins/shared/passing/simple_shared.rb
206
255
  - spec/fixtures/plugins/test_plugins/divide.rb
207
256
  - spec/fixtures/plugins/test_plugins/failing/simple.rb
@@ -224,7 +273,7 @@ licenses:
224
273
  - MIT
225
274
  metadata: {}
226
275
  post_install_message: "\n Thanks for installing the Pre-Git whatever hooker!\n\n
227
- \ If you don't have already, please install the hook:\n\n githoog install --type
276
+ \ If you don't have already, please install the hook:\n\n hoog install --type
228
277
  <GIT_HOOK_TYPE> --plugins_dir <PATH_TO_PLUGINS> --project_dir <PATH_TO_PROJECT>\n
229
278
  \ "
230
279
  rdoc_options: []
@@ -242,15 +291,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
242
291
  version: '0'
243
292
  requirements: []
244
293
  rubyforge_project:
245
- rubygems_version: 2.4.6
294
+ rubygems_version: 2.5.1
246
295
  signing_key:
247
296
  specification_version: 4
248
297
  summary: Plugin based git-pre hook.
249
298
  test_files:
250
299
  - features/failed_hook.feature
300
+ - features/init.feature
251
301
  - features/installing_hook.feature
252
302
  - features/moving_hooks.feature
253
303
  - features/passed_hook.feature
304
+ - features/pull.feature
254
305
  - features/removing_hook.feature
255
306
  - features/support/env.rb
256
307
  - features/support/steps/hooks_steps.rb
@@ -260,6 +311,20 @@ test_files:
260
311
  - spec/fixtures/code/helper.rb
261
312
  - spec/fixtures/config/cucumber/hoogfile.yml
262
313
  - spec/fixtures/config/spec/hoogfile.yml
314
+ - spec/fixtures/neverland.git/HEAD
315
+ - spec/fixtures/neverland.git/config
316
+ - spec/fixtures/neverland.git/description
317
+ - spec/fixtures/neverland.git/hooks/applypatch-msg.sample
318
+ - spec/fixtures/neverland.git/hooks/commit-msg.sample
319
+ - spec/fixtures/neverland.git/hooks/post-update.sample
320
+ - spec/fixtures/neverland.git/hooks/pre-applypatch.sample
321
+ - spec/fixtures/neverland.git/hooks/pre-commit.sample
322
+ - spec/fixtures/neverland.git/hooks/pre-push.sample
323
+ - spec/fixtures/neverland.git/hooks/pre-rebase.sample
324
+ - spec/fixtures/neverland.git/hooks/pre-receive.sample
325
+ - spec/fixtures/neverland.git/hooks/prepare-commit-msg.sample
326
+ - spec/fixtures/neverland.git/hooks/update.sample
327
+ - spec/fixtures/neverland.git/info/exclude
263
328
  - spec/fixtures/plugins/shared/passing/simple_shared.rb
264
329
  - spec/fixtures/plugins/test_plugins/divide.rb
265
330
  - spec/fixtures/plugins/test_plugins/failing/simple.rb
@@ -277,4 +342,3 @@ test_files:
277
342
  - spec/lib/captain_hoog/test/sandbox_spec.rb
278
343
  - spec/spec_helper.rb
279
344
  - spec/support/matchers/be_subclass_of.rb
280
- has_rdoc:
data/bin/githoog DELETED
@@ -1,118 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'thor'
4
- require 'colorize'
5
- require 'pathname'
6
-
7
- class GitHookInstall < Thor
8
- include Thor::Actions
9
-
10
- def self.exit_on_failure?
11
- true
12
- end
13
-
14
- def self.source_root
15
- File.join(File.dirname(__FILE__),"..", "lib", "captain_hoog", "templates")
16
- end
17
-
18
- class_option :type, type: :string, default: 'pre-commit'
19
- class_option :project_dir, type: :string, default: Dir.getwd
20
- class_option :plugins_dir, type: :string, default: Dir.getwd
21
-
22
- map %w[--version -v] => :__print_version
23
-
24
- desc "install","Installs the hook into your Git repository"
25
- def install(*args)
26
- check_if_git_present
27
- check_if_option_present("plugins_dir")
28
- # deprecated:
29
- # "#{options[:plugins_dir]}/#{options[:type]}"
30
- install_hook({ as: options[:type],
31
- context: {
32
- root_dir: Dir.getwd,
33
- plugins_dir: options[:plugins_dir],
34
- project_dir: options[:project_dir]
35
- }
36
- })
37
- puts "Installed hook as #{options[:type]} hook".green
38
- end
39
-
40
- desc "remove", "Removes a hook from your Git repository"
41
- def remove(*args)
42
- check_if_git_present
43
- remove_hook(as: options[:type])
44
- puts "The #{options[:type]} hook is removed.".green
45
- end
46
-
47
- option :from, type: :string, required: true
48
- option :to, type: :string, required: true
49
- desc "move", "Moves a hook from type to another"
50
- def move(*args)
51
- check_if_git_present
52
- if options[:from] == options[:to]
53
- puts "--from and --to arguments are the same".red
54
- raise Thor::Error
55
- else
56
- move_hook(options)
57
- puts "The #{options[:from]} hook is moved to #{options[:to]} hook.".green
58
- end
59
- end
60
-
61
- desc "version, -v", "Prints out the version"
62
- def __print_version
63
- puts CaptainHoog::VERSION
64
- end
65
-
66
- private
67
-
68
- def is_git_repository?
69
- File.exists?(File.join(Dir.getwd, ".git"))
70
- end
71
-
72
- def install_hook(config)
73
- opts = config[:context]
74
- opts[:type] = config[:as]
75
- copy_config_file(opts)
76
- template("install.erb",File.join(hooks_dir, config[:as]), opts)
77
- FileUtils.chmod(0755,File.join(hooks_dir, config[:as]))
78
- end
79
-
80
- def remove_hook(config)
81
- FileUtils.rm_rf(File.join(hooks_dir, config[:as]))
82
- end
83
-
84
- def move_hook(config)
85
- from = File.join(hooks_dir, config[:from])
86
- to = File.join(hooks_dir, config[:to])
87
- FileUtils.mv(from, to)
88
- end
89
-
90
- def hooks_dir
91
- git_dir.join(".git", "hooks")
92
- end
93
-
94
- def git_dir
95
- Pathname.new(Dir.getwd)
96
- end
97
-
98
- def check_if_git_present
99
- if not is_git_repository?
100
- puts "I can't detect a Git repository".red
101
- raise Thor::Error
102
- end
103
- end
104
-
105
- def check_if_option_present(type)
106
- unless options.has_key?(type)
107
- puts "No value provided for required options '--#{type}'".red
108
- raise Thor::Error
109
- end
110
- end
111
-
112
- def copy_config_file(opts={})
113
- template('hoogfile.erb', git_dir.join('hoogfile.yml'), opts)
114
- end
115
-
116
- end
117
-
118
- GitHookInstall.start(ARGV)