legit 0.0.10 → 0.0.11

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/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ test/example_repo
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in dotfile_linker.gemspec
4
4
  gemspec
5
+
6
+ gem "pry", :group => :pry
data/legit.gemspec CHANGED
@@ -17,14 +17,15 @@ 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.add_development_dependency "minitest", "~> 4.6.2"
21
- gem.add_development_dependency "minitest-reporters"
22
- gem.add_development_dependency "mocha", "~> 0.13.2"
20
+ gem.add_development_dependency "minitest", "~> 5.0.1"
21
+ gem.add_development_dependency "mocha", "~> 0.14.0"
23
22
  gem.add_development_dependency "guard-minitest"
24
23
  gem.add_development_dependency "growl"
25
24
  gem.add_development_dependency "rb-fsevent"
26
25
  gem.add_development_dependency "coveralls"
27
26
 
28
- gem.add_runtime_dependency "thor", "~> 0.17.0"
29
- gem.add_runtime_dependency "rugged", "0.17.0.b7" # need version 0.17 for a bug accessing Rugged::Repo.config in 0.16
27
+ gem.add_runtime_dependency "json", "~> 1.8.0"
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
+
30
31
  end
data/lib/legit/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Legit
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
data/lib/legit.rb CHANGED
@@ -45,6 +45,37 @@ module Legit
45
45
  run_command("git bisect reset")
46
46
  end
47
47
 
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} }
51
+
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)
56
+
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(' ')}")
77
+ end
78
+
48
79
  desc "delete BRANCH", "Delete BRANCH both locally and remotely"
49
80
  def delete(branch_name)
50
81
  delete_local_branch!(branch_name) || force_delete_local_branch?(branch_name) and delete_remote_branch?(branch_name)
data/lib/legit_helper.rb CHANGED
@@ -35,7 +35,7 @@ def delete_remote_branch?(branch_name)
35
35
  end
36
36
 
37
37
  def delete_remote_branch!(branch_name)
38
- system("git push --delete origin #{branch_name}")
38
+ run_command("git push --delete origin #{branch_name}")
39
39
  end
40
40
 
41
41
  def run_command(command)
data/test/legit_test.rb CHANGED
@@ -1,11 +1,13 @@
1
1
  require File.expand_path('../test_helper', __FILE__)
2
2
  require 'legit'
3
+ require File.expand_path('../setup_test_repo', __FILE__)
3
4
 
4
5
  describe Legit::CLI do
5
6
  include Mocha::Integration::MiniTest
6
7
 
7
8
  before do
8
9
  stub_config
10
+ Legit::CLI.any_instance.stubs(:run_command)
9
11
  end
10
12
 
11
13
  describe 'legit log' do
@@ -104,6 +106,51 @@ describe Legit::CLI do
104
106
  end
105
107
  end
106
108
 
