git-topic 0.1.6.4 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.vimspell.utf8.add +9 -0
- data/.vimspell.utf8.add.spl +0 -0
- data/README.rdoc +57 -27
- data/Rakefile +10 -0
- data/VERSION.yml +3 -3
- data/bin/git-topic-completion +58 -0
- data/lib/core_ext.rb +74 -12
- data/lib/git_topic.rb +145 -12
- data/lib/git_topic/cli.rb +105 -13
- data/lib/git_topic/comment.rb +273 -0
- data/lib/git_topic/git.rb +66 -3
- data/lib/git_topic/naming.rb +26 -5
- data/share/completion.bash +28 -0
- data/spec/bash_completion.rb +2 -0
- data/spec/comment_spec.rb +396 -0
- data/spec/git_topic_accept_spec.rb +78 -0
- data/spec/git_topic_comment_spec.rb +393 -0
- data/spec/git_topic_comments_spec.rb +47 -0
- data/spec/git_topic_done_spec.rb +94 -0
- data/spec/git_topic_install_aliases_spec.rb +32 -0
- data/spec/git_topic_reject_spec.rb +112 -0
- data/spec/git_topic_review_spec.rb +115 -0
- data/spec/git_topic_status_spec.rb +63 -0
- data/spec/git_topic_work_on_spec.rb +121 -0
- data/spec/spec_helper.rb +136 -0
- metadata +34 -11
- data/git-topic +0 -13
- data/git-topic.gemspec +0 -190
- data/spec/git_topic_spec.rb +0 -502
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe GitTopic do
|
5
|
+
|
6
|
+
describe "#accept" do
|
7
|
+
|
8
|
+
describe "while on a review branch" do
|
9
|
+
before( :each ) do
|
10
|
+
use_repo 'in-progress'
|
11
|
+
GitTopic.review 'user24601/zombie-basic'
|
12
|
+
end
|
13
|
+
after( :each ) { Dir.chdir '..' }
|
14
|
+
|
15
|
+
describe "with no specified argument" do
|
16
|
+
it "
|
17
|
+
should merge to master, push master and destroy the local and remote
|
18
|
+
branches when the merge is a fast-forward merge
|
19
|
+
".oneline do
|
20
|
+
|
21
|
+
git_branch.should == 'review/user24601/zombie-basic'
|
22
|
+
GitTopic.accept
|
23
|
+
git_branch.should == 'master'
|
24
|
+
git_branches.should_not include( 'review/user24601/zombie-basic' )
|
25
|
+
git_remote_branches.should_not include( 'review/user24601/zombie-basic' )
|
26
|
+
|
27
|
+
git_head.should == '0ce06c616769768f09f5e629cfcc68eabe3dee81'
|
28
|
+
git_origin_master.should == '0ce06c616769768f09f5e629cfcc68eabe3dee81'
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should provide feedback to the user" do
|
32
|
+
GitTopic.accept
|
33
|
+
$?.success?.should == true
|
34
|
+
@output.should_not be_nil
|
35
|
+
@output.should_not be_empty
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should fail if the working tree is dirty" do
|
39
|
+
dirty_branch!
|
40
|
+
lambda{ GitTopic.accept }.should raise_error
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "while on a review branch that does not FF" do
|
46
|
+
before( :each ) do
|
47
|
+
use_repo 'in-progress'
|
48
|
+
system "
|
49
|
+
git checkout master > /dev/null 2> /dev/null &&
|
50
|
+
git merge origin/wip/prevent-ff > /dev/null 2> /dev/null
|
51
|
+
"
|
52
|
+
@original_git_Head = git_head
|
53
|
+
GitTopic.review 'user24601/zombie-basic'
|
54
|
+
end
|
55
|
+
after( :each ) { Dir.chdir '..' }
|
56
|
+
|
57
|
+
it "should refuse to accept the review branch" do
|
58
|
+
git_branch.should == 'review/user24601/zombie-basic'
|
59
|
+
lambda{ GitTopic.accept }.should raise_error
|
60
|
+
git_branch.should == 'review/user24601/zombie-basic'
|
61
|
+
git_remote_branches.should include( 'review/user24601/zombie-basic' )
|
62
|
+
|
63
|
+
system "git checkout master > /dev/null 2> /dev/null"
|
64
|
+
git_head.should == @original_git_Head
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "while not on a review branch" do
|
69
|
+
before( :each ) { use_repo 'in-progress' }
|
70
|
+
after( :each ) { Dir.chdir '..' }
|
71
|
+
|
72
|
+
it "should fail" do
|
73
|
+
lambda{ GitTopic.accept }.should raise_error
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
@@ -0,0 +1,393 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
GeneralCommentOnly = %Q{
|
4
|
+
Spec 123: I have some general comments, mostly relating to the quality
|
5
|
+
of our zombie-control policies. Basically, they're not
|
6
|
+
working.
|
7
|
+
}.strip
|
8
|
+
|
9
|
+
FirstComment = %Q{
|
10
|
+
Spec 123: I have some general comments, mostly relating to the quality
|
11
|
+
of our zombie-control policies. Basically, they're not
|
12
|
+
working.
|
13
|
+
|
14
|
+
./zombies
|
15
|
+
|
16
|
+
Line 2
|
17
|
+
Spec 123: I suggest we do the following instead:
|
18
|
+
zombies.each{ |z| reason_with( z )}
|
19
|
+
zomies.select do |z|
|
20
|
+
z.unconvinced?
|
21
|
+
end.each do |z|
|
22
|
+
destroy z
|
23
|
+
end
|
24
|
+
This should take care of our issues with zombies.
|
25
|
+
}.strip
|
26
|
+
|
27
|
+
FirstCommentUpdated = %Q{
|
28
|
+
Spec 123: I agree, though I wonder if maybe we've become a little too
|
29
|
+
obsessed with bacon. Umm, wait, sorry, wrong thread.
|
30
|
+
There is no way this is going to work. Sorry, but there's just not.
|
31
|
+
|
32
|
+
./ninjas
|
33
|
+
|
34
|
+
Line 2
|
35
|
+
Spec 123: I suggest we do the following instead:
|
36
|
+
everyone.giveup
|
37
|
+
This should take care of our issues with zombies.
|
38
|
+
}.strip
|
39
|
+
|
40
|
+
FirstCommentReply = %Q{
|
41
|
+
# Spec 123: I have some general comments, mostly relating to the quality
|
42
|
+
# of our zombie-control policies. Basically, they're not
|
43
|
+
# working.
|
44
|
+
|
45
|
+
I agree, though I wonder if maybe we've become a little too obsessed with bacon. Umm, wait, sorry, wrong thread.
|
46
|
+
|
47
|
+
#
|
48
|
+
# ./zombies
|
49
|
+
#
|
50
|
+
# Line 2
|
51
|
+
# Spec 123: I suggest we do the following instead:
|
52
|
+
# zombies.each{ |z| reason_with( z )}
|
53
|
+
# zomies.select do |z|
|
54
|
+
# z.unconvinced?
|
55
|
+
# end.each do |z|
|
56
|
+
# destroy z
|
57
|
+
# end
|
58
|
+
# This should take care of our issues with zombies.
|
59
|
+
There is no way this is going to work. Sorry, but there's just not.
|
60
|
+
}.strip
|
61
|
+
|
62
|
+
SecondComment = %Q{
|
63
|
+
Spec 123: I have some general comments, mostly relating to the quality
|
64
|
+
of our zombie-control policies. Basically, they're not
|
65
|
+
working.
|
66
|
+
Spec 123: I agree, though I wonder if maybe we've become a little too
|
67
|
+
obsessed with bacon. Umm, wait, sorry, wrong thread.
|
68
|
+
|
69
|
+
./zombies
|
70
|
+
|
71
|
+
Line 2
|
72
|
+
Spec 123: I suggest we do the following instead:
|
73
|
+
zombies.each{ |z| reason_with( z )}
|
74
|
+
zomies.select do |z|
|
75
|
+
z.unconvinced?
|
76
|
+
end.each do |z|
|
77
|
+
destroy z
|
78
|
+
end
|
79
|
+
This should take care of our issues with zombies.
|
80
|
+
Spec 123: There is no way this is going to work. Sorry, but there's
|
81
|
+
just not.
|
82
|
+
}.strip
|
83
|
+
|
84
|
+
SecondCommentWithReply = %Q{
|
85
|
+
Spec 123: I have some general comments, mostly relating to the quality
|
86
|
+
of our zombie-control policies. Basically, they're not
|
87
|
+
working.
|
88
|
+
Spec 234: I agree, though I wonder if maybe we've become a little too
|
89
|
+
obsessed with bacon. Umm, wait, sorry, wrong thread.
|
90
|
+
|
91
|
+
./zombies
|
92
|
+
|
93
|
+
Line 2
|
94
|
+
Spec 123: I suggest we do the following instead:
|
95
|
+
zombies.each{ |z| reason_with( z )}
|
96
|
+
zomies.select do |z|
|
97
|
+
z.unconvinced?
|
98
|
+
end.each do |z|
|
99
|
+
destroy z
|
100
|
+
end
|
101
|
+
This should take care of our issues with zombies.
|
102
|
+
Spec 234: There is no way this is going to work. Sorry, but there's
|
103
|
+
just not.
|
104
|
+
}.strip
|
105
|
+
|
106
|
+
|
107
|
+
describe GitTopic do
|
108
|
+
|
109
|
+
describe "#comment" do
|
110
|
+
|
111
|
+
before( :each ) do
|
112
|
+
GitTopic.stub!( :invoke_git_editor ) do |path|
|
113
|
+
File.open( path, 'w' ) do |f|
|
114
|
+
f.puts %Q{
|
115
|
+
I have some general comments, mostly relating to the quality of our
|
116
|
+
zombie-control policies. Basically, they're not working.
|
117
|
+
}.cleanup
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe "on a review branch with no comments" do
|
123
|
+
|
124
|
+
before( :each ) do
|
125
|
+
use_repo 'in-progress'
|
126
|
+
GitTopic.review 'user24601/zombie-basic'
|
127
|
+
end
|
128
|
+
after( :each ) { Dir.chdir '..' }
|
129
|
+
|
130
|
+
|
131
|
+
it "should fail if the diff includes added lines not prefixed with #" do
|
132
|
+
File.open( 'zombies', 'a' ){ |f| f.puts "a line" }
|
133
|
+
lambda{ GitTopic.comment }.should raise_error
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should fail if the diff includes removed lines" do
|
137
|
+
File.open( 'zombies', 'w' ){ |f| f.puts '' }
|
138
|
+
lambda{ GitTopic.comment }.should raise_error
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should fail if there are new files." do
|
142
|
+
File.open( 'new-untracked-file', 'w' ){ |f| f.puts 'content' }
|
143
|
+
system "git add new-untracked-file > /dev/null 2> /dev/null"
|
144
|
+
lambda{ GitTopic.comment }.should raise_error
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should fail if files have been deleted." do
|
148
|
+
FileUtils.rm 'zombies'
|
149
|
+
lambda{ GitTopic.comment }.should raise_error
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should fail if file modes have been modified." do
|
153
|
+
FileUtils.chmod 0744, 'zombies'
|
154
|
+
lambda{ GitTopic.comment }.should raise_error
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should fail if git config user.name is not set" do
|
158
|
+
GitTopic::Git::ClassMethods.class_variable_set( "@@git_author_name_short", nil )
|
159
|
+
GitTopic.stub( :` ) do |cmd|
|
160
|
+
if cmd =~ %r{^git config user.name}
|
161
|
+
$?.instance_eval do
|
162
|
+
def success?; false; end
|
163
|
+
end
|
164
|
+
""
|
165
|
+
else
|
166
|
+
%x{#{cmd}}
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
File.open( 'zombies', 'a' ) do |f|
|
171
|
+
f.puts %Q{
|
172
|
+
# I suggest we do the following instead:
|
173
|
+
# zombies.each{ |z| reason_with( z )}
|
174
|
+
# zomies.select do |z|
|
175
|
+
# z.unconvinced?
|
176
|
+
# end.each do |z|
|
177
|
+
# destroy z
|
178
|
+
# end
|
179
|
+
# This should take care of our issues with zombies.
|
180
|
+
}.cleanup
|
181
|
+
end
|
182
|
+
lambda{ GitTopic.comment }.should raise_error
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should allow general comments if there is no diff" do
|
186
|
+
git_diff.should be_empty
|
187
|
+
|
188
|
+
GitTopic.should_receive( :invoke_git_editor ).once
|
189
|
+
GitTopic.should_receive(
|
190
|
+
:git_author_name_short
|
191
|
+
).once.and_return( "Spec 123" )
|
192
|
+
|
193
|
+
lambda{ GitTopic.comment }.should_not raise_error
|
194
|
+
|
195
|
+
git_notes_list(
|
196
|
+
"refs/notes/reviews/user24601/zombie-basic"
|
197
|
+
).should_not be_empty
|
198
|
+
|
199
|
+
git_notes_show(
|
200
|
+
"refs/notes/reviews/user24601/zombie-basic"
|
201
|
+
).should == GeneralCommentOnly
|
202
|
+
end
|
203
|
+
|
204
|
+
it "
|
205
|
+
should convert added lines to notes, formatted appropriately, and save
|
206
|
+
them in refs/notes/reviews/<user>/<topic>.
|
207
|
+
".oneline do
|
208
|
+
File.open( 'zombies', 'a' ) do |f|
|
209
|
+
f.puts %Q{
|
210
|
+
# I suggest we do the following instead:
|
211
|
+
# zombies.each{ |z| reason_with( z )}
|
212
|
+
# zomies.select do |z|
|
213
|
+
# z.unconvinced?
|
214
|
+
# end.each do |z|
|
215
|
+
# destroy z
|
216
|
+
# end
|
217
|
+
# This should take care of our issues with zombies.
|
218
|
+
}.cleanup
|
219
|
+
end
|
220
|
+
GitTopic.should_receive( :invoke_git_editor ).once
|
221
|
+
GitTopic.should_receive(
|
222
|
+
:git_author_name_short
|
223
|
+
).once.and_return( "Spec 123" )
|
224
|
+
|
225
|
+
lambda{ GitTopic.comment }.should_not raise_error
|
226
|
+
git_notes_list(
|
227
|
+
"refs/notes/reviews/user24601/zombie-basic"
|
228
|
+
).should_not be_empty
|
229
|
+
|
230
|
+
git_notes_show(
|
231
|
+
"refs/notes/reviews/user24601/zombie-basic"
|
232
|
+
).should == FirstComment
|
233
|
+
|
234
|
+
git_diff.should be_empty
|
235
|
+
end
|
236
|
+
|
237
|
+
end
|
238
|
+
|
239
|
+
|
240
|
+
describe "on a review branch with existing comments" do
|
241
|
+
|
242
|
+
before( :each ) do
|
243
|
+
use_repo( 'in-progress' )
|
244
|
+
GitTopic.review 'user24601/ninja-basic'
|
245
|
+
|
246
|
+
GitTopic.stub!( :invoke_git_editor ) do |path|
|
247
|
+
File.open( path, 'w' ) do |f|
|
248
|
+
f.write FirstCommentReply
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
252
|
+
after( :each ) { Dir.chdir '..' }
|
253
|
+
|
254
|
+
|
255
|
+
it "should fail if the working tree is dirty" do
|
256
|
+
File.open( 'ninjas', 'a' ) do |f|
|
257
|
+
f.puts %Q{
|
258
|
+
# I suggest we do the following instead:
|
259
|
+
# zombies.each{ |z| reason_with( z )}
|
260
|
+
# zomies.select do |z|
|
261
|
+
# z.unconvinced?
|
262
|
+
# end.each do |z|
|
263
|
+
# destroy z
|
264
|
+
# end
|
265
|
+
# This should take care of our issues with zombies.
|
266
|
+
}.cleanup
|
267
|
+
end
|
268
|
+
|
269
|
+
lambda{ GitTopic.comment }.should raise_error
|
270
|
+
end
|
271
|
+
|
272
|
+
it "should replace existing comments with --force" do
|
273
|
+
File.open( 'ninjas', 'a' ) do |f|
|
274
|
+
f.puts %Q{
|
275
|
+
# I suggest we do the following instead:
|
276
|
+
# everyone.giveup
|
277
|
+
# This should take care of our issues with zombies.
|
278
|
+
}.cleanup
|
279
|
+
end
|
280
|
+
|
281
|
+
GitTopic.should_receive( :invoke_git_editor ).once
|
282
|
+
GitTopic.should_receive(
|
283
|
+
:git_author_name_short
|
284
|
+
).once.and_return( "Spec 123" )
|
285
|
+
|
286
|
+
|
287
|
+
lambda do
|
288
|
+
GitTopic.comment :force_update => true
|
289
|
+
end.should_not raise_error
|
290
|
+
|
291
|
+
git_notes_list(
|
292
|
+
"refs/notes/reviews/user24601/ninja-basic"
|
293
|
+
).should_not be_empty
|
294
|
+
|
295
|
+
git_notes_show(
|
296
|
+
"refs/notes/reviews/user24601/ninja-basic"
|
297
|
+
).should == FirstCommentUpdated
|
298
|
+
|
299
|
+
git_diff.should be_empty
|
300
|
+
end
|
301
|
+
|
302
|
+
it "should append comments (without --force-update)" do
|
303
|
+
git_notes_list(
|
304
|
+
"refs/notes/reviews/user24601/ninja-basic"
|
305
|
+
).should_not be_empty
|
306
|
+
git_notes_show(
|
307
|
+
"refs/notes/reviews/user24601/ninja-basic"
|
308
|
+
).should == FirstComment
|
309
|
+
|
310
|
+
GitTopic.should_receive( :invoke_git_editor ).once
|
311
|
+
GitTopic.should_receive(
|
312
|
+
:git_author_name_short
|
313
|
+
).once.and_return( "Spec 123" )
|
314
|
+
|
315
|
+
lambda{ GitTopic.comment }.should_not raise_error
|
316
|
+
git_notes_list(
|
317
|
+
"refs/notes/reviews/user24601/ninja-basic"
|
318
|
+
).should_not be_empty
|
319
|
+
|
320
|
+
git_notes_show(
|
321
|
+
"refs/notes/reviews/user24601/ninja-basic"
|
322
|
+
).should == SecondComment
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
|
327
|
+
describe "on a wip branch with no comments" do
|
328
|
+
before( :each ) { use_repo 'in-progress' }
|
329
|
+
after( :each ) { Dir.chdir '..' }
|
330
|
+
|
331
|
+
it "should report that there is nothing to do" do
|
332
|
+
GitTopic.work_on 'pirates-advanced'
|
333
|
+
lambda{ GitTopic.comment }.should_not raise_error
|
334
|
+
|
335
|
+
git_notes_list(
|
336
|
+
"refs/notes/reviews/#{@user}/pirates-advanced"
|
337
|
+
).should be_empty
|
338
|
+
@output.should_not be_empty
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
|
343
|
+
describe "on a wip branch with existing comments" do
|
344
|
+
before( :each ) do
|
345
|
+
use_repo 'in-progress'
|
346
|
+
GitTopic.work_on 'rejected/krakens'
|
347
|
+
|
348
|
+
GitTopic.stub!( :invoke_git_editor ) do |path|
|
349
|
+
File.open( path, 'w' ) do |f|
|
350
|
+
f.puts FirstCommentReply
|
351
|
+
end
|
352
|
+
end
|
353
|
+
end
|
354
|
+
after( :each ) { Dir.chdir '..' }
|
355
|
+
|
356
|
+
|
357
|
+
it "should fail if the working tree is dirty" do
|
358
|
+
File.open( 'kraken', 'a' ) do |f|
|
359
|
+
f.puts %Q{
|
360
|
+
# I suggest we do the following instead:
|
361
|
+
# zombies.each{ |z| reason_with( z )}
|
362
|
+
# zomies.select do |z|
|
363
|
+
# z.unconvinced?
|
364
|
+
# end.each do |z|
|
365
|
+
# destroy z
|
366
|
+
# end
|
367
|
+
# This should take care of our issues with zombies.
|
368
|
+
}.cleanup
|
369
|
+
end
|
370
|
+
|
371
|
+
lambda{ GitTopic.comment }.should raise_error
|
372
|
+
end
|
373
|
+
|
374
|
+
it "should append comments" do
|
375
|
+
GitTopic.should_receive( :invoke_git_editor ).once
|
376
|
+
GitTopic.should_receive(
|
377
|
+
:git_author_name_short
|
378
|
+
).once.and_return( "Spec 234" )
|
379
|
+
|
380
|
+
lambda{ GitTopic.comment }.should_not raise_error
|
381
|
+
git_notes_list(
|
382
|
+
"refs/notes/reviews/#{@user}/krakens"
|
383
|
+
).should_not be_empty
|
384
|
+
|
385
|
+
git_notes_show(
|
386
|
+
"refs/notes/reviews/#{@user}/krakens"
|
387
|
+
).should == SecondCommentWithReply
|
388
|
+
end
|
389
|
+
end
|
390
|
+
|
391
|
+
end
|
392
|
+
end
|
393
|
+
|