scrumninja-git-cli 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -19,3 +19,4 @@ rdoc
19
19
  pkg
20
20
 
21
21
  ## PROJECT::SPECIFIC
22
+ .scrumninja.yml
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
data/bin/sgc CHANGED
@@ -1,3 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
3
+ require 'rubygems'
2
4
  require 'scrum_ninja_git_cli'
3
5
  ScrumNinjaGitCli.run_command(*ARGV)
data/lib/git_wrapper.rb CHANGED
@@ -59,10 +59,40 @@ module GitWrapper
59
59
  ##### Modification commands: these just shell out to git (directly or indirectly) #####
60
60
  def checkout(branch_name, remote='origin')
61
61
  fetch(remote)
62
- create_branch(branch_name) unless local_branch_exists?(branch_name)
63
- publish_remote_branch(branch_name, remote) unless remote_branch_exists?(branch_name, remote)
62
+ lb, rb = local_branch_exists?(branch_name), remote_branch_exists?(branch_name, remote)
63
+ case
64
+ when lb && rb
65
+ checkout_with_existing_local_and_existing_remote(branch_name, remote)
66
+ when lb && !rb
67
+ checkout_with_existing_local_and_NON_existing_remote(branch_name, remote)
68
+ when !lb && rb
69
+ checkout_with_NON_existing_local_and_existing_remote(branch_name, remote)
70
+ when !lb && !rb
71
+ checkout_with_NON_existing_local_and_NON_existing_remote(branch_name, remote)
72
+ end
73
+ return "That was fun!"
74
+ end
75
+
76
+ def checkout_with_existing_local_and_existing_remote(branch_name, remote)
77
+ checkout_branch(branch_name)
64
78
  track_remote_branch(branch_name, remote)
79
+ merge_without_remote_update(branch_name, remote)
80
+ end
81
+ def checkout_with_existing_local_and_NON_existing_remote(branch_name, remote)
82
+ checkout_branch(branch_name)
83
+ publish_remote_branch(branch_name, remote)
84
+ track_remote_branch(branch_name, remote)
85
+ end
86
+ def checkout_with_NON_existing_local_and_existing_remote(branch_name, remote)
65
87
  checkout_branch(branch_name, remote)
88
+ create_branch(branch_name)
89
+ track_remote_branch(branch_name, remote)
90
+ end
91
+ def checkout_with_NON_existing_local_and_NON_existing_remote(branch_name, remote)
92
+ checkout_branch 'master' # yes, really
93
+ create_branch(branch_name)
94
+ publish_remote_branch(branch_name, remote)
95
+ track_remote_branch(branch_name, remote)
66
96
  end
67
97
 
68
98
  def fetch(remote='origin')
@@ -85,8 +115,13 @@ module GitWrapper
85
115
  run_git "branch --set-upstream #{branch_name} #{remote}/#{branch_name}"
86
116
  end
87
117
 
88
- def checkout_branch(branch_name, remote='origin')
89
- run_git "checkout #{branch_name}"
118
+ def checkout_branch(branch_name, remote=nil)
119
+ refspec = [remote, branch_name].reject(&:nil?) * '/'
120
+ run_git "checkout #{refspec}"
121
+ end
122
+
123
+ def merge_without_remote_update(branch, remote)
124
+ run_git "merge #{remote}/#{branch}"
90
125
  end
91
126
 
92
127
  def merge_from_master
@@ -13,13 +13,15 @@ class GitWrapperUnitTest < Test::Unit::TestCase
13
13
  def setup
14
14
  # Holler if we ever inadvertently try to run a git command
15
15
  GitWrapper.expects(:run_git).never
16
+ @s=nil
16
17
  end
17
18
 
18
19
  def expect_git_command(command, interactive=false)
20
+ @s||=sequence('git commands sequence')
19
21
  if interactive
20
- GitWrapper.expects(:run_git).with(command, true)
22
+ GitWrapper.expects(:run_git).with(command, true).in_sequence(@s)
21
23
  else
22
- GitWrapper.expects(:run_git).with(command)
24
+ GitWrapper.expects(:run_git).with(command).in_sequence(@s)
23
25
  end
24
26
  end
25
27
 
@@ -136,18 +138,8 @@ class GitWrapperUnitTest < Test::Unit::TestCase
136
138
  end
137
139
  end
138
140
 
139
- context "checkout" do
140
- should 'fetch' do
141
- expect_git_command 'fetch origin'
142
- expect_git_command 'branch my-story'
143
- expect_git_command 'push origin my-story:refs/heads/my-story'
144
- expect_git_command 'branch --set-upstream my-story origin/my-story'
145
- expect_git_command 'checkout my-story'
146
-
147
- GitWrapper.checkout('my-story')
148
- end
149
-
150
- should "take an optional 'remote' parameter" do
141
+ context 'checkout (with optional remote arg)' do
142
+ should_eventually 'work' do
151
143
  expect_git_command 'fetch nonstandard_remote'
152
144
  expect_git_command 'branch my-story'
153
145
  expect_git_command 'push nonstandard_remote my-story:refs/heads/my-story'
@@ -156,6 +148,12 @@ class GitWrapperUnitTest < Test::Unit::TestCase
156
148
 
157
149
  GitWrapper.checkout('my-story', 'nonstandard_remote')
158
150
  end
151
+ end
152
+
153
+ context "checkout" do
154
+ setup do
155
+ expect_git_command 'fetch origin'
156
+ end
159
157
 
160
158
  context "when remote branch 'my-story' does not exist" do
161
159
  setup do
