git-topic 0.2.3.1 → 0.2.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -2,4 +2,4 @@
2
2
  :major: 0
3
3
  :minor: 2
4
4
  :patch: 3
5
- :build: "1"
5
+ :build: "2"
@@ -35,6 +35,14 @@ module GitTopic::Completion
35
35
  end.compact
36
36
  end
37
37
 
38
+ def all_reject_and_review_branches
39
+ branches.map do |b|
40
+ b =~ %r{^remotes/origin/(rejected|review)/(\S*)/(.*)}
41
+ suggestion = [$1,($2 unless $2 == user), $3].compact.join("/")
42
+ suggestion unless suggestion.strip.empty?
43
+ end.compact
44
+ end
45
+
38
46
  def complete
39
47
  suggestions =
40
48
  case ARGV.shift
@@ -42,8 +50,11 @@ module GitTopic::Completion
42
50
  # others_review_branches here
43
51
  when "accept"
44
52
  when "reject"
53
+ when "comment"
45
54
  when "done"
46
55
  # nothing
56
+ when "comments"
57
+ all_reject_and_review_branches
47
58
  when "work-on"
48
59
  my_reject_review_and_all_wip_branches
49
60
  when "review"
data/lib/git_topic/cli.rb CHANGED
@@ -161,11 +161,11 @@ module GitTopic
161
161
  ".oneline
162
162
  when "comments"
163
163
  banner "
164
- git[-topic] comments
164
+ git[-topic] comments [<topic>]
165
165
 
166
- View the comments for the current topic. If your branch was
167
- rejected, you should read these comments so you know what to do to
168
- appease the reviewer.
166
+ View the comments for <topic>, which defaults to the current topic.
167
+ If your branch was rejected, you should read these comments so you
168
+ know what to do to appease the reviewer.
169
169
 
170
170
  Options:
171
171
  ".cleanup
@@ -221,6 +221,8 @@ module GitTopic
221
221
  end
222
222
  end
223
223
 
224
+ check_for_setup unless cmd == "setup"
225
+
224
226
  opts = global_opts.merge( cmd_opts )
225
227
  display_git_output! if opts[:verbose]
226
228
 
@@ -243,7 +245,8 @@ module GitTopic
243
245
  when "comment"
244
246
  comment opts
245
247
  when "comments"
246
- comments opts
248
+ spec = ARGV.shift
249
+ comments spec, opts
247
250
  when "accept"
248
251
  topic = ARGV.shift
249
252
  accept topic, opts
@@ -252,6 +255,8 @@ module GitTopic
252
255
  reject topic, opts
253
256
  when "install-aliases"
254
257
  install_aliases opts
258
+ when "setup"
259
+ setup opts
255
260
  end
256
261
  rescue => error
257
262
  puts "Error: #{error.message}"
data/lib/git_topic/git.rb CHANGED
@@ -51,8 +51,9 @@ module GitTopic::Git
51
51
  not capture_git( "notes --ref #{ref} list" ).chomp.empty?
52
52
  end
53
53
 
54
- def existing_comments
55
- capture_git( "notes --ref #{notes_ref} show" ).chomp
54
+ def existing_comments( spec=nil )
55
+ ref = notes_ref( *[ spec ].compact )
56
+ capture_git( "notes --ref #{ref} show" ).chomp
56
57
  end
57
58
 
58
59
 
@@ -44,25 +44,20 @@ module GitTopic::Naming
44
44
 
45
45
 
46
46
  def notes_ref( branch=current_branch )
47
- user, topic = user_topic_name( branch )
47
+ user, topic = user_topic_name( branch, :lookup => true )
48
48
  "refs/notes/reviews/#{user}/#{topic}"
49
49
  end
50
50
 
51
51
 
