commit_hookr 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/bin/hookr CHANGED
@@ -1,16 +1,68 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require "fileutils"
4
+
5
+ usage_info = "Usage: hookr init [template]"
6
+ usage_info += "\nCurrently your only template option is 'codebase'"
7
+
8
+ working_directory = FileUtils.pwd
9
+ commit_msg_file = "#{working_directory}/.git/hooks/commit-msg"
10
+ hookr_file = "#{working_directory}/.hookr"
11
+
3
12
  if ARGV.size == 0
4
- puts File.read("../README.rdoc")
13
+ puts usage_info
14
+ exit 1
15
+ elsif !File.exist?("#{working_directory}/.git")
16
+ puts "You should do this in the root directory of a Git project."
5
17
  exit 1
6
18
  end
7
19
 
8
- require "fileutils"
9
-
10
- FileUtils.cp("#{File.dirname(__FILE__)}/../lib/templates/commit-msg.rb", "#{FileUtils.pwd}/.git/hooks/commit-msg")
11
- FileUtils.chmod 0755, "#{FileUtils.pwd}/.git/hooks/commit-msg"
12
- unless File.exist?("#{FileUtils.pwd}/.hookr")
13
- FileUtils.cp("#{File.dirname(__FILE__)}/../lib/templates/#{ARGV[0]}.rb", "#{FileUtils.pwd}/.hookr")
20
+ case ARGV[0]
21
+
22
+ when "init"
23
+ case ARGV[1]
24
+ when nil
25
+ puts usage_info
26
+ exit 1
27
+ when "codebase"
28
+ puts "Yo dawg I herd u like commit hooks, so I put some file in ur directories:\n\n"
29
+ unless File.exist?(hookr_file)
30
+ FileUtils.cp "#{File.dirname(__FILE__)}/../lib/templates/#{ARGV[1]}.rb", hookr_file
31
+ puts " added: .hookr"
32
+ else
33
+ puts " exists: .hookr"
34
+ end
35
+ unless File.exist?(commit_msg_file)
36
+ FileUtils.cp "#{File.dirname(__FILE__)}/../lib/templates/commit-msg.rb", commit_msg_file
37
+ puts " added: .git/hooks/commit-msg"
38
+ else
39
+ FileUtils.cp "#{File.dirname(__FILE__)}/../lib/templates/commit-msg.rb", commit_msg_file
40
+ puts " updated: .git/hooks/commit-msg"
41
+ end
42
+ FileUtils.chmod 0755, commit_msg_file
43
+ puts "\n"
44
+ exit 0
45
+ else
46
+ puts "Sorry, the only template available right now is 'codebase'. You can add your own .hookr template, of course."
47
+ exit 1
48
+ end
49
+ when "clear"
50
+ if File.exist?(commit_msg_file) && File.exist?(hookr_file)
51
+ puts "Well then, if it makes you happy...\n\n"
52
+ if File.exist?(hookr_file)
53
+ FileUtils.rm hookr_file
54
+ puts " removed: .hookr"
55
+ end
56
+ if File.exist?(commit_msg_file)
57
+ FileUtils.rm commit_msg_file
58
+ puts " removed: .git/hooks/commit-msg"
59
+ end
60
+ puts "\n"
61
+ exit 0
62
+ else
63
+ puts "There's nothing to clear."
64
+ end
65
+ exit 0
66
+ else
67
+ puts usage_info
14
68
  end
15
-
16
- puts "Yo dawg I herd u like commit hooks, so I put some files in ur directories."
@@ -0,0 +1,46 @@
1
+ Feature: commit_hookr Command Line Interface
2
+ In order to set up interactive Git commit menus
3
+ As a cool developer
4
+ I want to use the hookr command to add and remove commit hooks
5
+
6
+ Background:
7
+ Given a directory named "~/some_project"
8
+ And I cd to "~/some_project"
9
+ And I run "git init"
10
+
11
+ Scenario: Run hookr in a directory that's not a Git project root
12
+ Given I run "rm -rf .git"
13
+ When I run hookr with "init codebase"
14
+ Then I should see "You should do this in the root directory of a Git project."
15
+ And the exit status should be 1
16
+
17
+ Scenario: Run hookr without telling it what to do
18
+ When I run hookr with ""
19
+ Then I should see the usage info
20
+ And the exit status should be 1
21
+
22
+ Scenario: Initialize commit hook
23
+ When I run hookr with "init"
24
+ Then I should see the usage info
25
+ And the exit status should be 1
26
+
27
+ When I run hookr with "init lighthouse"
28
+ Then I should see "Sorry, the only template available right now is 'codebase'."
29
+ And the exit status should be 1
30
+
31
+ When I run hookr with "init codebase"
32
+ Then I should see "Yo dawg I herd u like commit hooks, so I put some file in ur directories:"
33
+ And the exit status should be 0
34
+ And the following files should exist:
35
+ | .hookr |
36
+ | .git/hooks/commit-msg |
37
+
38
+ Scenario: Clear commit hook
39
+ When I run hookr with "init codebase"
40
+ When I run hookr with "clear"
41
+ Then I should see "Well then, if it makes you happy..."
42
+
43
+ Scenario: Clear non-existent commit hook
44
+ Given there are no commit hook files
45
+ When I run hookr with "clear"
46
+ Then I should see "There's nothing to clear."
@@ -0,0 +1,12 @@
1
+ When /^I run hookr with "([^\"]*)"$/ do |command|
2
+ When "I run \"#{File.dirname(__FILE__)}/../../bin/hookr #{command}\""
3
+ end
4
+
5
+ Then /^I should see the usage info$/ do
6
+ Then "I should see \"Usage:\""
7
+ end
8
+
9
+ Given /^there are no commit hook files$/ do
10
+ Given "I run \"rm .hook\""
11
+ And "I run \"rm .git/hooks/commit-msg\""
12
+ end
@@ -1,5 +1,7 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
2
  require 'commit_hookr'
3
+ require 'aruba'
4
+ require 'fileutils'
3
5
 
4
6
  require 'test/unit/assertions'
5
7
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 4
9
- version: 0.1.4
8
+ - 5
9
+ version: 0.1.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Michael Bumann
@@ -53,8 +53,8 @@ extra_rdoc_files:
53
53
  - README.rdoc
54
54
  files:
55
55
  - bin/hookr
56
- - features/commit_hookr.feature
57
- - features/step_definitions/commit_hookr_steps.rb
56
+ - features/cli.feature
57
+ - features/step_definitions/cli_steps.rb
58
58
  - features/support/env.rb
59
59
  - lib/commit_hookr.rb
60
60
  - lib/templates/codebase.rb
@@ -1,9 +0,0 @@
1
- Feature: something something
2
- In order to something something
3
- A user something something
4
- something something something
5
-
6
- Scenario: something something
7
- Given inspiration
8
- When I create a sweet new gem
9
- Then everyone should see how awesome I am
File without changes