captain_hoog 1.1.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 20706e2075b81505658a78f84f2097446876230d
4
- data.tar.gz: 96c4216e0d8100cb9ce7025838f86ee8ab4f1dcb
3
+ metadata.gz: 71c7f0878efebe417bb2f84528cea22126380a8b
4
+ data.tar.gz: 467d29984360c62cf5d2a08b7b68d4f13d588515
5
5
  SHA512:
6
- metadata.gz: 5a180f98657cccebf00748a150a86cac43200cf5a425e76573d1baa10f8a6408fc15f73e2daa40f1df0d9aef123cc29a4aa793f6bd342e66d45bdac2b614dfdb
7
- data.tar.gz: b7bbbce673f95bfbc2d15591b9de576d988f811b75b4a33854c748bc95ff9a9ad14335ee74d427892de4a156a2b2efcee8150e2115e0afe9aac40f05617dd145
6
+ metadata.gz: 8ca444b46bf7e7a619892390562f54b7e49c9da97084e9c44ef8402248c74f53ad246051753aed683663be66a6216b8f7b5d830e74255532a4ffd7d73685d50c
7
+ data.tar.gz: a34a23f80e408a08d2ada2d1ce1b620e676648cc8fcaf9283b8792c65f307ab2ff490a596d1cf0ac30a8db553bf8bd9bc46b43da86529b9a8b510ee5a11206b7
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
1
+ source 'http://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in captain_hoog.gemspec
4
4
  gemspec
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # CaptainHoog
2
2
 
