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.
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe GitTopic do
5
+
6
+ describe "#comments" do
7
+
8
+ describe "on a branch with no comments" do
9
+
10
+ before( :each ) do
11
+ use_repo 'in-progress'
12
+ GitTopic.work_on 'pirates-advanced'
13
+ end
14
+ after( :each ) { Dir.chdir '..' }
15
+
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
+
23
+
24
+ describe "on a branch with comments" do
25
+
26
+ before( :each ) do
27
+ use_repo 'in-progress'
28
+ GitTopic.work_on 'krakens'
29
+ end
30
+
31
+ after( :each ) { Dir.chdir '..' }
32
+
33
+ it "should invoke git log to display the comments" do
34
+ GitTopic.should_receive( :git ) do |cmd|
35
+ cmd.should =~ /log/
36
+ cmd.should =~ %r{origin/master\.\.}
37
+ cmd.should =~ /--no-standard-notes/
38
+ cmd.should =~ %r{--show-notes=refs/notes/reviews/#{@user}/krakens}
39
+ end
40
+
41
+ lambda{ GitTopic.comments }.should_not raise_error
42
+ end
43
+ end
44
+
45
+ end
46
+
47
+ end
@@ -0,0 +1,94 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe GitTopic do
5
+
6
+ describe "#done" do
7
+
8
+ describe "in in-progress" do
9
+
10
+ before( :each ) { use_repo 'in-progress' }
11
+ after( :each ) { Dir.chdir '..' }
12
+
13
+ describe "without an argument" do
14
+
15
+ it "should fail if the working tree is dirty" do
16
+ GitTopic.work_on 'zombie-basic'
17
+ dirty_branch!
18
+
19
+ lambda{ GitTopic.done }.should raise_error
20
+ end
21
+
22
+ it "should fail if not on a wip branch" do
23
+ `git checkout master > /dev/null 2> /dev/null`
24
+ lambda{ GitTopic.done }.should raise_error
25
+ end
26
+
27
+ it "
28
+ should push the wip branch to origin in the review namespace, delete the
29
+ local branch, and leave the user on master
30
+ ".oneline do
31
+
32
+ git_branches.should include( "wip/#{@user}/zombie-basic" )
33
+ git_remote_branches.should_not include( "review/#{@user}/zombie-basic" )
34
+ GitTopic.work_on 'zombie-basic'
35
+ GitTopic.done
36
+
37
+ git_branches.should_not include( "wip/#{@user}/zombie-basic" )
38
+ git_remote_branches.should include( "review/#{@user}/zombie-basic" )
39
+ git_remote_branches.should_not include( "wip/#{@user}/zombie-basic" )
40
+ git_branch.should == 'master'
41
+ end
42
+ end
43
+
44
+ describe "with an argument" do
45
+
46
+ it "should fail for non-wip branch arguments" do
47
+ git_branches.should_not include( "wip/#{@user}/invalid-branch" )
48
+ lambda{ GitTopic.done( 'invalid-branch' )}.should raise_error
49
+ end
50
+
51
+ it "should succeed for superfluous wip-branch arguments" do
52
+ git_branches.should include( "wip/#{@user}/zombie-basic" )
53
+ git_remote_branches.should_not include( "review/#{@user}/zombie-basic" )
54
+ GitTopic.work_on 'zombie-basic'
55
+ GitTopic.done( 'zombie-basic' )
56
+
57
+ git_branches.should_not include( "wip/#{@user}/zombie-basic" )
58
+ git_remote_branches.should include( "review/#{@user}/zombie-basic" )
59
+ git_remote_branches.should_not include( "wip/#{@user}/zombie-basic" )
60
+ git_branch.should == 'master'
61
+ end
62
+
63
+ it "
64
+ should succeed for wip-branch arguments, and leave the user on the
65
+ same branch
66
+ ".oneline do
67
+ git_branches.should include( "wip/#{@user}/pirates-advanced" )
68
+ git_branches.should include( "wip/#{@user}/zombie-basic" )
69
+ git_remote_branches.should_not include( "review/#{@user}/zombie-basic" )
70
+
71
+ GitTopic.work_on 'pirates-advanced'
72
+ GitTopic.done 'zombie-basic'
73
+
74
+ git_branch.should == "wip/#{@user}/pirates-advanced"
75
+ git_branches.should_not include( "wip/#{@user}/zombie-basic" )
76
+ git_remote_branches.should include( "review/#{@user}/zombie-basic" )
77
+ git_remote_branches.should_not include( "wip/#{@user}/zombie-basic" )
78
+ end
79
+
80
+ it "should succeed for fully-qualified wip-branch arguments" do
81
+ git_branches.should include( "wip/#{@user}/zombie-basic" )
82
+ git_remote_branches.should_not include( "review/#{@user}/zombie-basic" )
83
+ GitTopic.done( "wip/#{@user}/zombie-basic" )
84
+
85
+ git_branches.should_not include( "wip/#{@user}/zombie-basic" )
86
+ git_remote_branches.should include( "review/#{@user}/zombie-basic" )
87
+ git_remote_branches.should_not include( "wip/#{@user}/zombie-basic" )
88
+ git_branch.should == 'master'
89
+ end
90
+ end
91
+ end
92
+ end
93
+
94
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe GitTopic do
5
+
6
+ describe "#install_aliases" do
7
+ it "should install aliases" do
8
+ GitTopic.install_aliases :local => true
9
+ git_config( 'alias.work-on' ).should == 'topic work-on'
10
+ git_config( 'alias.done' ).should == 'topic done'
11
+ git_config( 'alias.review' ).should == 'topic review'
12
+ git_config( 'alias.accept' ).should == 'topic accept'
13
+ git_config( 'alias.reject' ).should == 'topic reject'
14
+ git_config( 'alias.comment' ).should == 'topic comment'
15
+ 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
+ end
21
+
22
+ it "should provide feedback to the user" do
23
+ GitTopic.install_aliases :local => true
24
+ $?.success?.should == true
25
+ @output.should_not be_nil
26
+ @output.should_not be_empty
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+
@@ -0,0 +1,112 @@
1
+ require 'spec_helper'
2
+
3
+ RejectFirstComment = %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
+
8
+ ./zombies
9
+
10
+ Line 2
11
+ Spec 123: I suggest we do the following instead:
12
+ zombies.each{ |z| reason_with( z )}
13
+ zomies.select do |z|
14
+ z.unconvinced?
15
+ end.each do |z|
16
+ destroy z
17
+ end
18
+ This should take care of our issues with zombies.
19
+ }.strip
20
+
21
+ describe GitTopic do
22
+
23
+ describe "#reject" do
24
+
25
+ describe "while on a review branch" do
26
+ before( :each ) do
27
+ use_repo 'in-progress'
28
+ GitTopic.review 'user24601/zombie-basic'
29
+ end
30
+ after( :each ) { Dir.chdir '..' }
31
+
32
+ describe "with no specified argument" do
33
+ it "
34
+ should move branch to the rejected namespace and destroy the local and
35
+ remote review branches
36
+ ".oneline do
37
+
38
+ git_branch.should == 'review/user24601/zombie-basic'
39
+ GitTopic.reject
40
+ git_branch.should == 'master'
41
+ git_branches.should_not include( 'review/user24601/zombie-basic' )
42
+ git_remote_branches.should_not include( 'review/user24601/zombie-basic' )
43
+ git_remote_branches.should include( 'rejected/user24601/zombie-basic' )
44
+ end
45
+
46
+ it "should provide feedback to the user" do
47
+ GitTopic.reject
48
+ $?.success?.should == true
49
+ @output.should_not be_nil
50
+ @output.should_not be_empty
51
+ end
52
+
53
+ it "should auto-save comments with the --save-comments options" do
54
+ GitTopic.stub!( :invoke_git_editor ) do |path|
55
+ File.open( path, 'w' ) do |f|
56
+ f.puts %Q{
57
+ I have some general comments, mostly relating to the quality of our
58
+ zombie-control policies. Basically, they're not working.
59
+ }.cleanup
60
+ end
61
+ end
62
+
63
+ File.open( 'zombies', 'a' ) do |f|
64
+ f.puts %Q{
65
+ # I suggest we do the following instead:
66
+ # zombies.each{ |z| reason_with( z )}
67
+ # zomies.select do |z|
68
+ # z.unconvinced?
69
+ # end.each do |z|
70
+ # destroy z
71
+ # end
72
+ # This should take care of our issues with zombies.
73
+ }.cleanup
74
+ end
75
+ GitTopic.should_receive( :invoke_git_editor ).once
76
+ GitTopic.should_receive(
77
+ :git_author_name_short
78
+ ).once.and_return( "Spec 123" )
79
+
80
+ lambda do
81
+ GitTopic.reject :save_comments => true
82
+ end.should_not raise_error
83
+
84
+ git_notes_list(
85
+ "refs/notes/reviews/user24601/zombie-basic"
86
+ ).should_not be_empty
87
+
88
+ git_notes_show(
89
+ "refs/notes/reviews/user24601/zombie-basic",
90
+ "origin/rejected/user24601/zombie-basic"
91
+ ).should == RejectFirstComment
92
+ end
93
+
94
+ it "should fail if the working tree is dirty" do
95
+ dirty_branch!
96
+ lambda{ GitTopic.reject }.should raise_error
97
+ end
98
+ end
99
+ end
100
+
101
+ describe "while not on a review branch" do
102
+ before( :each ) { use_repo 'in-progress' }
103
+ after( :each ) { Dir.chdir '..' }
104
+
105
+ it "should fail" do
106
+ lambda{ GitTopic.reject }.should raise_error
107
+ end
108
+ end
109
+
110
+ end
111
+
112
+ end
@@ -0,0 +1,115 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe GitTopic do
5
+
6
+ describe "#review" do
7
+
8
+ describe "with no review branches" do
9
+ before( :each ) { use_repo 'fresh' }
10
+ after( :each ) { Dir.chdir '..' }
11
+
12
+ it "should report that there is nothing to do" do
13
+ git_remote_branches.each do |b|
14
+ b.should_not =~ /review/
15
+ end
16
+
17
+ GitTopic.review
18
+ @output.should =~ /nothing to review/
19
+ end
20
+ end
21
+
22
+ describe "with exactly one review branch" do
23
+ before( :each ) do
24
+ use_repo 'in-progress'
25
+ seen_a_review_b = false
26
+ git_remote_branches.each do |b|
27
+ if b =~ %r{review/user24601/(?!zombie-basic)}
28
+ system "git push origin :refs/heads/#{b} > /dev/null 2> /dev/null"
29
+ end
30
+ end
31
+ end
32
+ after( :each ) { Dir.chdir '..' }
33
+
34
+ it "should switch to the sole review branch when given no arguments." do
35
+ git_remote_branches.select do |branch|
36
+ branch =~ %r{review/user24601}
37
+ end.should == ['review/user24601/zombie-basic']
38
+ GitTopic.review
39
+ git_branch.should == 'review/user24601/zombie-basic'
40
+ git_branch_remote.should == 'origin'
41
+ git_branch_merge.should == 'refs/heads/review/user24601/zombie-basic'
42
+ end
43
+ end
44
+
45
+ describe "with some review branches" do
46
+ before( :each ) { use_repo 'in-progress' }
47
+ after( :each ) { Dir.chdir '..' }
48
+
49
+ it "
50
+ should create a local tracking branch for the oldest remote review
51
+ branch if none was specified
52
+ ".oneline do
53
+
54
+ git_remote_branches.should include 'review/user24601/zombie-basic'
55
+ GitTopic.review
56
+ git_branch.should == 'review/user24601/zombie-basic'
57
+ git_branch_remote.should == 'origin'
58
+ git_branch_merge.should == 'refs/heads/review/user24601/zombie-basic'
59
+ end
60
+
61
+ it "should use the local tracking branch, if one exists" do
62
+ git_remote_branches.should include 'review/user24601/zombie-basic'
63
+
64
+ GitTopic.review 'zombie-basic'
65
+ system "git checkout master > /dev/null 2> /dev/null"
66
+
67
+ git_branch.should == "master"
68
+ lambda do
69
+ GitTopic.review 'zombie-basic'
70
+ end.should_not raise_error
71
+ git_branch.should == "review/user24601/zombie-basic"
72
+ end
73
+
74
+ it "should provide feedback to the user" do
75
+ GitTopic.review
76
+ $?.success?.should == true
77
+ @output.should_not be_nil
78
+ @output.should_not be_empty
79
+ end
80
+
81
+ it "should create a local tracking branch for the specified topic" do
82
+ git_remote_branches.should include 'review/user24601/ninja-basic'
83
+ GitTopic.review( 'user24601/ninja-basic' )
84
+ git_branch.should == 'review/user24601/ninja-basic'
85
+ git_branch_remote.should == 'origin'
86
+ git_branch_merge.should == 'refs/heads/review/user24601/ninja-basic'
87
+ end
88
+
89
+ it "
90
+ should accept only a topic arg (vice <user>/<topic>) when the topic is
91
+ unambiguous.
92
+ ".oneline do
93
+ git_remote_branches.should include 'review/user24601/ninja-basic'
94
+ GitTopic.review( 'ninja-basic' )
95
+ git_branch.should == 'review/user24601/ninja-basic'
96
+ git_branch_remote.should == 'origin'
97
+ git_branch_merge.should == 'refs/heads/review/user24601/ninja-basic'
98
+ end
99
+
100
+ it "should handle fully-qualified topic args" do
101
+ git_remote_branches.should include 'review/user24601/ninja-basic'
102
+ lambda{ GitTopic.review( 'review/user24601/ninja-basic' )}.should_not raise_error
103
+ git_branch.should == 'review/user24601/ninja-basic'
104
+ git_branch_remote.should == 'origin'
105
+ git_branch_merge.should == 'refs/heads/review/user24601/ninja-basic'
106
+ end
107
+
108
+ it "should error if an illegal topic is specified" do
109
+ lambda{ GitTopic.review( 'fakeuser/faketopic' )}.should raise_error
110
+ end
111
+ end
112
+
113
+ end
114
+
115
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe GitTopic do
5
+
6
+ describe "#status" do
7
+
8
+ describe "with pending review branches" do
9
+
10
+ before( :each ) { use_repo 'in-progress' }
11
+ after( :each ) { Dir.chdir '..' }
12
+
13
+
14
+ it "should not show my review branches, but it should show others'" do
15
+ git_remote_branches.should include "review/#{@user}/pirates"
16
+
17
+ GitTopic.status
18
+ @output.should_not be_nil
19
+
20
+ @output.should_not =~ /^#\s*pirates\s*$/m
21
+ @output.should =~ /^#\s*ninja-basic\s*$/m
22
+ @output.should =~ /^#\s*zombie-basic\s*$/m
23
+ end
24
+
25
+ it "should not show others' rejected topics" do
26
+ git_remote_branches.should include 'review/user24601/ninja-basic'
27
+ GitTopic.review 'user24601/ninja-basic'
28
+ GitTopic.reject
29
+ git_remote_branches.should_not include 'review/user24601/ninja-basic'
30
+ git_remote_branches.should include 'rejected/user24601/ninja-basic'
31
+
32
+ @output.clear
33
+ GitTopic.status
34
+ @output.should_not =~ %r{ninja-basic}
35
+ end
36
+
37
+ it "
38
+ should show my rejected topics, and note that they have comments, when
39
+ they do.
40
+ " do
41
+ git_remote_branches.should include "rejected/#{@user}/krakens"
42
+ GitTopic.status
43
+ @output.should_not be_nil
44
+
45
+ @output.should =~ /^#\s*krakens\s*\(reviewer comments\)\s*$/m
46
+ end
47
+
48
+ end
49
+
50
+
51
+ describe "passed the --prepended flag" do
52
+ before( :each ) { use_repo 'in-progress' }
53
+ after( :each ) { Dir.chdir '..' }
54
+
55
+ it "should invoke git status before producing its output" do
56
+ GitTopic.status( :prepended => true )
57
+ @output.should_not be_nil
58
+ @output.should =~ /# On branch master/
59
+ end
60
+ end
61
+ end
62
+
63
+ end