@@ -164,14 +162,12 @@ class GitWrapperUnitTest < Test::Unit::TestCase
164
162
  GitWrapper.git.stubs(:remotes).returns(@remotes)
165
163
  end
166
164
 
167
- should "create local 'my-story' branch, check it out, publish it, and track it" do
168
- expect_git_command 'fetch origin'
169
- expect_git_command 'branch local-story-branch'
170
- expect_git_command 'push origin local-story-branch:refs/heads/local-story-branch'
171
- expect_git_command 'branch --set-upstream local-story-branch origin/local-story-branch'
172
- expect_git_command 'checkout local-story-branch'
173
-
174
- GitWrapper.checkout('local-story-branch')
165
+ context "and local branch 'my-story' does not exist" do
166
+ should "create local 'my-story' branch, check it out, publish it, and track it" do
167
+ GitWrapper.expects(:checkout_with_NON_existing_local_and_NON_existing_remote) \
168
+ .with('my-story', 'origin')
169
+ GitWrapper.checkout('my-story')
170
+ end
175
171
  end
176
172
 
177
173
  context "and local branch 'my-story' exists" do
@@ -179,12 +175,10 @@ class GitWrapperUnitTest < Test::Unit::TestCase
179
175
  @branches << branch('my-story')
180
176
  end
181
177
  should "check out the remote branch and track it" do
182
- expect_git_command 'fetch origin'
183
- expect_git_command 'push origin my-story:refs/heads/my-story'
184
- expect_git_command 'branch --set-upstream my-story origin/my-story'
185
- expect_git_command 'checkout my-story'
186
-
178
+ GitWrapper.expects(:checkout_with_existing_local_and_NON_existing_remote) \
179
+ .with('my-story', 'origin')
187
180
  GitWrapper.checkout('my-story')
181
+
188
182
  end
189
183
  end
190
184
  end
@@ -196,30 +190,60 @@ class GitWrapperUnitTest < Test::Unit::TestCase
196
190
  GitWrapper.git.stubs(:remotes).returns(@remotes)
197
191
  end
198
192
 
199
- should "create local 'my-story' branch, make it track the remote branch, and check it out" do
200
- expect_git_command 'fetch origin'
201
- expect_git_command 'branch my-story'
202
- expect_git_command 'branch --set-upstream my-story origin/my-story'
203
- expect_git_command 'checkout my-story'
204
-
205
- GitWrapper.checkout('my-story')
193
+ context "and local branch 'my-story' does not exist" do
194
+ should "create local 'my-story' branch, make it track the remote branch, and check it out" do
195
+ GitWrapper.expects(:checkout_with_NON_existing_local_and_existing_remote) \
196
+ .with('my-story', 'origin')
197
+ GitWrapper.checkout('my-story')
198
+ end
206
199
  end
207
200
 
208
201
  context "when local branch 'my-story' exists" do
209
202
  setup do
210
203
  @branches << branch('my-story')
211
204
  end
212
- should "make it track the remote branch, and check it out" do
213
- expect_git_command 'fetch origin'
214
- expect_git_command 'branch --set-upstream my-story origin/my-story'
215
- expect_git_command 'checkout my-story'
216
205
 
206
+ should "make it track the remote branch, and check it out" do
207
+ GitWrapper.expects(:checkout_with_existing_local_and_existing_remote) \
208
+ .with('my-story', 'origin')
217
209
  GitWrapper.checkout('my-story')
218
210
  end
219
211
  end
220
212
  end
221
213
  end
222
214
 
215
+ context 'stupid truthy-tably methods' do
216
+ should '#checkout_with_existing_local_and_existing_remote' do
217
+ expect_git_command 'checkout my-story'
218
+ expect_git_command 'branch --set-upstream my-story origin/my-story'
219
+ expect_git_command 'merge origin/my-story'
220
+
221
+ GitWrapper.checkout_with_existing_local_and_existing_remote('my-story', 'origin')
222
+ end
223
+ should '#checkout_with_existing_local_and_NON_existing_remote' do
224
+ expect_git_command 'checkout my-story'
225
+ expect_git_command 'push origin my-story:refs/heads/my-story'
226
+ expect_git_command 'branch --set-upstream my-story origin/my-story'
227
+
228
+ GitWrapper.checkout_with_existing_local_and_NON_existing_remote('my-story', 'origin')
229
+ end
230
+ should '#checkout_with_NON_existing_local_and_existing_remote' do
231
+ expect_git_command 'checkout origin/my-story'
232
+ expect_git_command 'branch my-story'
233
+ expect_git_command 'branch --set-upstream my-story origin/my-story'
234
+
235
+ GitWrapper.checkout_with_NON_existing_local_and_existing_remote('my-story', 'origin')
236
+ end
237
+ should '#checkout_with_NON_existing_local_and_NON_existing_remote' do
238
+ expect_git_command 'checkout master'
239
+ expect_git_command 'branch my-story'
240
+ expect_git_command 'push origin my-story:refs/heads/my-story'
241
+ expect_git_command 'branch --set-upstream my-story origin/my-story'
242
+
243
+ GitWrapper.checkout_with_NON_existing_local_and_NON_existing_remote('my-story', 'origin')
244
+ end
245
+ end
246
+
223
247
  context "#is_state_clean?" do
224
248
  should "be true when it is" do
225
249
  expect_git_command('status').returns <<-EOF
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 4
9
- version: 0.0.4
8
+ - 5
9
+ version: 0.0.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - John Wilger
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-03-26 00:00:00 -07:00
19
+ date: 2010-03-30 00:00:00 -07:00
20
20
  default_executable: sgc
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency