legit 0.0.9 → 0.0.10
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.
- data/README.md +1 -0
- data/legit.gemspec +1 -0
- data/lib/legit/version.rb +1 -1
- data/lib/legit.rb +13 -9
- data/lib/legit_helper.rb +5 -20
- data/test/legit_test.rb +40 -7
- data/test/test_helper.rb +3 -0
- metadata +19 -3
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Legit
|
2
2
|
|
3
3
|
[](https://travis-ci.org/dillonkearns/legit)
|
4
|
+
[](https://coveralls.io/r/dillonkearns/legit)
|
4
5
|
[](http://badge.fury.io/rb/legit)
|
5
6
|
[](https://gemnasium.com/dillonkearns/legit)
|
6
7
|
[](https://codeclimate.com/github/dillonkearns/legit)
|
data/legit.gemspec
CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |gem|
|
|
23
23
|
gem.add_development_dependency "guard-minitest"
|
24
24
|
gem.add_development_dependency "growl"
|
25
25
|
gem.add_development_dependency "rb-fsevent"
|
26
|
+
gem.add_development_dependency "coveralls"
|
26
27
|
|
27
28
|
gem.add_runtime_dependency "thor", "~> 0.17.0"
|
28
29
|
gem.add_runtime_dependency "rugged", "0.17.0.b7" # need version 0.17 for a bug accessing Rugged::Repo.config in 0.16
|
data/lib/legit/version.rb
CHANGED
data/lib/legit.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'legit_helper'
|
2
|
-
require 'thor'
|
3
2
|
|
4
3
|
module Legit
|
5
4
|
class CLI < Thor
|
5
|
+
include Thor::Actions
|
6
|
+
|
6
7
|
desc "log [ARGS]", "print a graph-like log"
|
7
8
|
method_option :me, :type => :boolean, :desc => 'Only include my commits'
|
8
9
|
def log(*args)
|
@@ -19,14 +20,17 @@ module Legit
|
|
19
20
|
desc "catch-todos [TODO_FORMAT]", "Abort commit if any todos in TODO_FORMAT found"
|
20
21
|
method_option :enable, :type => :boolean, :desc => 'Enable todo checking'
|
21
22
|
method_option :disable, :type => :boolean, :desc => 'Disable todo checking'
|
23
|
+
method_option :warn, :type => :boolean, :desc => 'Turn on warn mode'
|
22
24
|
def catch_todos(todo_format = "TODO")
|
23
25
|
if options[:enable]
|
24
|
-
repo.config.delete('hooks.
|
26
|
+
repo.config.delete('hooks.catch-todos-mode')
|
25
27
|
elsif options[:disable]
|
26
|
-
repo.config['hooks.
|
28
|
+
repo.config['hooks.catch-todos-mode'] = 'disable'
|
29
|
+
elsif options[:warn]
|
30
|
+
repo.config['hooks.catch-todos-mode'] = 'warn'
|
27
31
|
else
|
28
|
-
if repo.config['hooks.
|
29
|
-
|
32
|
+
if repo.config['hooks.catch-todos-mode'] == 'disable'
|
33
|
+
say("[pre-commit hook] ignoring todos. Re-enable with `legit catch-todos --enable`", :yellow)
|
30
34
|
else
|
31
35
|
run_catch_todos(todo_format)
|
32
36
|
end
|
@@ -48,19 +52,19 @@ module Legit
|
|
48
52
|
|
49
53
|
private
|
50
54
|
def repo
|
51
|
-
@repo ||= Rugged::Repository.new(
|
55
|
+
@repo ||= Rugged::Repository.new(Rugged::Repository.discover)
|
52
56
|
end
|
53
57
|
|
54
58
|
def run_catch_todos(todo_format)
|
55
59
|
if todos_staged?(todo_format)
|
56
|
-
if
|
60
|
+
if repo.config['hooks.catch-todos-mode'] == 'warn'
|
57
61
|
exit 1 unless yes?("[pre-commit hook] Found staged `#{todo_format}`s. Do you still want to continue?", :yellow)
|
58
62
|
else
|
59
|
-
|
63
|
+
say("[pre-commit hook] Aborting commit... found staged `#{todo_format}`s.", :red)
|
60
64
|
exit 1
|
61
65
|
end
|
62
66
|
else
|
63
|
-
|
67
|
+
say("[pre-commit hook] Success: No `#{todo_format}`s staged.", :green)
|
64
68
|
end
|
65
69
|
end
|
66
70
|
end
|
data/lib/legit_helper.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rugged'
|
2
|
+
require 'thor'
|
2
3
|
|
3
4
|
LOG_BASE_COMMAND = "git log --pretty=format:'%C(yellow)%h%Creset%C(bold cyan)%d%Creset %s %Cgreen(%cr)%Creset %C(bold magenta) <%an>%Creset' --graph --abbrev-commit --date=relative"
|
4
5
|
|
@@ -38,26 +39,10 @@ def delete_remote_branch!(branch_name)
|
|
38
39
|
end
|
39
40
|
|
40
41
|
def run_command(command)
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
def show(message, type = :success)
|
46
|
-
color =
|
47
|
-
case type
|
48
|
-
when :success
|
49
|
-
:green
|
50
|
-
when :warning
|
51
|
-
:red
|
52
|
-
when :low_warning
|
53
|
-
:yellow
|
54
|
-
when :normal
|
55
|
-
:white
|
56
|
-
else
|
57
|
-
raise 'Unknown prompt type'
|
58
|
-
end
|
59
|
-
|
60
|
-
say(message, color)
|
42
|
+
options = {
|
43
|
+
:verbose => ENV.has_key?('LEGIT_DEBUG')
|
44
|
+
}
|
45
|
+
run(command, options)
|
61
46
|
end
|
62
47
|
|
63
48
|
def todos_staged?(todo_format)
|
data/test/legit_test.rb
CHANGED
@@ -24,20 +24,53 @@ describe Legit::CLI do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
describe 'legit catch-todos' do
|
27
|
-
it "calls exit 1 when TODOs staged but not
|
27
|
+
it "calls exit 1 when TODOs staged but not disabled" do
|
28
28
|
Legit::CLI.any_instance.expects(:todos_staged?).with('TODO').returns(true)
|
29
29
|
Legit::CLI.any_instance.expects(:exit).with(1)
|
30
|
-
Legit::CLI.any_instance.expects(:
|
31
|
-
Legit::CLI.start(
|
32
|
-
|
33
|
-
Legit::CLI.start('catch-todos --disable'.split(' '))
|
34
|
-
Legit::CLI.any_instance.expects(:exit).never
|
30
|
+
Legit::CLI.any_instance.expects(:say).with("[pre-commit hook] Aborting commit... found staged `TODO`s.", :red)
|
31
|
+
Legit::CLI.start('catch-todos'.split(' '))
|
35
32
|
end
|
36
33
|
|
37
34
|
it "doesn't call exit 1 when no TODOs staged" do
|
38
35
|
Legit::CLI.any_instance.expects(:todos_staged?).with('TODO').returns(false)
|
39
36
|
Legit::CLI.any_instance.expects(:exit).never
|
40
|
-
Legit::CLI.any_instance.expects(:
|
37
|
+
Legit::CLI.any_instance.expects(:say).with("[pre-commit hook] Success: No `TODO`s staged.", :green)
|
38
|
+
Legit::CLI.start('catch-todos'.split(' '))
|
39
|
+
end
|
40
|
+
|
41
|
+
it "removes catch-todos-mode when called with --enable" do
|
42
|
+
config_mock = mock('config')
|
43
|
+
config_mock.expects(:delete).with('hooks.catch-todos-mode')
|
44
|
+
Legit::CLI.any_instance.stubs(:repo => stub({ :config => config_mock }))
|
45
|
+
Legit::CLI.start('catch-todos --enable'.split(' '))
|
46
|
+
end
|
47
|
+
|
48
|
+
it "sets catch-todos-mode to disable when called with --disable" do
|
49
|
+
config_mock = mock('config')
|
50
|
+
config_mock.expects(:[]=).with('hooks.catch-todos-mode', 'disable')
|
51
|
+
Legit::CLI.any_instance.stubs(:repo => stub({ :config => config_mock }))
|
52
|
+
Legit::CLI.start('catch-todos --disable'.split(' '))
|
53
|
+
end
|
54
|
+
|
55
|
+
it "sets catch-todos-mode to warn when called with --warn" do
|
56
|
+
config_mock = mock('config')
|
57
|
+
config_mock.expects(:[]=).with('hooks.catch-todos-mode', 'warn')
|
58
|
+
Legit::CLI.any_instance.stubs(:repo => stub({ :config => config_mock }))
|
59
|
+
Legit::CLI.start('catch-todos --warn'.split(' '))
|
60
|
+
end
|
61
|
+
|
62
|
+
it "skips catch-todos when disabled" do
|
63
|
+
stub_config('hooks.catch-todos-mode' => 'disable')
|
64
|
+
Legit::CLI.any_instance.expects(:run_catch_todos).never
|
65
|
+
Legit::CLI.any_instance.expects(:say).with("[pre-commit hook] ignoring todos. Re-enable with `legit catch-todos --enable`", :yellow)
|
66
|
+
Legit::CLI.start('catch-todos'.split(' '))
|
67
|
+
end
|
68
|
+
|
69
|
+
it "have exit status of 0 in warn mode when positive response" do
|
70
|
+
stub_config('hooks.catch-todos-mode' => 'warn')
|
71
|
+
Legit::CLI.any_instance.expects(:todos_staged?).returns(true)
|
72
|
+
Legit::CLI.any_instance.expects(:exit).never
|
73
|
+
Legit::CLI.any_instance.expects(:yes?).with("[pre-commit hook] Found staged `TODO`s. Do you still want to continue?", :yellow).returns(true)
|
41
74
|
Legit::CLI.start('catch-todos'.split(' '))
|
42
75
|
end
|
43
76
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: legit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -123,6 +123,22 @@ dependencies:
|
|
123
123
|
- - ! '>='
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: coveralls
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
126
142
|
- !ruby/object:Gem::Dependency
|
127
143
|
name: thor
|
128
144
|
requirement: !ruby/object:Gem::Requirement
|
@@ -198,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
198
214
|
version: '0'
|
199
215
|
segments:
|
200
216
|
- 0
|
201
|
-
hash:
|
217
|
+
hash: 3336823418665542283
|
202
218
|
requirements: []
|
203
219
|
rubyforge_project:
|
204
220
|
rubygems_version: 1.8.23
|