legit 0.0.11 → 0.0.13

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 496dfcd5cb7b062ac51f2371e752980fe4104e82
4
+ data.tar.gz: ef4efafa23bd59980490b00997cc92fc9c5b115d
5
+ SHA512:
6
+ metadata.gz: 1f80616786cb2fe52f054131ff0debb1cd1df3b1ef43e1c3a72ce244b670027c2c6f9f1b7c8d701c3477d03b19a45102aef80fde62797c00862d7bb971e0ed95
7
+ data.tar.gz: 058acddbcdd1ba8ec4ea7c2012a32f765ce955b02cce1a76de8a2ac3c0d6adf9ffdbb351abfc9a316395b885f28acf644e72fbe6f374c0c02d5b223a7a26d879
data/legit.gemspec CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |gem|
16
16
 
17
17
  gem.required_ruby_version = ">=1.8.7"
18
18
 
19
- gem.add_development_dependency "rake", "~> 10.0.3"
19
+ gem.add_development_dependency "rake", "~> 10.1.0"
20
20
  gem.add_development_dependency "minitest", "~> 5.0.1"
21
21
  gem.add_development_dependency "mocha", "~> 0.14.0"
22
22
  gem.add_development_dependency "guard-minitest"
@@ -26,6 +26,5 @@ Gem::Specification.new do |gem|
26
26
 
27
27
  gem.add_runtime_dependency "json", "~> 1.8.0"
28
28
  gem.add_runtime_dependency "thor", "~> 0.18.1"
29
- gem.add_runtime_dependency "rugged", "0.18.0.b1" # need >= version 0.17 for a bug accessing Rugged::Repo.config in 0.16
30
-
29
+ gem.add_runtime_dependency "rugged", "~> 0.19.0"
31
30
  end
@@ -0,0 +1,63 @@
1
+ require 'rugged'
2
+ require 'thor'
3
+
4
+ module Legit
5
+ module Helpers
6
+ 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"
7
+
8
+ def repo
9
+ @repo ||= Rugged::Repository.new(Rugged::Repository.discover)
10
+ end
11
+
12
+ def current_branch
13
+ system "git rev-parse --abbrev-ref HEAD"
14
+ end
15
+
16
+ def local_branches
17
+ repo.branches.select { |b| b.branch? }
18
+ end
19
+
20
+ def delete_local_branch!(branch_name)
21
+ run_command("git branch -d #{branch_name}")
22
+ $?.success?
23
+ end
24
+
25
+ def force_delete_local_branch?(branch_name)
26
+ if yes?("Force delete branch?", :red)
27
+ force_delete_local_branch!(branch_name)
28
+ true
29
+ else
30
+ false
31
+ end
32
+ end
33
+
34
+ def force_delete_local_branch!(branch_name)
35
+ run_command("git branch -D #{branch_name}")
36
+ end
37
+
38
+ def delete_remote_branch?(branch_name)
39
+ if yes?("Delete branch remotely?", :red)
40
+ delete_remote_branch!(branch_name)
41
+ true
42
+ else
43
+ false
44
+ end
45
+ end
46
+
47
+ def delete_remote_branch!(branch_name)
48
+ run_command("git push --delete origin #{branch_name}")
49
+ end
50
+
51
+ def run_command(command)
52
+ options = {
53
+ :verbose => ENV.has_key?('LEGIT_DEBUG')
54
+ }
55
+ run(command, options)
56
+ end
57
+
58
+ def todos_staged?(todo_format)
59
+ run_command("git diff --staged | grep '^+' | grep #{todo_format}")
60
+ $?.success? # grep returns 0 if there is a match
61
+ end
62
+ end
63
+ end
data/lib/legit/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Legit
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.13"
3
3
  end
data/lib/legit.rb CHANGED
@@ -1,14 +1,15 @@
1
- require 'legit_helper'
1
+ require 'legit/helpers'
2
2
 
3
3
  module Legit
4
4
  class CLI < Thor
