legit 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +4 -0
- data/Guardfile +5 -0
- data/README.md +2 -1
- data/Rakefile +7 -0
- data/bin/legit +1 -1
- data/legit.gemspec +7 -1
- data/lib/legit/version.rb +1 -1
- data/lib/legit.rb +49 -61
- data/lib/legit_helper.rb +32 -8
- data/test/legit_test.rb +86 -0
- data/test/test_helper.rb +7 -0
- metadata +94 -8
data/.travis.yml
ADDED
data/Guardfile
ADDED
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# Legit
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/dillonkearns/legit.png)](https://travis-ci.org/dillonkearns/legit)
|
3
4
|
[![Gem Version](https://fury-badge.herokuapp.com/rb/legit.png)](http://badge.fury.io/rb/legit)
|
4
5
|
[![Dependency Status](https://gemnasium.com/dillonkearns/legit.png)](https://gemnasium.com/dillonkearns/legit)
|
5
|
-
[![Code Climate](https://codeclimate.com/
|
6
|
+
[![Code Climate](https://codeclimate.com/github/dillonkearns/dotfile-linker.png)](https://codeclimate.com/github/dillonkearns/dotfile-linker)
|
6
7
|
|
7
8
|
## Installation
|
8
9
|
```bash
|
data/Rakefile
CHANGED
data/bin/legit
CHANGED
data/legit.gemspec
CHANGED
@@ -17,7 +17,13 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.required_ruby_version = ">=1.8.7"
|
18
18
|
|
19
19
|
gem.add_development_dependency "rake", "~> 10.0.3"
|
20
|
-
gem.
|
20
|
+
gem.add_development_dependency "minitest", "~> 4.6.2"
|
21
|
+
gem.add_development_dependency "minitest-reporters"
|
22
|
+
gem.add_development_dependency "mocha", "~> 0.13.2"
|
23
|
+
gem.add_development_dependency "guard-minitest"
|
24
|
+
gem.add_development_dependency "growl"
|
25
|
+
gem.add_development_dependency "rb-fsevent"
|
26
|
+
|
21
27
|
gem.add_runtime_dependency "thor", "~> 0.17.0"
|
22
28
|
gem.add_runtime_dependency "rugged", "0.17.0.b7" # need version 0.17 for a bug accessing Rugged::Repo.config in 0.16
|
23
29
|
end
|
data/lib/legit/version.rb
CHANGED
data/lib/legit.rb
CHANGED
@@ -1,79 +1,67 @@
|
|
1
1
|
require 'legit_helper'
|
2
2
|
require 'thor'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
4
|
+
module Legit
|
5
|
+
class CLI < Thor
|
6
|
+
desc "log [ARGS]", "print a graph-like log"
|
7
|
+
method_option :me, :type => :boolean, :desc => 'Only include my commits'
|
8
|
+
def log(*args)
|
9
|
+
command = []
|
10
|
+
command << LOG_BASE_COMMAND
|
11
|
+
command << "--author='#{repo.config['user.name']}'" if options[:me]
|
12
|
+
args.each do |arg|
|
13
|
+
command << arg
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
16
|
+
run_command(command.join(' '))
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
else
|
27
|
-
if repo.config['hooks.ignore-todos'] == 'true'
|
28
|
-
show("[pre-commit hook] ignoring todos. Re-enable with `legit catch-todos --enable`", :low_warning)
|
19
|
+
desc "catch-todos [TODO_FORMAT]", "Abort commit if any todos in TODO_FORMAT found"
|
20
|
+
method_option :enable, :type => :boolean, :desc => 'Enable todo checking'
|
21
|
+
method_option :disable, :type => :boolean, :desc => 'Disable todo checking'
|
22
|
+
def catch_todos(todo_format = "TODO")
|
23
|
+
if options[:enable]
|
24
|
+
repo.config.delete('hooks.ignore-todos')
|
25
|
+
elsif options[:disable]
|
26
|
+
repo.config['hooks.ignore-todos'] = true
|
29
27
|
else
|
30
|
-
|
28
|
+
if repo.config['hooks.ignore-todos'] == 'true'
|
29
|
+
show("[pre-commit hook] ignoring todos. Re-enable with `legit catch-todos --enable`", :low_warning)
|
30
|
+
else
|
31
|
+
run_catch_todos(todo_format)
|
32
|
+
end
|
31
33
|
end
|
32
34
|
end
|
33
|
-
end
|
34
|
-
|
35
|
-
desc "bisect BAD GOOD COMMAND", "Find the first bad commit by running COMMAND, using GOOD and BAD as the first known good and bad commits"
|
36
|
-
def bisect(bad, good, *command_args)
|
37
|
-
command = command_args.join(' ')
|
38
|
-
run_command("git bisect start #{bad} #{good}")
|
39
|
-
run_command("git bisect run #{command}")
|
40
|
-
run_command("git bisect reset")
|
41
|
-
end
|
42
35
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
else
|
50
|
-
show("Force delete branch #{branch_name}? (y/n)", :warning)
|
51
|
-
if STDIN.gets.chomp =~ /^y/
|
52
|
-
run_command("git branch -D #{branch_name}")
|
53
|
-
delete_remote_branch(branch_name)
|
54
|
-
else
|
55
|
-
puts "Abort. #{branch_name} not deleted"
|
56
|
-
end
|
36
|
+
desc "bisect BAD GOOD COMMAND", "Find the first bad commit by running COMMAND, using GOOD and BAD as the first known good and bad commits"
|
37
|
+
def bisect(bad, good, *command_args)
|
38
|
+
command = command_args.join(' ')
|
39
|
+
run_command("git bisect start #{bad} #{good}")
|
40
|
+
run_command("git bisect run #{command}")
|
41
|
+
run_command("git bisect reset")
|
57
42
|
end
|
58
|
-
end
|
59
43
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
44
|
+
desc "delete BRANCH", "Delete BRANCH both locally and remotely"
|
45
|
+
def delete(branch_name)
|
46
|
+
delete_local_branch!(branch_name) || force_delete_local_branch?(branch_name) and delete_remote_branch?(branch_name)
|
47
|
+
end
|
64
48
|
|
65
|
-
|
66
|
-
|
49
|
+
private
|
50
|
+
def repo
|
51
|
+
@repo ||= Rugged::Repository.new('.')
|
52
|
+
end
|
67
53
|
|
68
|
-
|
69
|
-
if
|
70
|
-
|
54
|
+
def run_catch_todos(todo_format)
|
55
|
+
if todos_staged?(todo_format)
|
56
|
+
if options[:warn]
|
57
|
+
exit 1 unless positive_response?("[pre-commit hook] Found staged `#{todo_format}`s. Do you still want to continue?", :warning)
|
58
|
+
else
|
59
|
+
show("[pre-commit hook] Aborting commit... found staged `#{todo_format}`s.", :warning)
|
60
|
+
exit 1
|
61
|
+
end
|
71
62
|
else
|
72
|
-
show("[pre-commit hook]
|
73
|
-
exit 1
|
63
|
+
show("[pre-commit hook] Success: No `#{todo_format}`s staged.", :success)
|
74
64
|
end
|
75
|
-
else
|
76
|
-
show("Success: No #{todo_format}s staged.", :success)
|
77
65
|
end
|
78
66
|
end
|
79
67
|
end
|
data/lib/legit_helper.rb
CHANGED
@@ -1,20 +1,40 @@
|
|
1
|
-
require 'colorize'
|
2
1
|
require 'rugged'
|
3
2
|
|
3
|
+
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
|
+
|
4
5
|
def current_branch
|
5
6
|
system "git rev-parse --abbrev-ref HEAD"
|
6
7
|
end
|
7
8
|
|
8
|
-
def
|
9
|
-
|
9
|
+
def delete_local_branch!(branch_name)
|
10
|
+
run_command("git branch -d #{branch_name}")
|
11
|
+
$?.success?
|
12
|
+
end
|
13
|
+
|
14
|
+
def force_delete_local_branch?(branch_name)
|
15
|
+
if yes?("Force delete branch?", :red)
|
16
|
+
force_delete_local_branch!(branch_name)
|
17
|
+
true
|
18
|
+
else
|
19
|
+
false
|
20
|
+
end
|
10
21
|
end
|
11
22
|
|
12
|
-
def
|
13
|
-
"
|
23
|
+
def force_delete_local_branch!(branch_name)
|
24
|
+
run_command("git branch -D #{branch_name}")
|
14
25
|
end
|
15
26
|
|
16
|
-
def
|
17
|
-
|
27
|
+
def delete_remote_branch?(branch_name)
|
28
|
+
if yes?("Delete branch remotely?", :red)
|
29
|
+
delete_remote_branch!(branch_name)
|
30
|
+
true
|
31
|
+
else
|
32
|
+
false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def delete_remote_branch!(branch_name)
|
37
|
+
system("git push --delete origin #{branch_name}")
|
18
38
|
end
|
19
39
|
|
20
40
|
def run_command(command)
|
@@ -37,9 +57,13 @@ def show(message, type = :success)
|
|
37
57
|
raise 'Unknown prompt type'
|
38
58
|
end
|
39
59
|
|
40
|
-
|
60
|
+
show(message, color)
|
41
61
|
end
|
42
62
|
|
63
|
+
def todos_staged?(todo_format)
|
64
|
+
run_command("git diff --staged | grep '^+' | grep #{todo_format}")
|
65
|
+
$?.success? # grep returns 0 if there is a match
|
66
|
+
end
|
43
67
|
|
44
68
|
def positive_response?(message, type = :normal)
|
45
69
|
show("#{message} (y/n)", type)
|
data/test/legit_test.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
require 'legit'
|
3
|
+
|
4
|
+
describe Legit::CLI do
|
5
|
+
include Mocha::Integration::MiniTest
|
6
|
+
|
7
|
+
before do
|
8
|
+
stub_config
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'legit log' do
|
12
|
+
it "parses --me command and passes through other options" do
|
13
|
+
args = 'log -p --me -n 1'
|
14
|
+
stub_config({ 'user.name' => 'Stubbed Username' })
|
15
|
+
Legit::CLI.any_instance.expects(:run_command).with("#{LOG_BASE_COMMAND} --author='Stubbed Username' -p -n 1")
|
16
|
+
Legit::CLI.start(args.split(' '))
|
17
|
+
end
|
18
|
+
|
19
|
+
it "passes through options that aren't defined by legit log" do
|
20
|
+
args = 'log -p --stat'
|
21
|
+
Legit::CLI.any_instance.expects(:run_command).with("#{LOG_BASE_COMMAND} -p --stat")
|
22
|
+
Legit::CLI.start(args.split(' '))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'legit catch-todos' do
|
27
|
+
it "calls exit 1 when TODOs staged but not when disabled" do
|
28
|
+
Legit::CLI.any_instance.expects(:todos_staged?).with('TODO').returns(true)
|
29
|
+
Legit::CLI.any_instance.expects(:exit).with(1)
|
30
|
+
Legit::CLI.any_instance.expects(:show).with("[pre-commit hook] Aborting commit... found staged `TODO`s.", :warning)
|
31
|
+
Legit::CLI.start(['catch-todos'])
|
32
|
+
|
33
|
+
Legit::CLI.start('catch-todos --disable'.split(' '))
|
34
|
+
Legit::CLI.any_instance.expects(:exit).never
|
35
|
+
end
|
36
|
+
|
37
|
+
it "doesn't call exit 1 when no TODOs staged" do
|
38
|
+
Legit::CLI.any_instance.expects(:todos_staged?).with('TODO').returns(false)
|
39
|
+
Legit::CLI.any_instance.expects(:exit).never
|
40
|
+
Legit::CLI.any_instance.expects(:show).with("[pre-commit hook] Success: No `TODO`s staged.", :success)
|
41
|
+
Legit::CLI.start('catch-todos'.split(' '))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'legit delete' do
|
46
|
+
it 'force deletes branch when user responds yes' do
|
47
|
+
Legit::CLI.any_instance.expects(:delete_local_branch!).with('branch_to_delete').returns(false)
|
48
|
+
Legit::CLI.any_instance.expects(:yes?).with('Force delete branch?', :red).returns(true)
|
49
|
+
Legit::CLI.any_instance.expects(:force_delete_local_branch!).with('branch_to_delete')
|
50
|
+
Legit::CLI.any_instance.expects(:delete_remote_branch?).with('branch_to_delete').returns(false)
|
51
|
+
Legit::CLI.start('delete branch_to_delete'.split(' '))
|
52
|
+
end
|
53
|
+
|
54
|
+
it "doesn't force delete branch when user responds no" do
|
55
|
+
Legit::CLI.any_instance.expects(:delete_local_branch!).with('branch_to_delete').returns(false)
|
56
|
+
Legit::CLI.any_instance.expects(:yes?).with('Force delete branch?', :red).returns(false)
|
57
|
+
Legit::CLI.any_instance.expects(:force_delete_local_branch!).never
|
58
|
+
Legit::CLI.start('delete branch_to_delete'.split(' '))
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'deletes remotely when user responds yes' do
|
62
|
+
Legit::CLI.any_instance.expects(:delete_local_branch!).with('branch_to_delete').returns(true)
|
63
|
+
Legit::CLI.any_instance.expects(:yes?).with('Delete branch remotely?', :red).returns(true)
|
64
|
+
Legit::CLI.start('delete branch_to_delete'.split(' '))
|
65
|
+
end
|
66
|
+
|
67
|
+
it "doesn't delete remotely when user responds no" do
|
68
|
+
Legit::CLI.any_instance.expects(:delete_local_branch!).with('branch_to_delete').returns(true)
|
69
|
+
Legit::CLI.any_instance.expects(:yes?).with('Delete branch remotely?', :red).returns(false)
|
70
|
+
Legit::CLI.start('delete branch_to_delete'.split(' '))
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe 'legit bisect' do
|
75
|
+
command = 'ruby -n my/test/file "/testpattern/"'
|
76
|
+
args = "bisect HEAD HEAD~5 #{command}"
|
77
|
+
Legit::CLI.any_instance.expects(:run_command).with('git bisect start HEAD HEAD~5')
|
78
|
+
Legit::CLI.any_instance.expects(:run_command).with("git bisect run #{command}")
|
79
|
+
Legit::CLI.any_instance.expects(:run_command).with("git bisect reset")
|
80
|
+
Legit::CLI.start(args.split(' '))
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def stub_config(config = {})
|
85
|
+
Legit::CLI.any_instance.stubs(:repo => stub({ :config => config }))
|
86
|
+
end
|
data/test/test_helper.rb
ADDED
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.8
|
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-
|
12
|
+
date: 2013-03-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -28,21 +28,101 @@ dependencies:
|
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 10.0.3
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
31
|
+
name: minitest
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
35
|
- - ~>
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
38
|
-
type: :
|
37
|
+
version: 4.6.2
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 4.6.2
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: minitest-reporters
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: mocha
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.13.2
|
70
|
+
type: :development
|
39
71
|
prerelease: false
|
40
72
|
version_requirements: !ruby/object:Gem::Requirement
|
41
73
|
none: false
|
42
74
|
requirements:
|
43
75
|
- - ~>
|
44
76
|
- !ruby/object:Gem::Version
|
45
|
-
version: 0.
|
77
|
+
version: 0.13.2
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: guard-minitest
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: growl
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: rb-fsevent
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
46
126
|
- !ruby/object:Gem::Dependency
|
47
127
|
name: thor
|
48
128
|
requirement: !ruby/object:Gem::Requirement
|
@@ -85,7 +165,9 @@ extensions: []
|
|
85
165
|
extra_rdoc_files: []
|
86
166
|
files:
|
87
167
|
- .gitignore
|
168
|
+
- .travis.yml
|
88
169
|
- Gemfile
|
170
|
+
- Guardfile
|
89
171
|
- LICENSE
|
90
172
|
- README.md
|
91
173
|
- Rakefile
|
@@ -94,6 +176,8 @@ files:
|
|
94
176
|
- lib/legit.rb
|
95
177
|
- lib/legit/version.rb
|
96
178
|
- lib/legit_helper.rb
|
179
|
+
- test/legit_test.rb
|
180
|
+
- test/test_helper.rb
|
97
181
|
homepage: https://github.com/dillonkearns/legit
|
98
182
|
licenses: []
|
99
183
|
post_install_message:
|
@@ -114,11 +198,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
198
|
version: '0'
|
115
199
|
segments:
|
116
200
|
- 0
|
117
|
-
hash:
|
201
|
+
hash: 1919928434083848105
|
118
202
|
requirements: []
|
119
203
|
rubyforge_project:
|
120
204
|
rubygems_version: 1.8.23
|
121
205
|
signing_key:
|
122
206
|
specification_version: 3
|
123
207
|
summary: A collection of scripts for common git tasks to simplify and improve workflow.
|
124
|
-
test_files:
|
208
|
+
test_files:
|
209
|
+
- test/legit_test.rb
|
210
|
+
- test/test_helper.rb
|