52
- def user_topic_name( branch )
53
- if branch =~ %r{^origin}
54
- branch =~ %r{^\S*?/\S*?/(\S*?)/(\S*)}
55
- [$1, $2]
56
- elsif branch =~ %r{^(?:\S*/)?(\S*?)/(\S*)}
57
- [$1, $2]
58
- else
59
- raise "Cannot compute user_topic for [#{branch}]"
60
- end
52
+ def user_topic_name( ref, opts={} )
53
+ p = topic_parts( ref, opts )
54
+ [ p[:user], p[:topic ] ]
61
55
  end
62
56
 
63
- def topic_parts( ref )
57
+ def topic_parts( ref, opts={} )
64
58
  p = {}
65
59
  parts = ref.split( '/' )
60
+ parts.shift if parts.first == "origin"
66
61
  case parts.size
67
62
  when 3
68
63
  p[:namespace], p[:user], p[:topic] = parts
@@ -74,6 +69,19 @@ module GitTopic::Naming
74
69
  else
75
70
  raise "Unexpected topic: #{ref}"
76
71
  end
72
+
73
+ if opts[:lookup] && p[:user].nil?
74
+ remote_branches_organized.find do |namespace, v|
75
+ v.find do |user, vv|
76
+ if vv.find{ |topic| topic == p[:topic] }
77
+ p[:user] = user
78
+ p[:namespace] = namespace
79
+ true
80
+ end
81
+ end
82
+ end
83
+ end
84
+
77
85
  p
78
86
  end
79
87
 
@@ -141,13 +149,6 @@ module GitTopic::Naming
141
149
  namespace_ut[:review] ||= {}
142
150
  namespace_ut[:rejected] ||= {}
143
151
 
144
- namespace_ut[:rejected].each do |user, topics|
145
- topics.map! do |topic|
146
- suffix = " (reviewer comments) "
147
- "#{topic}#{suffix if existing_comments?( "#{user}/#{topic}" )}"
148
- end
149
- end
150
-
151
152
  namespace_ut[:review].reject!{|k,v| k == user}
152
153
  namespace_ut
153
154
  )
data/lib/git_topic.rb CHANGED
@@ -76,8 +76,13 @@ module GitTopic
76
76
 
77
77
  wb = wip_branch( topic )
78
78
  rb = review_branch( topic )
79
+ refspecs = [
80
+ "refs/heads/#{wb}:refs/heads/#{rb}",
81
+ ":refs/heads/#{wb}",
82
+ "refs/notes/reviews/*:refs/notes/reviews/*"
83
+ ].join( " " )
79
84
  git [
80
- "push origin refs/heads/#{wb}:refs/heads/#{rb} :refs/heads/#{wb}",
85
+ "push origin #{refspecs}",
81
86
  ("checkout master" if strip_namespace( topic ) == current_topic),
82
87
  "branch -D #{wip_branch( topic )}"
83
88
  ].compact
@@ -119,7 +124,11 @@ module GitTopic
119
124
  end.join( "\n" )
120
125
  end
121
126
 
122
- rejected_topics = rejected_ut[ user ] || []
127
+ rejected_topics = (rejected_ut[ user ] || []).dup
128
+ rejected_topics.map! do |topic|
129
+ suffix = " (reviewer comments) "
130
+ "#{topic}#{suffix if existing_comments?( "#{user}/#{topic}" )}"
131
+ end
123
132
  unless rejected_topics.empty?
124
133
  sb << "\n" unless review_ut.empty?
125
134
  verb = rejected_topics.size == 1 ? 'is' : 'are'
@@ -261,13 +270,14 @@ module GitTopic
261
270
  report "Your comments have been saved."
262
271
  end
263
272
 
264
- def comments( opts={} )
265
- unless existing_comments?
273
+ def comments( spec=nil, opts={} )
274
+ args = [ spec ].compact
275
+ unless existing_comments? *args
266
276
  puts "There are no comments on this branch."
267
277
  return
268
278
  end
269
279
 