5
5
  include Thor::Actions
6
+ include Legit::Helpers
6
7
 
7
8
  desc "log [ARGS]", "print a graph-like log"
8
9
  method_option :me, :type => :boolean, :desc => 'Only include my commits'
9
10
  def log(*args)
10
11
  command = []
11
- command << LOG_BASE_COMMAND
12
+ command << Legit::Helpers::LOG_BASE_COMMAND
12
13
  command << "--author='#{repo.config['user.name']}'" if options[:me]
13
14
  args.each do |arg|
14
15
  command << arg
@@ -45,35 +46,26 @@ module Legit
45
46
  run_command("git bisect reset")
46
47
  end
47
48
 
48
- desc "checkout ARGS", "git checkout, matching an arg between /'s to a local branch, i.e. `legit checkout /my_feature/`"
49
- def checkout(*args)
50
- regex_index = args.index { |arg| arg =~ %r{\A/.*/\z} }
49
+ desc "checkout REGEX", "fuzzy git checkout - can use ruby regex notation `legit checkout BUG-40\\d`"
50
+ def checkout(branch_pattern)
51
+ regex = Regexp.new(branch_pattern, Regexp::IGNORECASE)
52
+ matching_branches = local_branches.select { |b| b.name =~ regex }
51
53
 
52
- if regex_index
53
- regex_argument = args.delete_at(regex_index)
54
- regex_without_slashes = regex_argument[%r{\A/(.*)/\z}, 1]
55
- regex = Regexp.new(regex_without_slashes)
54
+ matched_branch =
55
+ case matching_branches.length
56
+ when 0
57
+ say("No branches match #{regex.inspect}", :red)
58
+ exit 1
59
+ when 1
60
+ matching_branches.first
61
+ else
62
+ matching_branches = matching_branches.sort_by { |b| b.name }
63
+ branch_list = matching_branches.each_with_index.map { |branch, index| "#{index + 1}. #{branch.name}" }
64
+ response = ask("Choose a branch to checkout:\n#{branch_list.join("\n")}", :yellow).to_i
65
+ matching_branches[response - 1]
66
+ end
56
67
 
57
- local_branches = repo.branches.select { |b| b.branch? }
58
- matching_branches = local_branches.select { |b| b.name =~ regex }
59
-
60
- matched_branch =
61
- case matching_branches.length
62
- when 0
63
- say("No branches match #{regex.inspect}", :red)
64
- exit 1
65
- when 1
66
- matching_branches.first
67
- else
68
- matching_branches = matching_branches.sort_by {|b| b.name }
69
- branch_list = matching_branches.each_with_index.map { |branch, index| "#{index + 1}. #{branch.name}"}
70
- response = ask("Choose a branch to checkout:\n#{branch_list.join("\n")}", :yellow).to_i
71
- matching_branches[response - 1]
72
- end
73
- args.insert(regex_index, matched_branch.name)
74
- end
75
-
76
- run_command("git checkout #{args.join(' ')}")
68
+ run_command("git checkout #{matched_branch.name}")
77
69
  end
78
70
 
79
71
  desc "delete BRANCH", "Delete BRANCH both locally and remotely"
@@ -82,10 +74,6 @@ module Legit
82
74
  end
83
75
 
84
76
  private
85
- def repo
86
- @repo ||= Rugged::Repository.new(Rugged::Repository.discover)
87
- end
88
-
89
77
  def run_catch_todos(todo_format)
90
78
  if todos_staged?(todo_format)
91
79
  if repo.config['hooks.catch-todos-mode'] == 'warn'
data/test/legit_test.rb CHANGED
@@ -8,19 +8,20 @@ describe Legit::CLI do
8
8
  before do
9
9
  stub_config
10
10
  Legit::CLI.any_instance.stubs(:run_command)
11
+ Legit::CLI.expects(:exit).never
11
12
  end
12
13
 
13
14
  describe 'legit log' do
14
15
  it "parses --me command and passes through other options" do
