git-topic 0.2.4.1 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +10 -0
- data/VERSION.yml +2 -2
- data/lib/git_topic.rb +49 -30
- data/lib/git_topic/comment.rb +10 -3
- data/lib/git_topic/git.rb +13 -0
- data/lib/git_topic/naming.rb +15 -6
- data/spec/comment_spec.rb +23 -3
- data/spec/git_topic_comment_spec.rb +40 -0
- data/spec/git_topic_comments_spec.rb +26 -0
- data/spec/git_topic_install_aliases_spec.rb +2 -4
- data/spec/git_topic_setup_spec.rb +1 -1
- data/spec/spec_helper.rb +2 -1
- metadata +3 -4
data/History.rdoc
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
=== 0.2.5
|
2
|
+
|
3
|
+
* issues closed
|
4
|
+
- 9 git comments <spec> now asks for the right range.
|
5
|
+
- 11 git comments now falls back to name-rev, so works even for remote
|
6
|
+
branches.
|
7
|
+
- 16 shorthand aliases not installed by git-topic setup.
|
8
|
+
- 17 git comment reports to the user if they entered a blank comment.
|
9
|
+
- 20 refspecs now use +, i.e. they autoforce.
|
10
|
+
|
1
11
|
==== 0.2.4.1
|
2
12
|
|
3
13
|
* issue 14 closed. Added --completion-help like output to
|
data/VERSION.yml
CHANGED
data/lib/git_topic.rb
CHANGED
@@ -233,25 +233,10 @@ module GitTopic
|
|
233
233
|
|
234
234
|
diff_empty = git( "diff --diff-filter=M --quiet" ) && $?.success?
|
235
235
|
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
diff → comments not allowed when replying. Please make sure your
|
241
|
-
working tree is completely clean and then invoke git-topic comment
|
242
|
-
again.
|
243
|
-
".oneline unless diff_empty
|
244
|
-
|
245
|
-
notes_from_reply_to_comments
|
246
|
-
else
|
247
|
-
puts "No comments to reply to. See git-topic comment --help for usage."
|
248
|
-
return
|
249
|
-
end
|
250
|
-
when "review"
|
251
|
-
if existing_comments?
|
252
|
-
if opts[ :force_update ]
|
253
|
-
notes_from_initial_comments( "edit" )
|
254
|
-
else
|
236
|
+
added_comments =
|
237
|
+
case current_namespace
|
238
|
+
when "wip"
|
239
|
+
if existing_comments?
|
255
240
|
raise "
|
256
241
|
diff → comments not allowed when replying. Please make sure your
|
257
242
|
working tree is completely clean and then invoke git-topic comment
|
@@ -259,25 +244,63 @@ module GitTopic
|
|
259
244
|
".oneline unless diff_empty
|
260
245
|
|
261
246
|
notes_from_reply_to_comments
|
247
|
+
else
|
248
|
+
puts "No comments to reply to. See git-topic comment --help for usage."
|
249
|
+
return
|
250
|
+
end
|
251
|
+
when "review"
|
252
|
+
if existing_comments?
|
253
|
+
if opts[ :force_update ]
|
254
|
+
notes_from_initial_comments( "edit" )
|
255
|
+
else
|
256
|
+
raise "
|
257
|
+
diff → comments not allowed when replying. Please make sure your
|
258
|
+
working tree is completely clean and then invoke git-topic comment
|
259
|
+
again.
|
260
|
+
".oneline unless diff_empty
|
261
|
+
|
262
|
+
notes_from_reply_to_comments
|
263
|
+
end
|
264
|
+
else
|
265
|
+
notes_from_initial_comments
|
262
266
|
end
|
263
267
|
else
|
264
|
-
|
268
|
+
raise "Inappropriate namespace for comments: [#{namespace}]"
|
265
269
|
end
|
270
|
+
|
271
|
+
if added_comments
|
272
|
+
report "Your comments have been saved."
|
266
273
|
else
|
267
|
-
|
274
|
+
report "You did not write any comments. Nothing to save."
|
268
275
|
end
|
269
|
-
|
270
|
-
report "Your comments have been saved."
|
271
276
|
end
|
272
277
|
|
273
278
|
def comments( spec=nil, opts={} )
|
274
279
|
args = [ spec ].compact
|
280
|
+
if args.empty? && current_branch.nil?
|
281
|
+
if guess = guess_branch
|
282
|
+
args << guess_branch
|
283
|
+
|
284
|
+
puts "
|
285
|
+
You are not on a branch and no topic branch was specified. Using
|
286
|
+
alternate name for HEAD, #{guess}.
|
287
|
+
".oneline
|
288
|
+
else
|
289
|
+
puts "
|
290
|
+
You are not on a branch and no topic branch was specified. I could
|
291
|
+
not find an appropriate name for HEAD to guess.
|
292
|
+
"
|
293
|
+
return
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
275
297
|
unless existing_comments? *args
|
276
298
|
puts "There are no comments on this branch."
|
277
299
|
return
|
278
300
|
end
|
279
301
|
|
280
|
-
|
302
|
+
range = "origin/master..#{remote_branch *args}"
|
303
|
+
git "log #{range} --show-notes=#{notes_ref *args} --no-standard-notes",
|
281
304
|
:show => true
|
282
305
|
end
|
283
306
|
|
@@ -333,7 +356,7 @@ module GitTopic
|
|
333
356
|
cmds = []
|
334
357
|
|
335
358
|
cmds <<(
|
336
|
-
"config --add remote.origin.fetch refs/notes/reviews/*:refs/notes/reviews/*"
|
359
|
+
"config --add remote.origin.fetch +refs/notes/reviews/*:refs/notes/reviews/*"
|
337
360
|
) unless has_setup_refspec?
|
338
361
|
|
339
362
|
cmds <<(
|
@@ -356,10 +379,6 @@ module GitTopic
|
|
356
379
|
"config #{flags} alias.reject 'topic reject'",
|
357
380
|
"config #{flags} alias.comment 'topic comment'",
|
358
381
|
"config #{flags} alias.comments 'topic comments'",
|
359
|
-
|
360
|
-
"config #{flags} alias.w 'topic work-on'",
|
361
|
-
"config #{flags} alias.r 'topic review'",
|
362
|
-
"config #{flags} alias.st 'topic status --prepended'",
|
363
382
|
]
|
364
383
|
|
365
384
|
report "Aliases installed Successfully.",
|
@@ -416,7 +435,7 @@ module GitTopic
|
|
416
435
|
def has_setup_refspec?
|
417
436
|
fetch_refspecs = capture_git( "config --get-all remote.origin.fetch" ).split( "\n" )
|
418
437
|
fetch_refspecs.any? do |refspec|
|
419
|
-
refspec == "refs/notes/reviews/*:refs/notes/reviews/*"
|
438
|
+
refspec == "+refs/notes/reviews/*:refs/notes/reviews/*"
|
420
439
|
end
|
421
440
|
end
|
422
441
|
|
data/lib/git_topic/comment.rb
CHANGED
@@ -247,10 +247,17 @@ module GitTopic::Comment
|
|
247
247
|
notes,
|
248
248
|
content,
|
249
249
|
:author => git_author_name_short )
|
250
|
-
|
250
|
+
|
251
251
|
File.open( edit_file, 'w' ){ |f| f.write( notes_with_reply )}
|
252
|
-
|
253
|
-
|
252
|
+
|
253
|
+
|
254
|
+
if notes_with_reply != notes
|
255
|
+
git "notes --ref #{notes_ref} edit -F #{edit_file}",
|
256
|
+
:must_succeed => true
|
257
|
+
else
|
258
|
+
# No comments to add.
|
259
|
+
return false
|
260
|
+
end
|
254
261
|
end
|
255
262
|
|
256
263
|
def attrib( author, indent=0, max_w=16 )
|
data/lib/git_topic/git.rb
CHANGED
@@ -56,6 +56,19 @@ module GitTopic::Git
|
|
56
56
|
capture_git( "notes --ref #{ref} show" ).chomp
|
57
57
|
end
|
58
58
|
|
59
|
+
def current_branch
|
60
|
+
@@current_branch ||= capture_git( "branch --no-color" ).split( "\n" ).find do |b|
|
61
|
+
b =~ %r{^\*}
|
62
|
+
end[ 2..-1 ]
|
63
|
+
@@current_branch = nil if @@current_branch == '(no branch)'
|
64
|
+
|
65
|
+
@@current_branch
|
66
|
+
end
|
67
|
+
|
68
|
+
def guess_branch
|
69
|
+
capture_git( "name-rev --name-only HEAD" )
|
70
|
+
end
|
71
|
+
|
59
72
|
|
60
73
|
def display_git_output?
|
61
74
|
@@display_git_output ||= false
|
data/lib/git_topic/naming.rb
CHANGED
@@ -29,6 +29,18 @@ module GitTopic::Naming
|
|
29
29
|
"rejected/#{user}/#{strip_namespace topic}"
|
30
30
|
end
|
31
31
|
|
32
|
+
def remote_branch( spec=current_branch )
|
33
|
+
parts = topic_parts( spec )
|
34
|
+
|
35
|
+
remote_branches.find do |remote_branch|
|
36
|
+
bp = topic_parts( remote_branch )
|
37
|
+
|
38
|
+
parts.all? do |part, value|
|
39
|
+
bp[part] == value
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
32
44
|
|
33
45
|
def find_remote_review_branch( topic )
|
34
46
|
others_review_branches.find{|b| b.index topic}
|
@@ -57,7 +69,10 @@ module GitTopic::Naming
|
|
57
69
|
def topic_parts( ref, opts={} )
|
58
70
|
p = {}
|
59
71
|
parts = ref.split( '/' )
|
72
|
+
|
73
|
+
parts.shift if parts.first == 'remotes'
|
60
74
|
parts.shift if parts.first == "origin"
|
75
|
+
|
61
76
|
case parts.size
|
62
77
|
when 3
|
63
78
|
p[:namespace], p[:user], p[:topic] = parts
|
@@ -100,12 +115,6 @@ module GitTopic::Naming
|
|
100
115
|
$1
|
101
116
|
end
|
102
117
|
|
103
|
-
def current_branch
|
104
|
-
@@current_branch ||= capture_git( "branch --no-color" ).split( "\n" ).find do |b|
|
105
|
-
b =~ %r{^\*}
|
106
|
-
end[ 2..-1 ]
|
107
|
-
end
|
108
|
-
|
109
118
|
def branches
|
110
119
|
@@branches ||= capture_git( "branch --no-color" ).split( "\n" ).map{|b| b[2..-1]}
|
111
120
|
end
|
data/spec/comment_spec.rb
CHANGED
@@ -333,9 +333,11 @@ describe GitTopic::Comment do
|
|
333
333
|
lambda{ notes_from_reply_to_comments }.should raise_error
|
334
334
|
end
|
335
335
|
|
336
|
-
it "
|
336
|
+
it "
|
337
|
+
should add the users' comments as replies to the originals and return true
|
338
|
+
".oneline do
|
337
339
|
self.should_receive( :existing_comments? ). and_return( true )
|
338
|
-
self.should_receive( :existing_comments ).
|
340
|
+
self.should_receive( :existing_comments ). and_return( ExistingComment )
|
339
341
|
self.should_receive( :git_dir ). and_return( "." )
|
340
342
|
self.should_receive( :git_author_name_short ). and_return( "Spec 456" )
|
341
343
|
self.should_receive( :notes_ref ).
|
@@ -348,9 +350,27 @@ describe GitTopic::Comment do
|
|
348
350
|
File.read( "./COMMENT_EDITMSG" ).should == CommentWithReply
|
349
351
|
end
|
350
352
|
|
351
|
-
lambda
|
353
|
+
lambda do
|
354
|
+
notes_from_reply_to_comments.should == true
|
355
|
+
end.should_not raise_error
|
352
356
|
end
|
353
357
|
|
358
|
+
it "should return false if the user added no comments" do
|
359
|
+
self.should_receive( :existing_comments? ). and_return( true )
|
360
|
+
self.should_receive( :existing_comments ). and_return( ExistingComment )
|
361
|
+
self.should_receive( :git_dir ). and_return( "." )
|
362
|
+
self.should_receive( :git_author_name_short ). and_return( "Spec 456" )
|
363
|
+
self.should_not_receive( :notes_ref )
|
364
|
+
self.stub!( :invoke_git_editor ) do |path|
|
365
|
+
File.open( path, 'w' ) do |f|
|
366
|
+
f.write ExistingComment.lines.map{ |l| "# #{l}" }.join
|
367
|
+
end
|
368
|
+
end
|
369
|
+
self.should_receive( :invoke_git_editor )
|
370
|
+
self.should_not_receive( :git )
|
371
|
+
|
372
|
+
notes_from_reply_to_comments.should == false
|
373
|
+
end
|
354
374
|
end
|
355
375
|
|
356
376
|
|
@@ -319,6 +319,46 @@ describe GitTopic do
|
|
319
319
|
"refs/notes/reviews/user24601/ninja-basic"
|
320
320
|
).should == SecondComment
|
321
321
|
end
|
322
|
+
|
323
|
+
it "should report success to the user" do
|
324
|
+
GitTopic.should_receive( :invoke_git_editor ).once
|
325
|
+
GitTopic.should_receive(
|
326
|
+
:git_author_name_short
|
327
|
+
).once.and_return( "Spec 123" )
|
328
|
+
|
329
|
+
lambda{ GitTopic.comment }.should_not raise_error
|
330
|
+
@output.should =~ /comments have been saved/i
|
331
|
+
end
|
332
|
+
|
333
|
+
it "should fail (and report the failure) if the user entered no comments" do
|
334
|
+
git_notes_list(
|
335
|
+
"refs/notes/reviews/user24601/ninja-basic"
|
336
|
+
).should_not be_empty
|
337
|
+
git_notes_show(
|
338
|
+
"refs/notes/reviews/user24601/ninja-basic"
|
339
|
+
).should == FirstComment
|
340
|
+
|
341
|
+
GitTopic.stub!( :invoke_git_editor ) do |path|
|
342
|
+
File.open( path, 'w' ) do |f|
|
343
|
+
f.write FirstComment.lines.map{ |l| "# #{l}" }.join
|
344
|
+
end
|
345
|
+
end
|
346
|
+
GitTopic.should_receive( :invoke_git_editor ).once
|
347
|
+
GitTopic.should_receive(
|
348
|
+
:git_author_name_short
|
349
|
+
).once.and_return( "Spec 123" )
|
350
|
+
|
351
|
+
lambda{ GitTopic.comment }.should_not raise_error
|
352
|
+
git_notes_list(
|
353
|
+
"refs/notes/reviews/user24601/ninja-basic"
|
354
|
+
).should_not be_empty
|
355
|
+
|
356
|
+
git_notes_show(
|
357
|
+
"refs/notes/reviews/user24601/ninja-basic"
|
358
|
+
).should == FirstComment
|
359
|
+
|
360
|
+
@output.should =~ /nothing to save/i
|
361
|
+
end
|
322
362
|
end
|
323
363
|
|
324
364
|
|
@@ -93,6 +93,31 @@ describe GitTopic do
|
|
93
93
|
|
94
94
|
|
95
95
|
it "should invoke git log to display the comments" do
|
96
|
+
GitTopic.should_receive( :git ) do |cmd|
|
97
|
+
cmd.should =~ /log/
|
98
|
+
cmd.should =~ %r{origin/master\.\.origin/wip/#{@user}/krakens}
|
99
|
+
cmd.should =~ /--no-standard-notes/
|
100
|
+
cmd.should =~ %r{--show-notes=refs/notes/reviews/#{@user}/krakens}
|
101
|
+
end
|
102
|
+
|
103
|
+
lambda{ GitTopic.comments }.should_not raise_error
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe "on a commit named by a topic branch with comments" do
|
108
|
+
|
109
|
+
before( :each ) do
|
110
|
+
use_repo 'in-progress'
|
111
|
+
system "git checkout origin/rejected/#{@user}/krakens > /dev/null 2> /dev/null"
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should report the topic it's guessing to look for comments on" do
|
115
|
+
lambda{ GitTopic.comments }.should_not raise_error
|
116
|
+
@output.should =~ /no topic branch/i
|
117
|
+
@output.should =~ /krakens/i
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should guess a topic and show its comments" do
|
96
121
|
GitTopic.should_receive( :git ) do |cmd|
|
97
122
|
cmd.should =~ /log/
|
98
123
|
cmd.should =~ %r{origin/master\.\.}
|
@@ -102,6 +127,7 @@ describe GitTopic do
|
|
102
127
|
|
103
128
|
lambda{ GitTopic.comments }.should_not raise_error
|
104
129
|
end
|
130
|
+
|
105
131
|
end
|
106
132
|
end
|
107
133
|
|
@@ -4,6 +4,8 @@ require 'spec_helper'
|
|
4
4
|
describe GitTopic do
|
5
5
|
|
6
6
|
describe "#install_aliases" do
|
7
|
+
before( :each ){ use_repo 'in-progress' }
|
8
|
+
|
7
9
|
it "should install aliases" do
|
8
10
|
GitTopic.install_aliases :local => true
|
9
11
|
git_config( 'alias.work-on' ).should == 'topic work-on'
|
@@ -13,10 +15,6 @@ describe GitTopic do
|
|
13
15
|
git_config( 'alias.reject' ).should == 'topic reject'
|
14
16
|
git_config( 'alias.comment' ).should == 'topic comment'
|
15
17
|
git_config( 'alias.comments' ).should == 'topic comments'
|
16
|
-
|
17
|
-
git_config( 'alias.w' ).should == 'topic work-on'
|
18
|
-
git_config( 'alias.r' ).should == 'topic review'
|
19
|
-
git_config( 'alias.st' ).should == 'topic status --prepended'
|
20
18
|
end
|
21
19
|
|
22
20
|
it "should provide feedback to the user" do
|
data/spec/spec_helper.rb
CHANGED
@@ -16,7 +16,8 @@ class << GitTopic
|
|
16
16
|
|
17
17
|
define_method( "#{m}_with_nocache" ) do
|
18
18
|
rv = send( "#{m}_without_nocache" )
|
19
|
-
GitTopic::Naming::ClassMethods.class_variable_set(
|
19
|
+
GitTopic::Naming::ClassMethods.class_variable_set( "@@#{m}", nil )
|
20
|
+
GitTopic::Git::ClassMethods.class_variable_set( "@@#{m}", nil )
|
20
21
|
rv
|
21
22
|
end
|
22
23
|
alias_method_chain m.to_sym, :nocache
|
metadata
CHANGED
@@ -5,9 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
|
10
|
-
version: 0.2.4.1
|
8
|
+
- 5
|
9
|
+
version: 0.2.5
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- David J. Hamilton
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-08-
|
17
|
+
date: 2010-08-27 00:00:00 -07:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|