3
- [![Build Status](https://travis-ci.org/GateprotectGmbH/captain_hoog.svg)](https://travis-ci.org/GateprotectGmbH/captain_hoog)
3
+ [![Build Status](https://travis-ci.org/GateprotectGmbH/captain_hoog.svg)](https://travis-ci.org/GateprotectGmbH/captain_hoog) [![Code Climate](https://codeclimate.com/github/GateprotectGmbH/captain_hoog/badges/gpa.svg)](https://codeclimate.com/github/GateprotectGmbH/captain_hoog)
4
4
 
5
5
  Okay. That's not such a funny gem name. But it's a reference to Git and the subject
6
6
  of the gem: the Git Hooks.
@@ -26,10 +26,14 @@ Or install it yourself as:
26
26
  ### Install the hook
27
27
 
28
28
  ```
29
- githoog install --type <GIT_HOOK_TYPE> --plugins_dir <PATH_TO_PLUGINS> --project_dir <PATH_TO_PROJECT>
29
+ hoog install --type <GIT_HOOK_TYPE> --plugins_dir <PATH_TO_PLUGINS> --project_dir <PATH_TO_PROJECT>
30
30
  ```
31
31
 
32
+ Captain Hoog will install also a global ```.hoog``` directory in ```$HOME```. It will
33
+ also pull the default hookins. If you don't want to have this pulled, use the ```--skip-hookins``` flags.
34
+
32
35
  **Please note:** ```<PATH_TO_PLUGINS>``` and ```<PATH_TO_PROJECT>``` must be given as absolute paths.
36
+ ```<PATH_TO_PLUGINS>``` and ```<PATH_TO_PROJECT>``` are also optional.
33
37
  Also make sure to run this from your git repository's root folder.
34
38
 
35
39
  ```GIT_HOOK_TYPE``` may be something like this
@@ -60,7 +64,7 @@ _A note about plugin directories:_ To have more than one plugin directory used,
60
64
  Remove a hook by using the
61
65
 
62
66
  ```
63
- githoog remove --type <GIT_HOOK_TYPE>
67
+ hoog remove --type <GIT_HOOK_TYPE>
64
68
  ```
65
69
 
66
70
  command.
@@ -126,6 +130,10 @@ git.describe 'sample' do |pre|
126
130
 
127
131
  pre.message do
128
132
  # Define a message string here that is shown if the test fails.
133
+ # The message is printed out in red per default. If you don't want
134
+ # a color pass color: :none to the helper method. Or if you want a
135
+ # specific color, the color as symbol:
136
+ # pre.message(color: :none) do ....
129
137
  end
130
138
 
131
139
  end
@@ -165,6 +173,20 @@ end
165
173
 
166
174
  ```
167
175
 
176
+ Within all expressions you can use the ```env``` variable which provides you the
177
+ context the plugin is run in:
178
+
179
+ ```rb
180
+ git.describe 'output the plugin context' do |pre|
181
+
182
+ pre.run do
183
+ puts env.context # might be 'pre-commit, pre-push etc ...
184
+ end
185
+
186
+ end
187
+
188
+ ```
189
+
168
190
  **Plugin file structure**
169
191
 
170
192
  A common way to organize plugins is:
@@ -197,22 +219,22 @@ end
197
219
 
198
220
  ## Test Support
199
221
 
200
- ### Sandbox
222
+ ### Sandbox
201
223
 
202
224
  For testing purposes, Captain Hoog uses some kind of sandboxing. You're able to use the sandbox directly (you have to do this by now for any other test frameworks than RSpec).
203
225
 
204
- Using the sandbox is easy:
226
+ Using the sandbox is easy:
205
227
 
206
228
  ```ruby
207
229
  sandbox = CaptainHoog::Test::Sandbox.new(plugin_code, cfg)
208
230
  sandbox.run
209
231
  # then have full access to the plugin by using sandbox.plugin
210
- ```
232
+ ```
211
233
 
212
- You have to pass the plugin as String or File object and a configuration hash to the sandbox.
234
+ You have to pass the plugin as String or File object and a configuration hash to the sandbox.
213
235
  The configuration hash might consist of a global (the ```env```) and a plugin specific configuration (marked by using the plugins name as key).
214
236
 
215
- Example:
237
+ Example:
216
238
 
217
239
  ```rb
218
240
  plugin_code = <<-PLUGIN
@@ -245,11 +267,11 @@ cfg = {
245
267
  sandbox = CaptainHoog::Test::Sandbox.new(plugin_code, cfg)
246
268
  sandbox.run
247
269
  sandbox.plugin.result[:test] # => true
248
- sandbox.plugin.foo_helper # => 12
270
+ sandbox.plugin.foo_helper # => 12
249
271
  sandbox.plugin.result[:message] # => Fun
250
272
  ```
251
273
 
252
- **Note** that the sandbox will not provide you some fake file system.
274
+ **Note** that the sandbox will not provide you some fake file system.
253
275
 
254
276
  ### Frameworks
255
277
 
@@ -263,25 +285,25 @@ Require test support by using
263
285
  require 'captain_hoog/test'
264
286
  ```
265
287
 
266
- There is no configuration needed, Captain Hoog will detect if you're using Rspec.
288
+ There is no configuration needed, Captain Hoog will detect if you're using Rspec.
267
289
 
268
- Then - as usual - add a ```describe``` block. Within this block you have access to a block helper:
290
+ Then - as usual - add a ```describe``` block. Within this block you have access to a block helper:
269
291
 
270
292
  ```rb
271
- with_plugin :<PLUGIN_NAME>, config: <HASH>, silence: <true|false> do
293
+ with_plugin :<PLUGIN_NAME>, config: <HASH>, silence: <true|false> do
272
294
  # ....
273
295
  end
274
296
  ```
275
297
 
276
- |Argument| Description|
298
+ |Argument| Description|
277
299
  |:-------|:-----------|
278
300
  |PLUGIN_NAME | Plugin - as String or File object (given as a ```let``` or method) |
279
301
  |config | plugin configuration, see **Sandbox** section for details. |
280
302
  |silence | Truthy or falsy value, silences the plugin output |
281
303
 
282
- With ```with_plugin``` you have full access to the Captain Hoog plugin by using ```plugin```.
304
+ With ```with_plugin``` you have full access to the Captain Hoog plugin by using ```plugin```.
283
305
 
284
- A full example:
306
+ A full example:
285
307
 
286
308
  ```rb
287
309
  require 'rspec'
@@ -332,7 +354,7 @@ describe 'Test for hook' do
332
354
  end
333
355
  ```
334
356
 
335
- ### Other Test Frameworks (MiniTest, TestUnit ...)
357
+ ### Other Test Frameworks (MiniTest, TestUnit ...)
336
358
 
337
359
  You have to use the sandbox directly. See an example using MiniTest below.
338
360
 
@@ -383,6 +405,6 @@ end
383
405
 
384
406
  ## Last stuff
385
407
 
386
- Init and written by Daniel Schmidt (daniel.schmidt@gateprotect.com)
408
+ Init and written by Daniel Schmidt (daniel-a.schmidt@rohde-schwarz.com)
387
409
 
388
410
  Image "Captain Hook" © 2012 Brian Patterson
data/bin/hoog ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'captain_hoog'
4
+
5
+ CaptainHoog::Cli::Hoog.start(ARGV)
data/captain_hoog.gemspec CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
16
16
 
17
17
  If you don't have already, please install the hook:
18
18
 
19
- githoog install --type <GIT_HOOK_TYPE> --plugins_dir <PATH_TO_PLUGINS> \
19
+ hoog install --type <GIT_HOOK_TYPE> --plugins_dir <PATH_TO_PLUGINS> \
20
20
  --project_dir <PATH_TO_PROJECT>
21
21
  }
22
22
  spec.required_ruby_version = '>= 2.0'
@@ -30,11 +30,13 @@ Gem::Specification.new do |spec|
30
30
  spec.add_runtime_dependency "colorize", '~> 0.7', '>= 0.7.3'
31
31
  spec.add_runtime_dependency "thor", '~> 0.19', '>= 0.19.1'
32
32
  spec.add_runtime_dependency "terminal-table", '~> 1.4.5'
33
+ spec.add_runtime_dependency "git", '~> 1.2.9.1'
33
34
 
34
35
  spec.add_development_dependency "bundler", "~> 1.6"
35
36
  spec.add_development_dependency "rake"
36
37
  spec.add_development_dependency "rspec"
37
38
  spec.add_development_dependency "cucumber"
38
- spec.add_development_dependency "aruba"
39
+ spec.add_development_dependency "aruba", "0.6.1"
39
40
  spec.add_development_dependency "minitest"
41
+ spec.add_development_dependency "pry"
40
42
  end
@@ -0,0 +1,16 @@
1
+ Feature: Init a Captain Hoog environment
2
+ In order to bootstrap a Captain Hoog environment
3
+ As a developer
4
+ I want to init the environment with a init script
5
+
6
+ Background:
7
+ Given I run the init script with a custom home path
8
+
9
+ Scenario: Not having the environment bootstraped before
10
+ Then the init script outputs "Initializing treasury"
11
+ Then it should create a .hoog directory
12
+ And inside the .hoog directory a treasury directory exists
13
+
14
+ Scenario: Having the environment already bootstrapped
15
+ Given I run the init script with a custom home path
16
+ Then the init script outputs "Treasury already exists. Skipping."
@@ -0,0 +1,11 @@
1
+ Feature: Pull a plugin repository into the treasury
2
+ In order to use plugins from a global location
3
+ As a developer
4
+ I want to add plugins to the treasury
5
+
6
+ Background:
7
+ Given I run the init script with a custom home path
8
+
9
+ Scenario: Pulling an existing repository
10
+ Given I pull a plugin repository into the treasury
11
+ Then the repository is installed in the treasury
@@ -2,7 +2,6 @@ require 'cucumber'
2
2
  require 'aruba/cucumber'
3
3
 
4
4
  require 'rspec/expectations'
5
-
6
5
  SPEC_PATH = File.expand_path(File.join(File.dirname(__FILE__),
7
6
  "..",
8
7
  "..",
@@ -10,8 +9,9 @@ SPEC_PATH = File.expand_path(File.join(File.dirname(__FILE__),
10
9
 
11
10
  FIXTURES_PATH = File.join(SPEC_PATH, "fixtures")
12
11
  HOOK_SPEC_PATH = File.join(SPEC_PATH, "hooks")
13
-
12
+
14
13
  Before do
14
+ @aruba_timeout_seconds = 5
15
15
  $git_fixture_dir_exists ||= false
16
16
  @dirs = [FIXTURES_PATH]
17
17
  ["no_git", "with_git"].each do |dir|
@@ -30,6 +30,7 @@ end
30
30
 
31
31
 
32
32
  After do
33
+ FileUtils.rm_rf(File.join(FIXTURES_PATH, '.hoog'))
33
34
  FileUtils.rm_rf(File.join(FIXTURES_PATH, 'with_git', 'hoogfile.yml'))
34
35
  %w{ pre-commit
35
36
  pre-push
@@ -44,6 +45,6 @@ After do
44
45
  ".git",
45
46
  "hooks",
46
47
  hook_type))
47
- FileUtils.rm_rf(HOOK_SPEC_PATH)
48
+ FileUtils.rm_rf(HOOK_SPEC_PATH)
48
49
  end
49
50
  end
@@ -1,23 +1,18 @@
1
1
  When(/^I run a commit hook that might succeeds$/) do
2
- hook_path = File.expand_path(File.join(File.dirname(__FILE__),
3
- "..",
4
- "..",
5
- "..",
6
- "spec",
7
- "fixtures"))
8
2
  FileUtils.chdir(hook_path)
9
-
10
3
  end
11
4
 
12
5
  When(/^I run the install script with "(.*?)" type flag$/) do |commit_type|
13
6
  @dir = git_project_path.to_s
14
- run_simple(unescape("ruby #{bin_path}/bin/githoog install --type #{commit_type} --plugins_dir #{@dir}"),
15
- false)
7
+ @cmd = "bundle exec #{bin_path}/bin/#{executable} install --type #{commit_type} "
8
+ @cmd += "--plugins_dir #{@dir}"
9
+ run_simple(unescape(@cmd), false)
16
10
  end
17
11
 
18
12
  When(/^I run the remove script with "(.*?)" type flag$/) do |commit_type|
19
- run_simple(unescape("ruby #{bin_path}/bin/githoog remove --type #{commit_type} --plugins_dir /home"),
20
- false)
13
+ @cmd = "bundle exec #{bin_path}/bin/#{executable} remove --type #{commit_type} "
14
+ @cmd += "--plugins_dir /home"
15
+ run_simple(unescape(@cmd),false)
21
16
  end
22
17
 
23
18
  Given(/^I am in a directory that isnt a Git repository$/) do
@@ -51,12 +46,12 @@ Then(/^I should see the current version$/) do
51
46
  end
52
47
 
53
48
  When(/^I run the move script with "(.*?)" from flag and "(.*?)" to flag$/) do |from, to|
54
- cmd = "ruby #{bin_path}/bin/githoog move --from #{from} --to #{to}"
49
+ cmd = "bundle exec #{bin_path}/bin/#{executable} move --from #{from} --to #{to}"
55
50
  run_simple(unescape(cmd), false)
56
51
  end
57
52
 
58
53
  When(/^I run the install script without "(.*?)" flag$/) do |type_flag|
59
- cmd = "ruby #{bin_path}/bin/githoog install"
54
+ cmd = "bundle exec #{bin_path}/bin/#{executable} install"
60
55
  run_simple(unescape(cmd),false)
61
56
  end
62
57
 
@@ -102,3 +97,41 @@ Then(/^I should see the test is passing with "([^"]*)" example and "([^"]*)" fai
102
97
  expect(output).to match(/\d+ runs, #{success_count} assertions, #{failure_count} failures/)
103
98
  end
104
99
  end
100
+
101
+ Given(/^I run the init script with a custom home path$/) do
102
+ @cmd = "bundle exec #{bin_path}/bin/#{executable} init --home #{hook_path}"
103
+ run_simple(unescape(@cmd),false)
104
+ end
105
+
106
+ Then(/^it should create a \.hoog directory$/) do
107
+ expect(File.exists?(File.join(hook_path, '.hoog'))).to be true
108
+ end
109
+
110
+ Then(/^inside the \.hoog directory a treasury directory exists$/) do
111
+ expect(File.exists?(treasury_path)).to be true
112
+ end
113
+
114
+ Then(/^the init script outputs "(.*?)"$/) do |line|
115
+ expect(output_from(@cmd)).to include line
116
+ end
117
+
118
+ Then(/^I get this scripts output$/) do
119
+ puts output_from(@cmd)
120
+ end
121
+
122
+ When(/^I run a hoog named "(.*?)"$/) do |cmd|
123
+ @cmd = cmd
124
+ run_simple(unescape(@cmd), false)
125
+ end
126
+
127
+ Given(/^I pull a plugin repository into the treasury$/) do
128
+ repo_url = hook_git_repo_path
129
+ @cmd = "bundle exec #{bin_path}/bin/#{executable} treasury pull #{repo_url}"
130
+ @cmd += " --home #{treasury_path}"
131
+ run_simple(unescape(@cmd), false)
132
+ end
133
+
134
+ Then(/^the repository is installed in the treasury$/) do
135
+ step "I get this scripts output"
136
+ expect(File.exist?(File.join(treasury_path, 'neverland'))).to be true
137
+ end
@@ -1,6 +1,18 @@
1
1
  require 'pathname'
2
2
 
3
3
  module FileWorld
4
+ def executable
5
+ 'hoog'
6
+ end
7
+
8
+ def hook_path
9
+ File.expand_path(File.join(File.dirname(__FILE__),
10
+ "..",
11
+ "..",
12
+ "spec",
13
+ "fixtures"))
14
+ end
15
+
4
16
  def bin_path
5
17
  File.expand_path(File.join(File.dirname(__FILE__),
6
18
  "..",
@@ -24,6 +36,14 @@ module FileWorld
24
36
  path
25
37
  end
26
38
 
39
+ def treasury_path
40
+ File.join(hook_path, '.hoog', 'treasury')
41
+ end
42
+
43
+ def hook_git_repo_path
44
+ File.join(hook_path, 'neverland.git')
45
+ end
46
+
27
47
  def hook_config_file_path
28
48
  git_project_path.join('hoogfile.yml')
29
49
  end
@@ -41,7 +61,7 @@ module FileWorld
41
61
  "#{name}.rb"))
42
62
  write_file(spec_name, file_content)
43
63
  end
44
-
64
+
45
65
  end
46
66
 
47
67
  World(FileWorld)
@@ -6,6 +6,15 @@ Feature: Testing a hook plugin
6
6
  Scenario: Testing a hook plugin with RSpec
7
7
  Given I wrote a spec "divide_spec" containing:
8
8
  """
9
+ require 'bundler'
10
+ require 'bundler/inline'
11
+
12
+ gemfile do
13
+ gem 'captain_hoog', path: File.expand_path('../../..', __FILE__)
14
+ gem 'rspec'
15
+ gem 'minitest'
16
+ end
17
+
9
18
  require 'rspec'
10
19
  require 'captain_hoog/test'
11
20
 
@@ -60,6 +69,15 @@ Feature: Testing a hook plugin
60
69
  Scenario: Testing a hook plugin with Minitest
61
70
  Given I wrote a test "divide_test" containing:
62
71
  """
72
+ require 'bundler'
73
+ require 'bundler/inline'
74
+
75
+ gemfile do
76
+ gem 'captain_hoog', path: File.expand_path('../../..', __FILE__)
77
+ gem 'rspec'
78
+ gem 'minitest'
79
+ end
80
+
63
81
  gem 'minitest'
64
82
  require 'minitest/autorun'
65
83
  require 'minitest/unit'
@@ -1,8 +1,8 @@
1
1
  Feature: Getting the gems version number printed to stdout
2
- In order to get the version printed out to stdout
2
+ In order to get the version printed out to stdout
3
3
  As developer
4
- I want to type in githoog --version to know about the current version
4
+ I want to type in hoog --version to know about the current version
5
5
 
6
6
  Scenario: Getting the version printed to stdout
7
- Given I type in "githoog --version"
7
+ Given I type in "hoog --version"
8
8
  Then I should see the current version
@@ -0,0 +1,26 @@
1
+ module CaptainHoog
2
+ module Cli
3
+ module Git
4
+ module_function
5
+
6
+ def is_git_repository?
7
+ File.exist?(File.join(Dir.getwd, ".git"))
8
+ end
9
+
10
+ def hooks_dir
11
+ git_dir.join(".git", "hooks")
12
+ end
13
+
14
+ def git_dir
15
+ Pathname.new(Dir.getwd)
16
+ end
17
+
18
+ def check_if_git_present
19
+ if not is_git_repository?
20
+ puts "I can't detect a Git repository".red
21
+ raise Thor::Error
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end