15
16
  args = 'log -p --me -n 1'
16
17
  stub_config({ 'user.name' => 'Stubbed Username' })
17
- Legit::CLI.any_instance.expects(:run_command).with("#{LOG_BASE_COMMAND} --author='Stubbed Username' -p -n 1")
18
+ Legit::CLI.any_instance.expects(:run_command).with("#{Legit::Helpers::LOG_BASE_COMMAND} --author='Stubbed Username' -p -n 1")
18
19
  Legit::CLI.start(args.split(' '))
19
20
  end
20
21
 
21
22
  it "passes through options that aren't defined by legit log" do
22
23
  args = 'log -p --stat'
23
- Legit::CLI.any_instance.expects(:run_command).with("#{LOG_BASE_COMMAND} -p --stat")
24
+ Legit::CLI.any_instance.expects(:run_command).with("#{Legit::Helpers::LOG_BASE_COMMAND} -p --stat")
24
25
  Legit::CLI.start(args.split(' '))
25
26
  end
26
27
  end
@@ -107,47 +108,48 @@ describe Legit::CLI do
107
108
  end
108
109
 
109
110
  describe "legit checkout" do
110
- describe "when no regex passed" do
111
- it "runs git checkout command" do
112
- Legit::CLI.any_instance.expects(:run_command).with('git checkout plain_old_branch')
113
- Legit::CLI.start('checkout plain_old_branch'.split(' '))
114
- end
115
-
116
- it "passes through git checkout options" do
117
- Legit::CLI.any_instance.expects(:run_command).with('git checkout -b plain_old_branch')
118
- Legit::CLI.start('checkout -b plain_old_branch'.split(' '))
119
- end
120
- end
121
-
122
- describe "when passed a regex" do
123
- before do
124
- setup_example_repo
125
- end
126
-
127
- it "calls checkout on branch if unique match" do
128
- Legit::CLI.any_instance.expects(:run_command).with('git checkout feature_with_unique_match')
129
- Legit::CLI.start('checkout /unique/'.split(' '))
130
- end
131
-
132
- it "calls checkout with options passed through with a unique match" do
133
- Legit::CLI.any_instance.expects(:run_command).with('git checkout --contains feature_with_unique_match')
134
- Legit::CLI.start('checkout --contains /unique/'.split(' '))
135
- end
136
-
137
- it "doesn't call checkout and exits if no match" do
138
- Legit::CLI.any_instance.expects(:run_command).never
139
- Legit::CLI.any_instance.expects(:say).with("No branches match /this_shouldnt_match_anything/", :red)
140
- assert_raises(SystemExit) { Legit::CLI.start('checkout /this_shouldnt_match_anything/'.split(' ')) }
141
- end
142
-
143
- it "lists options if non-unique match" do
144
- Legit::CLI.any_instance.expects(:run_command).never
145
- Legit::CLI.any_instance.expects(:ask).with(
111
+ before do
112
+ setup_example_repo
113
+ end
114
+
115
+ it "checks out branch that matches substring" do
116
+ Legit::CLI.any_instance.expects(:run_command).with('git checkout feature_with_unique_match')
117
+ Legit::CLI.start('checkout niqu'.split(' '))
118
+ end
119
+
120
+ it "lists options if non-unique match" do
121
+ Legit::CLI.any_instance.expects(:run_command).never
122
+ Legit::CLI.any_instance.expects(:ask).with(
146
123
  "Choose a branch to checkout:\n1. multiple_matches_a\n2. multiple_matches_b", :yellow).returns('2')
147
- Legit::CLI.any_instance.expects(:run_command).with('git checkout multiple_matches_b')
148
- Legit::CLI.start('checkout /multiple_matches/'.split(' '))
149
- end
124
+ Legit::CLI.any_instance.expects(:run_command).with('git checkout multiple_matches_b')
125
+ Legit::CLI.start('checkout multiple_matches'.split(' '))
126
+ end
127
+
128
+ it "calls checkout on branch if unique match" do
129
+ Legit::CLI.any_instance.expects(:run_command).with('git checkout feature_with_unique_match')
130
+ Legit::CLI.start('checkout unique'.split(' '))
131
+ end
132
+
133
+ it "uses case-insensitive regex" do
134
+ Legit::CLI.any_instance.expects(:run_command).with('git checkout UPPERCASE_BRANCH')
135
+ Legit::CLI.start('checkout uppercase'.split(' '))
136
+ end
137
+
138
+ it "doesn't call checkout and exits if no match" do
139
+ Legit::CLI.any_instance.expects(:run_command).never
140
+ Legit::CLI.any_instance.expects(:say).with("No branches match /this_shouldnt_match_anything/i", :red)
141
+ assert_raises(SystemExit) { Legit::CLI.start('checkout this_shouldnt_match_anything'.split(' ')) }
142
+ end
143
+
144
+ it "calls checkout on branch if unique match" do
145
+ Legit::CLI.any_instance.expects(:run_command).with('git checkout feature_with_unique_match')
146
+ Legit::CLI.start('checkout _wit.'.split(' '))
147
+ end
150
148
 
149
+ it "doesn't call checkout and exits if there is no regex match" do
150
+ Legit::CLI.any_instance.expects(:run_command).never
151
+ Legit::CLI.any_instance.expects(:say).with("No branches match /^_wit./i", :red)
152
+ assert_raises(SystemExit) { Legit::CLI.start('checkout ^_wit.'.split(' ')) }
151
153
  end
152
154
  end
153
155
 
@@ -19,7 +19,7 @@ class SetupTestRepo < Thor
19
19
  create_file('README.txt', 'Example repo for testing')
20
20
  run "git add ."
21
21
  run "git commit -m 'Add README'"
22
- branch_names = %w{ feature_with_unique_match multiple_matches_a multiple_matches_b }
22
+ branch_names = %w{ feature_with_unique_match multiple_matches_a multiple_matches_b UPPERCASE_BRANCH }
23
23
  branch_names.each do |branch_name|
24
24
  run "git branch #{branch_name}"
25
25
  end
metadata CHANGED
@@ -1,36 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: legit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
5
- prerelease:
4
+ version: 0.0.13
6
5
  platform: ruby
7
6
  authors:
8
7
  - Dillon Kearns
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-05-19 00:00:00.000000000 Z
11
+ date: 2013-08-30 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
21
- version: 10.0.3
19
+ version: 10.1.0
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
29
- version: 10.0.3
26
+ version: 10.1.0
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: minitest
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: mocha
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,71 +55,62 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: guard-minitest
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: growl
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - '>='
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: rb-fsevent
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - '>='
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0'
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - '>='
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0'
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: coveralls
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
- - - ! '>='
101
+ - - '>='
116
102
  - !ruby/object:Gem::Version
117
103
  version: '0'
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
- - - ! '>='
108
+ - - '>='
124
109
  - !ruby/object:Gem::Version
125
110
  version: '0'
126
111
  - !ruby/object:Gem::Dependency
127
112
  name: json
128
113
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
114
  requirements:
131
115
  - - ~>
132
116
  - !ruby/object:Gem::Version
@@ -134,7 +118,6 @@ dependencies:
134
118
  type: :runtime
135
119
  prerelease: false
136
120
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
121
  requirements:
139
122
  - - ~>
140
123
  - !ruby/object:Gem::Version
@@ -142,7 +125,6 @@ dependencies:
142
125
  - !ruby/object:Gem::Dependency
143
126
  name: thor
144
127
  requirement: !ruby/object:Gem::Requirement
145
- none: false
146
128
  requirements:
147
129
  - - ~>
148
130
  - !ruby/object:Gem::Version
@@ -150,7 +132,6 @@ dependencies:
150
132
  type: :runtime
151
133
  prerelease: false
152
134
  version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
135
  requirements:
155
136
  - - ~>
156
137
  - !ruby/object:Gem::Version
@@ -158,19 +139,17 @@ dependencies:
158
139
  - !ruby/object:Gem::Dependency
159
140
  name: rugged
160
141
  requirement: !ruby/object:Gem::Requirement
161
- none: false
162
142
  requirements:
163
- - - '='
143
+ - - ~>
164
144
  - !ruby/object:Gem::Version
165
- version: 0.18.0.b1
145
+ version: 0.19.0
166
146
  type: :runtime
167
147
  prerelease: false
168
148
  version_requirements: !ruby/object:Gem::Requirement
169
- none: false
170
149
  requirements:
171
- - - '='
150
+ - - ~>
172
151
  - !ruby/object:Gem::Version
173
- version: 0.18.0.b1
152
+ version: 0.19.0
174
153
  description: A collection of scripts for common git tasks to simplify and improve
175
154
  workflow.
176
155
  email:
@@ -190,37 +169,33 @@ files:
190
169
  - bin/legit
191
170
  - legit.gemspec
192
171
  - lib/legit.rb
172
+ - lib/legit/helpers.rb
193
173
  - lib/legit/version.rb
194
- - lib/legit_helper.rb
195
174
  - test/legit_test.rb
196
175
  - test/setup_test_repo.rb
197
176
  - test/test_helper.rb
198
177
  homepage: https://github.com/dillonkearns/legit
199
178
  licenses: []
179
+ metadata: {}
200
180
  post_install_message:
201
181
  rdoc_options: []
202
182
  require_paths:
203
183
  - lib
204
184
  required_ruby_version: !ruby/object:Gem::Requirement
205
- none: false
206
185
  requirements:
207
- - - ! '>='
186
+ - - '>='
208
187
  - !ruby/object:Gem::Version
209
188
  version: 1.8.7
210
189
  required_rubygems_version: !ruby/object:Gem::Requirement
211
- none: false
212
190
  requirements:
213
- - - ! '>='
191
+ - - '>='
214
192
  - !ruby/object:Gem::Version
215
193
  version: '0'
216
- segments:
217
- - 0
218
- hash: -1588079376854796946
219
194
  requirements: []
220
195
  rubyforge_project:
221
- rubygems_version: 1.8.25
196
+ rubygems_version: 2.0.3
222
197
  signing_key:
223
- specification_version: 3
198
+ specification_version: 4
224
199
  summary: A collection of scripts for common git tasks to simplify and improve workflow.
225
200
  test_files:
226
201
  - test/legit_test.rb
data/lib/legit_helper.rb DELETED
@@ -1,51 +0,0 @@
1
- require 'rugged'
2
- require 'thor'
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"
5
-
6
- def current_branch
7
- system "git rev-parse --abbrev-ref HEAD"
8
- end
9
-
10
- def delete_local_branch!(branch_name)
11
- run_command("git branch -d #{branch_name}")
12
- $?.success?
13
- end
14
-
15
- def force_delete_local_branch?(branch_name)
16
- if yes?("Force delete branch?", :red)
17
- force_delete_local_branch!(branch_name)
18
- true
19
- else
20
- false
21
- end
22
- end
23
-
24
- def force_delete_local_branch!(branch_name)
25
- run_command("git branch -D #{branch_name}")
26
- end
27
-
28
- def delete_remote_branch?(branch_name)
29
- if yes?("Delete branch remotely?", :red)
30
- delete_remote_branch!(branch_name)
31
- true
32
- else
33
- false
34
- end
35
- end
36
-
37
- def delete_remote_branch!(branch_name)
38
- run_command("git push --delete origin #{branch_name}")
39
- end
40
-
41
- def run_command(command)
42
- options = {
43
- :verbose => ENV.has_key?('LEGIT_DEBUG')
44
- }
45
- run(command, options)
46
- end
47
-
48
- def todos_staged?(todo_format)
49
- run_command("git diff --staged | grep '^+' | grep #{todo_format}")
50
- $?.success? # grep returns 0 if there is a match
51
- end