109
+ 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(
146
+ "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
150
+
151
+ end
152
+ end
153
+
107
154
  describe 'legit bisect' do
108
155
  command = 'ruby -n my/test/file "/testpattern/"'
109
156
  args = "bisect HEAD HEAD~5 #{command}"
@@ -117,3 +164,9 @@ end
117
164
  def stub_config(config = {})
118
165
  Legit::CLI.any_instance.stubs(:repo => stub({ :config => config }))
119
166
  end
167
+
168
+ def setup_example_repo
169
+ SetupTestRepo.new.invoke(:create_repo)
170
+ example_repo = Rugged::Repository.new(File.expand_path('../example_repo', __FILE__))
171
+ Legit::CLI.any_instance.stubs(:repo => example_repo)
172
+ end
@@ -0,0 +1,27 @@
1
+ require 'thor'
2
+
3
+ class SetupTestRepo < Thor
4
+ include Thor::Actions
5
+
6
+ desc "SOMETHING", 'something else'
7
+ def create_repo
8
+ test_location = File.expand_path('../example_repo', __FILE__)
9
+ remove_dir(test_location)
10
+ inside(test_location) do
11
+ run 'git init'
12
+ run 'git config user.name "John Doe" && git config user.email johndoe@example.com'
13
+ setup_branches
14
+ end
15
+ end
16
+
17
+ private
18
+ def setup_branches
19
+ create_file('README.txt', 'Example repo for testing')
20
+ run "git add ."
21
+ run "git commit -m 'Add README'"
22
+ branch_names = %w{ feature_with_unique_match multiple_matches_a multiple_matches_b }
23
+ branch_names.each do |branch_name|
24
+ run "git branch #{branch_name}"
25
+ end
26
+ end
27
+ end
data/test/test_helper.rb CHANGED
@@ -2,9 +2,7 @@ require 'coveralls'
2
2
  Coveralls.wear!
3
3
 
4
4
  require "minitest/autorun"
5
- require "minitest/reporters"
6
-
7
- # for attaching tests to rubymine
8
- MiniTest::Reporters.use! if ENV['RUBYMINE']
9
5
 
10
6
  require 'mocha/setup'
7
+
8
+ Bundler.require(:pry) if ENV["PRY"]
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.10
4
+ version: 0.0.11
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-09 00:00:00.000000000 Z
12
+ date: 2013-05-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 4.6.2
37
+ version: 5.0.1
38
38
  type: :development
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,23 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
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'
45
+ version: 5.0.1
62
46
  - !ruby/object:Gem::Dependency
63
47
  name: mocha
64
48
  requirement: !ruby/object:Gem::Requirement
@@ -66,7 +50,7 @@ dependencies:
66
50
  requirements:
67
51
  - - ~>
68
52
  - !ruby/object:Gem::Version
69
- version: 0.13.2
53
+ version: 0.14.0
70
54
  type: :development
71
55
  prerelease: false
72
56
  version_requirements: !ruby/object:Gem::Requirement
@@ -74,7 +58,7 @@ dependencies:
74
58
  requirements:
75
59
  - - ~>
76
60
  - !ruby/object:Gem::Version
77
- version: 0.13.2
61
+ version: 0.14.0
78
62
  - !ruby/object:Gem::Dependency
79
63
  name: guard-minitest
80
64
  requirement: !ruby/object:Gem::Requirement
@@ -139,6 +123,22 @@ dependencies:
139
123
  - - ! '>='
140
124
  - !ruby/object:Gem::Version
141
125
  version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: json
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ~>
132
+ - !ruby/object:Gem::Version
133
+ version: 1.8.0
134
+ type: :runtime
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ~>
140
+ - !ruby/object:Gem::Version
141
+ version: 1.8.0
142
142
  - !ruby/object:Gem::Dependency
143
143
  name: thor
144
144
  requirement: !ruby/object:Gem::Requirement
@@ -146,7 +146,7 @@ dependencies:
146
146
  requirements:
147
147
  - - ~>
148
148
  - !ruby/object:Gem::Version
149
- version: 0.17.0
149
+ version: 0.18.1
150
150
  type: :runtime
151
151
  prerelease: false
152
152
  version_requirements: !ruby/object:Gem::Requirement
@@ -154,7 +154,7 @@ dependencies:
154
154
  requirements:
155
155
  - - ~>
156
156
  - !ruby/object:Gem::Version
157
- version: 0.17.0
157
+ version: 0.18.1
158
158
  - !ruby/object:Gem::Dependency
159
159
  name: rugged
160
160
  requirement: !ruby/object:Gem::Requirement
@@ -162,7 +162,7 @@ dependencies:
162
162
  requirements:
163
163
  - - '='
164
164
  - !ruby/object:Gem::Version
165
- version: 0.17.0.b7
165
+ version: 0.18.0.b1
166
166
  type: :runtime
167
167
  prerelease: false
168
168
  version_requirements: !ruby/object:Gem::Requirement
@@ -170,7 +170,7 @@ dependencies:
170
170
  requirements:
171
171
  - - '='
172
172
  - !ruby/object:Gem::Version
173
- version: 0.17.0.b7
173
+ version: 0.18.0.b1
174
174
  description: A collection of scripts for common git tasks to simplify and improve
175
175
  workflow.
176
176
  email:
@@ -193,6 +193,7 @@ files:
193
193
  - lib/legit/version.rb
194
194
  - lib/legit_helper.rb
195
195
  - test/legit_test.rb
196
+ - test/setup_test_repo.rb
196
197
  - test/test_helper.rb
197
198
  homepage: https://github.com/dillonkearns/legit
198
199
  licenses: []
@@ -214,13 +215,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
214
215
  version: '0'
215
216
  segments:
216
217
  - 0
217
- hash: 3336823418665542283
218
+ hash: -1588079376854796946
218
219
  requirements: []
219
220
  rubyforge_project:
220
- rubygems_version: 1.8.23
221
+ rubygems_version: 1.8.25
221
222
  signing_key:
222
223
  specification_version: 3
223
224
  summary: A collection of scripts for common git tasks to simplify and improve workflow.
224
225
  test_files:
225
226
  - test/legit_test.rb
227
+ - test/setup_test_repo.rb
226
228
  - test/test_helper.rb