270
- git "log origin/master.. --show-notes=#{notes_ref} --no-standard-notes",
280
+ git "log origin/master.. --show-notes=#{notes_ref *args} --no-standard-notes",
271
281
  :show => true
272
282
  end
273
283
 
@@ -301,6 +311,7 @@ module GitTopic
301
311
  refspecs = [
302
312
  "refs/heads/#{current_branch}:refs/heads/#{rem_rej_branch}",
303
313
  ":refs/heads/#{rem_review_branch}",
314
+ "refs/notes/reviews/*:refs/notes/reviews/*"
304
315
  ].join( " " )
305
316
  git [
306
317
  "checkout master",
@@ -312,6 +323,15 @@ module GitTopic
312
323
  end
313
324
 
314
325
 
326
+ # Setup .git/config.
327
+ #
328
+ # This amounts to setting up refspecs for origin fetching for review
329
+ # comments.
330
+ def setup( opts={} )
331
+ return if has_setup_refspec?
332
+ git "config --add remote.origin.fetch refs/notes/reviews/*:refs/notes/reviews/*"
333
+ end
334
+
315
335
  def install_aliases( opts={} )
316
336
  opts.assert_valid_keys :local, :local_given, *GlobalOptKeys
317
337
 
@@ -350,6 +370,37 @@ module GitTopic
350
370
  end
351
371
  end
352
372
 
373
+
374
+ def check_for_setup
375
+ git_dir = `git rev-parse --git-dir 2> /dev/null`.chomp
376
+ return if git_dir.empty?
377
+
378
+ suppress_whine = `git config topic.checkForNotesRef`.chomp == "false"
379
+ return if suppress_whine
380
+
381
+ unless has_setup_refspec?
382
+ STDERR.puts "
383
+ Warning: git repository is not set up for git topic. Review comments
384
+ will not automatically be pulled on git fetch. You have two options
385
+ for suppressing this message:
386
+
387
+ 1. Run git-topic setup to setup fetch refspecs for origin.
388
+ 2. Run git config topic.checkForNotesRef false.
389
+ If you do this, you can manually fetch reviewers' comments with
390
+ the following command
391
+
392
+ git fetch origin refs/notes/reviews/*:refs/notes/reviews/*
393
+ ".cleanup
394
+ end
395
+ end
396
+
397
+ def has_setup_refspec?
398
+ fetch_refspecs = capture_git( "config --get-all remote.origin.fetch" ).split( "\n" )
399
+ fetch_refspecs.any? do |refspec|
400
+ refspec == "refs/notes/reviews/*:refs/notes/reviews/*"
401
+ end
402
+ end
403
+
353
404
  end
354
405
  end
355
406
 
@@ -26,3 +26,13 @@ _git_reject() {
26
26
  __gitcomp "$(git-topic-completion reject 2> /dev/null)"
27
27
  return
28
28
  }
29
+
30
+ _git_comment() {
31
+ __gitcomp "$(git-topic-completion comment 2> /dev/null)"
32
+ return
33
+ }
34
+
35
+ _git_comments() {
36
+ __gitcomp "$(git-topic-completion comments 2> /dev/null)"
37
+ return
38
+ }
@@ -10,7 +10,6 @@ describe GitTopic do
10
10
  use_repo 'in-progress'
11
11
  GitTopic.review 'user24601/zombie-basic'
12
12
  end
13
- after( :each ) { Dir.chdir '..' }
14
13
 
15
14
  describe "with no specified argument" do
16
15
  it "
@@ -52,7 +51,6 @@ describe GitTopic do
52
51
  @original_git_Head = git_head
53
52
  GitTopic.review 'user24601/zombie-basic'
54
53
  end
55
- after( :each ) { Dir.chdir '..' }
56
54
 
57
55
  it "should refuse to accept the review branch" do
58
56
  git_branch.should == 'review/user24601/zombie-basic'
@@ -67,7 +65,6 @@ describe GitTopic do
67
65
 
68
66
  describe "while not on a review branch" do
69
67
  before( :each ) { use_repo 'in-progress' }
70
- after( :each ) { Dir.chdir '..' }
71
68
 
72
69
  it "should fail" do
73
70
  lambda{ GitTopic.accept }.should raise_error
@@ -125,7 +125,6 @@ describe GitTopic do
125
125
  use_repo 'in-progress'
126
126
  GitTopic.review 'user24601/zombie-basic'
127
127
  end
128
- after( :each ) { Dir.chdir '..' }
129
128
 
130
129
 
131
130
  it "should fail if the diff includes added lines not prefixed with #" do
@@ -249,7 +248,6 @@ describe GitTopic do
249
248
  end
250
249
  end
251
250
  end
252
- after( :each ) { Dir.chdir '..' }
253
251
 
254
252
 
255
253
  it "should fail if the working tree is dirty" do
@@ -326,7 +324,6 @@ describe GitTopic do
326
324
 
327
325
  describe "on a wip branch with no comments" do
328
326
  before( :each ) { use_repo 'in-progress' }
329
- after( :each ) { Dir.chdir '..' }
330
327
 
331
328
  it "should report that there is nothing to do" do
332
329
  GitTopic.work_on 'pirates-advanced'
@@ -351,7 +348,6 @@ describe GitTopic do
351
348
  end
352
349
  end
353
350
  end
354
- after( :each ) { Dir.chdir '..' }
355
351
 
356
352
 
357
353
  it "should fail if the working tree is dirty" do
@@ -5,40 +5,103 @@ describe GitTopic do
5
5
 
6
6
  describe "#comments" do
7
7
 
8
- describe "on a branch with no comments" do
8
+ describe "with an argument" do
9
9
 
10
- before( :each ) do
11
- use_repo 'in-progress'
12
- GitTopic.work_on 'pirates-advanced'
13
- end
14
- after( :each ) { Dir.chdir '..' }
10
+ before( :each ) { use_repo 'in-progress' }
15
11
 
16
- it "should report that there are no comments" do
17
- lambda{ GitTopic.comments }.should_not raise_error
18
- @output.should_not be_nil
19
- @output.should =~ /no comments/i
20
- end
21
- end
22
12
 
13
+ it "shows comments for the supplied topic" do
14
+ git_branch.should == 'master'
15
+ GitTopic.should_receive( :git ) do |cmd|
16
+ cmd.should =~ /log/
17
+ cmd.should =~ %r{origin/master\.\.}
18
+ cmd.should =~ /--no-standard-notes/
19
+ cmd.should =~ %r{--show-notes=refs/notes/reviews/#{@user}/krakens}
20
+ end
21
+ GitTopic.comments 'krakens'
22
+ end
23
23
 
24
- describe "on a branch with comments" do
24
+ it "should strip fully qualified namespaces" do
25
+ git_branch.should == 'master'
26
+ GitTopic.should_receive( :git ) do |cmd|
27
+ cmd.should =~ /log/
28
+ cmd.should =~ %r{origin/master\.\.}
29
+ cmd.should =~ /--no-standard-notes/
30
+ cmd.should =~ %r{--show-notes=refs/notes/reviews/#{@user}/krakens}
31
+ end
32
+ GitTopic.comments "rejected/#{@user}/krakens"
33
+ end
25
34
 
26
- before( :each ) do
27
- use_repo 'in-progress'
28
- GitTopic.work_on 'krakens'
35
+ it "should strip partially qualified namespaces" do
36
+ git_branch.should == 'master'
37
+ GitTopic.should_receive( :git ) do |cmd|
38
+ cmd.should =~ /log/
39
+ cmd.should =~ %r{origin/master\.\.}
40
+ cmd.should =~ /--no-standard-notes/
41
+ cmd.should =~ %r{--show-notes=refs/notes/reviews/#{@user}/krakens}
42
+ end
43
+ GitTopic.comments "#{@user}/krakens"
29
44
  end
30
45
 
31
- after( :each ) { Dir.chdir '..' }
46
+ it "should strip fully qualified namespaces for other users" do
47
+ git_branch.should == 'master'
48
+ GitTopic.should_receive( :git ) do |cmd|
49
+ cmd.should =~ /log/
50
+ cmd.should =~ %r{origin/master\.\.}
51
+ cmd.should =~ /--no-standard-notes/
52
+ cmd.should =~ %r{--show-notes=refs/notes/reviews/user24601/ninja-basic}
53
+ end
54
+ GitTopic.comments "review/user24601/ninja-basic"
55
+ end
32
56
 
33
- it "should invoke git log to display the comments" do
57
+ it "should strip partially qualified namespaces for other users" do
58
+ git_branch.should == 'master'
34
59
  GitTopic.should_receive( :git ) do |cmd|
35
60
  cmd.should =~ /log/
36
61
  cmd.should =~ %r{origin/master\.\.}
37
62
  cmd.should =~ /--no-standard-notes/
38
- cmd.should =~ %r{--show-notes=refs/notes/reviews/#{@user}/krakens}
63
+ cmd.should =~ %r{--show-notes=refs/notes/reviews/user24601/ninja-basic}
39
64
  end
65
+ GitTopic.comments "user24601/ninja-basic"
66
+ end
67
+
68
+ end
40
69
 
41
- lambda{ GitTopic.comments }.should_not raise_error
70
+ describe "with no argument" do
71
+
72
+ describe "on a branch with no comments" do
73
+
74
+ before( :each ) do
75
+ use_repo 'in-progress'
76
+ GitTopic.work_on 'pirates-advanced'
77
+ end
78
+
79
+ it "should report that there are no comments" do
80
+ lambda{ GitTopic.comments }.should_not raise_error
81
+ @output.should_not be_nil
82
+ @output.should =~ /no comments/i
83
+ end
84
+ end
85
+
86
+
87
+ describe "on a branch with comments" do
88
+
89
+ before( :each ) do
90
+ use_repo 'in-progress'
91
+ GitTopic.work_on 'krakens'
92
+ end
93
+
94
+
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\.\.}
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
42
105
  end
43
106
  end
44
107
 
@@ -5,10 +5,22 @@ describe GitTopic do
5
5
 
6
6
  describe "#done" do
7
7
 
8
+ describe "while on a branch with no local refs/notes" do
9
+ before( :each ) { use_repo 'in-progress' }
10
+
11
+ it "should not error on a missing refs/notes" do
12
+ File.exists?(
13
+ "./.git/refs/notes/reviews/"
14
+ ).should == true
15
+ FileUtils.rm_rf "./.git/refs/notes/"
16
+ lambda{ GitTopic.work_on 'krakens' }.should_not raise_error
17
+ lambda{ GitTopic.done }.should_not raise_error
18
+ end
19
+ end
20
+
8
21
  describe "in in-progress" do
9
22
 
10
23
  before( :each ) { use_repo 'in-progress' }
11
- after( :each ) { Dir.chdir '..' }
12
24
 
13
25
  describe "without an argument" do
14
26
 
@@ -39,6 +51,55 @@ describe GitTopic do
39
51
  git_remote_branches.should_not include( "wip/#{@user}/zombie-basic" )
40
52
  git_branch.should == 'master'
41
53
  end
54
+
55
+ it "should push any replies to review comments" do
56
+ GitTopic.stub!( :invoke_git_editor ) do |path|
57
+ File.open( path, 'w' ) do |f|
58
+ f.puts %Q{
59
+ I have some general comments, mostly relating to the quality of our
60
+ zombie-control policies. Basically, they're not working.
61
+ }.cleanup
62
+ end
63
+ end
64
+
65
+ File.open( 'zombies', 'a' ) do |f|
66
+ f.puts %Q{
67
+ # I suggest we do the following instead:
68
+ # zombies.each{ |z| reason_with( z )}
69
+ # zomies.select do |z|
70
+ # z.unconvinced?
71
+ # end.each do |z|
72
+ # destroy z
73
+ # end
74
+ # This should take care of our issues with zombies.
75
+ }.cleanup
76
+ end
77
+ GitTopic.should_receive( :invoke_git_editor ).once
78
+ GitTopic.should_receive(
79
+ :git_author_name_short
80
+ ).once.and_return( "Spec 123" )
81
+
82
+ File.exists?(
83
+ "../origin/refs/notes/reviews/#{@user}/krakens"
84
+ ).should == false
85
+
86
+ lambda do
87
+ GitTopic.work_on 'krakens'
88
+ cmd = [
89
+ "echo 'harder than you might think' >> kraken",
90
+ "git commit kraken -m 'working on krakens'",
91
+ ].join( " && " )
92
+ cmd << " 2> /dev/null > /dev/null"
93
+ system cmd
94
+ GitTopic.comment
95
+ GitTopic.done
96
+ end.should_not raise_error
97
+
98
+ File.exists?(
99
+ "../origin/refs/notes/reviews/#{@user}/krakens"
100
+ ).should == true
101
+ end
102
+
42
103
  end
43
104
 
44
105
  describe "with an argument" do
@@ -22,12 +22,26 @@ describe GitTopic do
22
22
 
23
23
  describe "#reject" do
24
24
 
25
+
26
+ describe "while on a review branch in a repo with no local refs/notes" do
27
+ before( :each ) { use_repo 'in-progress' }
28
+
29
+ it "should not error on a missing refs/notes" do
30
+ File.exists?(
31
+ "./.git/refs/notes/reviews/"
32
+ ).should == true
33
+ FileUtils.rm_rf "./.git/refs/notes/"
34
+ lambda{ GitTopic.review }.should_not raise_error
35
+ lambda{ GitTopic.reject }.should_not raise_error
36
+ end
37
+ end
38
+
39
+
25
40
  describe "while on a review branch" do
26
41
  before( :each ) do
27
42
  use_repo 'in-progress'
28
43
  GitTopic.review 'user24601/zombie-basic'
29
44
  end
30
- after( :each ) { Dir.chdir '..' }
31
45
 
32
46
  describe "with no specified argument" do
33
47
  it "
@@ -43,6 +57,47 @@ describe GitTopic do
43
57
  git_remote_branches.should include( 'rejected/user24601/zombie-basic' )
44
58
  end
45
59
 
60
+ it "should push any review comments" do
61
+ GitTopic.stub!( :invoke_git_editor ) do |path|
62
+ File.open( path, 'w' ) do |f|
63
+ f.puts %Q{
64
+ I have some general comments, mostly relating to the quality of our
65
+ zombie-control policies. Basically, they're not working.
66
+ }.cleanup
67
+ end
68
+ end
69
+
70
+ File.open( 'zombies', 'a' ) do |f|
71
+ f.puts %Q{
72
+ # 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
+ }.cleanup
81
+ end
82
+ GitTopic.should_receive( :invoke_git_editor ).once
83
+ GitTopic.should_receive(
84
+ :git_author_name_short
85
+ ).once.and_return( "Spec 123" )
86
+
87
+ File.exists?(
88
+ "../origin/refs/notes/reviews/user24601/zombie-basic"
89
+ ).should == false
90
+
91
+ lambda do
92
+ GitTopic.comment
93
+ GitTopic.reject
94
+ end.should_not raise_error
95
+
96
+ File.exists?(
97
+ "../origin/refs/notes/reviews/user24601/zombie-basic"
98
+ ).should == true
99
+ end
100
+
46
101
  it "should provide feedback to the user" do
47
102
  GitTopic.reject
48
103
  $?.success?.should == true
@@ -100,7 +155,6 @@ describe GitTopic do
100
155
 
101
156
  describe "while not on a review branch" do
102
157
  before( :each ) { use_repo 'in-progress' }
103
- after( :each ) { Dir.chdir '..' }
104
158
 
105
159
  it "should fail" do
106
160
  lambda{ GitTopic.reject }.should raise_error
@@ -7,7 +7,6 @@ describe GitTopic do
7
7
 
8
8
  describe "with no review branches" do
9
9
  before( :each ) { use_repo 'fresh' }
10
- after( :each ) { Dir.chdir '..' }
11
10
 
12
11
  it "should report that there is nothing to do" do
13
12
  git_remote_branches.each do |b|
@@ -29,7 +28,6 @@ describe GitTopic do
29
28
  end
30
29
  end
31
30
  end
32
- after( :each ) { Dir.chdir '..' }
33
31
 
34
32
  it "should switch to the sole review branch when given no arguments." do
35
33
  git_remote_branches.select do |branch|
@@ -44,7 +42,6 @@ describe GitTopic do
44
42
 
45
43
  describe "with some review branches" do
46
44
  before( :each ) { use_repo 'in-progress' }
47
- after( :each ) { Dir.chdir '..' }
48
45
 
49
46
  it "
50
47
  should create a local tracking branch for the oldest remote review
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe GitTopic do
5
+
6
+ describe "#setup" do
7
+ before( :each ) { use_repo 'in-progress' }
8
+
9
+
10
+ it "should install reviews refspec for origin" do
11
+
12
+ %x{
13
+ git config --get-all remote.origin.fetch
14
+ }.should_not =~ %r{refs/notes}
15
+
16
+ GitTopic.setup
17
+ %x{
18
+ git config --get-all remote.origin.fetch
19
+ }.should =~ %r{refs/notes}
20
+ end
21
+
22
+ it "should be idempotent" do
23
+ File.exists?( ".git/config" ).should == true
24
+ GitTopic.setup
25
+ content = File.read( ".git/config" )
26
+ GitTopic.setup
27
+
28
+ File.read( ".git/config" ).should == content
29
+ end
30
+ end
31
+
32
+ describe "for any non --help command" do
33
+
34
+ describe "when not in a git repository" do
35
+ before( :each ) do
36
+ Dir.chdir '/tmp'
37
+ end
38
+
39
+ it "should not whine" do
40
+ git_dir.should == ""
41
+ GitTopic.run
42
+ @err.should_not =~ /setup/
43
+ end
44
+ end
45
+
46
+ describe "
47
+ when in a git repository that is neither setup nor configured to nowhine
48
+ ".oneline do
49
+
50
+ before( :each ) { use_repo 'in-progress' }
51
+
52
+ it "should ask the user to #setup or configure no-whine" do
53
+ with_argv( [] ) do
54
+ GitTopic.run
55
+ @err.should =~ /setup/
56
+ end
57
+ end
58
+ end
59
+
60
+ describe "when in a git repository configured for nowhining" do
61
+ before( :each ) { use_repo 'in-progress' }
62
+
63
+ it "should not whine, even when refs are not set up" do
64
+ system "git config topic.checkForNotesRef false > /dev/null 2> /dev/null"
65
+ GitTopic.run
66
+ @err.should_not =~ /setup/
67
+ end
68
+ end
69
+
70
+ describe "when in a git repository that is #setup" do
71
+
72
+ before( :each ) { use_repo 'in-progress' }
73
+
74
+ it "
75
+ should not whine, regardless of whether it is configured for whining or
76
+ not
77
+ ".oneline do
78
+
79
+ GitTopic.setup
80
+ GitTopic.run
81
+ @err.should_not =~ /setup/
82
+ end
83
+ end
84
+ end
85
+
86
+ end
@@ -8,7 +8,6 @@ describe GitTopic do
8
8
  describe "with pending review branches" do
9
9
 
10
10
  before( :each ) { use_repo 'in-progress' }
11
- after( :each ) { Dir.chdir '..' }
12
11
 
13
12
 
14
13
  it "should not show my review branches, but it should show others'" do
@@ -52,7 +51,6 @@ describe GitTopic do
52
51
 
53
52
  describe "passed the --prepended flag" do
54
53
  before( :each ) { use_repo 'in-progress' }
55
- after( :each ) { Dir.chdir '..' }
56
54
 
57
55
  it "should invoke git status before producing its output" do
58
56
  GitTopic.status( :prepended => true )
@@ -24,7 +24,6 @@ describe GitTopic do
24
24
 
25
25
  describe "in fresh" do
26
26
  before( :each ) { use_repo( 'fresh' )}
27
- after( :each ) { Dir.chdir( '..' )}
28
27
 
29
28
  it_should_behave_like "#work_on general cases"
30
29
 
@@ -56,7 +55,6 @@ describe GitTopic do
56
55
  describe "in in-progress" do
57
56
 
58
57
  before( :each ) { use_repo( 'in-progress' )}
59
- after( :each ) { Dir.chdir( '..' )}
60
58
 
61
59
  it_should_behave_like "#work_on general cases"
62
60
 
data/spec/spec_helper.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require 'fileutils'
4
4
 
5
5
  require 'git_topic'
6
+ require 'git_topic/cli'
6
7
 
7
8
 
8
9
  # Testing-specific monkeypatching # {{{
@@ -105,7 +106,7 @@ Rspec.configure do |c|
105
106
  end
106
107
  Dir.chdir @starting_dir
107
108
  end
108
- Dir.chdir './tmp'
109
+ Dir.chdir "#{@starting_dir}/tmp"
109
110
 
110
111
  # capture output
111
112
  @output = ''
@@ -127,10 +128,14 @@ end
127
128
  def use_repo( repo )
128
129
  Dir.chdir( repo )
129
130
  # Exit if e.g. GIT_DIR is set
130
- raise "Spec error" unless `git rev-parse --git-dir`.chomp == '.git'
131
+ raise "Spec error" unless git_dir == '.git'
131
132
  end
132
133
 
133
134
 
135
+ def git_dir
136
+ `git rev-parse --git-dir 2> /dev/null`.chomp
137
+ end
138
+
134
139
  def git_branch
135
140
  all_branches = `git branch --no-color`.split( "\n" )
136
141
  current_branch = all_branches.find{|b| b =~ /^\*/}
