-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathgit_process_spec.rb
218 lines (145 loc) · 5.41 KB
/
git_process_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
require File.dirname(__FILE__) + '/../lib/git-process/git_process'
require 'GitRepoHelper'
require 'climate_control'
require 'fileutils'
describe GitProc::Process do
include GitRepoHelper
def log_level
Logger::ERROR
end
before(:each) do
create_files(%w(.gitignore))
gitlib.commit('initial')
end
after(:each) do
rm_rf(gitlib.workdir)
end
around do |example|
# make sure there aren't side-effects testing from the testing user's .gitconfig
ClimateControl.modify HOME: '/path_that_does_not_exist' do
example.run
end
end
describe 'run lifecycle' do
it 'should call the standard hooks' do
proc = GitProc::Process.new(gitlib)
proc.should_receive(:verify_preconditions)
proc.should_receive(:runner)
proc.should_receive(:cleanup)
proc.should_not_receive(:exit)
proc.run
end
it 'should call "cleanup" even if there is an error' do
proc = GitProc::Process.new(gitlib)
proc.should_receive(:verify_preconditions)
proc.should_receive(:runner).and_raise(GitProc::GitProcessError.new('Error!'))
proc.should_receive(:cleanup)
proc.should_receive(:exit)
proc.should_receive(:puts).with('Error!')
proc.run
end
end
describe 'validate local integration branch' do
it 'should use remove the int-branch if not on it and not blocked' do
clone_repo('master') do |gl|
gl.checkout('fb', :new_branch => 'master')
gp = GitProc::Process.new(gl)
gp.stub(:ask_about_removing_master).and_return(true)
gp.verify_preconditions
gl.branches.include?('master').should be false
end
end
it 'should ask to remove the int-branch if not on it and not blocked' do
clone_repo('master') do |gl|
gl.checkout('fb', :new_branch => 'master')
gp = GitProc::Process.new(gl)
gp.should_receive(:ask_about_removing_master).and_return(true)
gp.verify_preconditions
gl.branches.include?('master').should be false
end
end
it 'should ask to remove the int-branch if not on it and not blocked and not remove if answered no' do
clone_repo('master') do |gl|
gl.checkout('fb', :new_branch => 'master')
gp = GitProc::Process.new(gl)
gp.should_receive(:ask_about_removing_master).and_return(false)
gp.verify_preconditions
gl.branches.include?('master').should be true
end
end
it 'should not remove the int-branch if on it' do
clone_repo('master') do |gl|
gp = GitProc::Process.new(gl)
gp.verify_preconditions
gl.branches.include?('master').should be true
end
end
it 'should not remove the int-branch if blocked' do
clone_repo('master') do |gl|
gl.config['gitProcess.keepLocalIntegrationBranch'] = 'true'
gl.checkout('fb', :new_branch => 'master')
gp = GitProc::Process.new(gl)
gp.verify_preconditions
gl.branches.include?('master').should be true
end
end
describe 'local vs remote branch status' do
before(:each) do
change_file_and_commit('a.txt', 'a content', gitlib)
change_file_and_commit('b.txt', 'b content', gitlib)
end
it 'should not remove if both have changes' do
clone_repo('master') do |gl|
change_file_and_commit('c.txt', 'c on origin/master', gitlib)
change_file_and_commit('d.txt', 'd on master', gl)
gl.checkout('fb', :new_branch => 'master')
gl.fetch
gp = GitProc::Process.new(gl)
gp.stub(:ask_about_removing_master).and_return(false)
gp.verify_preconditions
gl.branches.include?('master').should be true
end
end
it 'should remove if server changed but not local' do
clone_repo('master') do |gl|
gp = GitProc::Process.new(gl)
gp.stub(:ask_about_removing_master).and_return(true)
change_file_and_commit('c.txt', 'c on origin/master', gitlib)
gl.checkout('fb', :new_branch => 'master')
gl.fetch
gp.verify_preconditions
gl.branches.include?('master').should be false
end
end
it 'should not remove if server did not change but local did' do
clone_repo('master') do |gl|
change_file_and_commit('c.txt', 'c on master', gl)
gl.checkout('fb', :new_branch => 'master')
gl.fetch
gp = GitProc::Process.new(gl)
gp.stub(:ask_about_removing_master).and_return(false)
gp.verify_preconditions
gl.branches.include?('master').should be true
end
end
it 'should remove if server and local are the same' do
change_file_and_commit('c.txt', 'c on origin/master', gitlib)
clone_repo('master') do |gl|
gl.checkout('fb', :new_branch => 'master')
gp = GitProc::Process.new(gl)
gp.stub(:ask_about_removing_master).and_return(true)
gl.fetch
gp.verify_preconditions
gl.branches.include?('master').should be false
end
end
end
it 'should not remove the int-branch if not a clone' do
gitlib.config['gitProcess.keepLocalIntegrationBranch'] = 'false'
gitlib.checkout('fb', :new_branch => 'master')
gitprocess = GitProc::Process.new(gitlib)
gitprocess.verify_preconditions
gitlib.branches.include?('master').should be true
end
end
end