@@ -190,5 +195,14 @@ def dirty_branch!
190
195
  system "git add -N dirty"
191
196
  end
192
197
 
198
+
199
+ def with_argv( val )
200
+ restore = ARGV.dup
201
+ ARGV.replace( val )
202
+ rv = yield
203
+ ARGV.replace( restore )
204
+ rv
205
+ end
206
+
193
207
  # }}}
194
208
 
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 0
7
7
  - 2
8
8
  - 3
9
- - 1
10
- version: 0.2.3.1
9
+ - 2
10
+ version: 0.2.3.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - David J. Hamilton
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-28 00:00:00 -07:00
18
+ date: 2010-07-29 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -187,6 +187,7 @@ files:
187
187
  - spec/git_topic_install_aliases_spec.rb
188
188
  - spec/git_topic_reject_spec.rb
189
189
  - spec/git_topic_review_spec.rb
190
+ - spec/git_topic_setup_spec.rb
190
191
  - spec/git_topic_status_spec.rb
191
192
  - spec/git_topic_work_on_spec.rb
192
193
  - spec/spec_helper.rb
@@ -302,6 +303,7 @@ test_files:
302
303
  - spec/comment_spec.rb
303
304
  - spec/git_topic_comment_spec.rb
304
305
  - spec/spec_helper.rb
306
+ - spec/git_topic_setup_spec.rb
305
307
  - spec/git_topic_work_on_spec.rb
306
308
  - spec/git_topic_done_spec.rb
307
309
  - spec/bash_completion.rb