|
1 | NO CONTENT: modified file, binary diff hidden |
@@ -1,493 +1,493 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2011 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class RepositoriesGitControllerTest < ActionController::TestCase |
|
21 | 21 | tests RepositoriesController |
|
22 | 22 | |
|
23 | 23 | fixtures :projects, :users, :roles, :members, :member_roles, |
|
24 | 24 | :repositories, :enabled_modules |
|
25 | 25 | |
|
26 | 26 | REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s |
|
27 | 27 | REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin? |
|
28 | 28 | PRJ_ID = 3 |
|
29 | 29 | CHAR_1_HEX = "\xc3\x9c" |
|
30 |
NUM_REV = 2 |
|
|
30 | NUM_REV = 28 | |
|
31 | 31 | |
|
32 | 32 | ## Git, Mercurial and CVS path encodings are binary. |
|
33 | 33 | ## Subversion supports URL encoding for path. |
|
34 | 34 | ## Redmine Mercurial adapter and extension use URL encoding. |
|
35 | 35 | ## Git accepts only binary path in command line parameter. |
|
36 | 36 | ## So, there is no way to use binary command line parameter in JRuby. |
|
37 | 37 | JRUBY_SKIP = (RUBY_PLATFORM == 'java') |
|
38 | 38 | JRUBY_SKIP_STR = "TODO: This test fails in JRuby" |
|
39 | 39 | |
|
40 | 40 | def setup |
|
41 | 41 | @ruby19_non_utf8_pass = |
|
42 | 42 | (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8') |
|
43 | 43 | |
|
44 | 44 | User.current = nil |
|
45 | 45 | @project = Project.find(PRJ_ID) |
|
46 | 46 | @repository = Repository::Git.create( |
|
47 | 47 | :project => @project, |
|
48 | 48 | :url => REPOSITORY_PATH, |
|
49 | 49 | :path_encoding => 'ISO-8859-1' |
|
50 | 50 | ) |
|
51 | 51 | assert @repository |
|
52 | 52 | @char_1 = CHAR_1_HEX.dup |
|
53 | 53 | if @char_1.respond_to?(:force_encoding) |
|
54 | 54 | @char_1.force_encoding('UTF-8') |
|
55 | 55 | end |
|
56 | 56 | |
|
57 | 57 | Setting.default_language = 'en' |
|
58 | 58 | end |
|
59 | 59 | |
|
60 | 60 | if File.directory?(REPOSITORY_PATH) |
|
61 | 61 | def test_get_new |
|
62 | 62 | @request.session[:user_id] = 1 |
|
63 | 63 | @project.repository.destroy |
|
64 | 64 | get :new, :project_id => 'subproject1', :repository_scm => 'Git' |
|
65 | 65 | assert_response :success |
|
66 | 66 | assert_template 'new' |
|
67 | 67 | assert_kind_of Repository::Git, assigns(:repository) |
|
68 | 68 | assert assigns(:repository).new_record? |
|
69 | 69 | end |
|
70 | 70 | |
|
71 | 71 | def test_browse_root |
|
72 | 72 | assert_equal 0, @repository.changesets.count |
|
73 | 73 | @repository.fetch_changesets |
|
74 | 74 | @project.reload |
|
75 | 75 | assert_equal NUM_REV, @repository.changesets.count |
|
76 | 76 | |
|
77 | 77 | get :show, :id => PRJ_ID |
|
78 | 78 | assert_response :success |
|
79 | 79 | assert_template 'show' |
|
80 | 80 | assert_not_nil assigns(:entries) |
|
81 | 81 | assert_equal 9, assigns(:entries).size |
|
82 | 82 | assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} |
|
83 | 83 | assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'} |
|
84 | 84 | assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} |
|
85 | 85 | assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} |
|
86 | 86 | assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'} |
|
87 | 87 | assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'} |
|
88 | 88 | assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'} |
|
89 | 89 | assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'} |
|
90 | 90 | assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'} |
|
91 | 91 | assert_not_nil assigns(:changesets) |
|
92 | 92 | assert assigns(:changesets).size > 0 |
|
93 | 93 | end |
|
94 | 94 | |
|
95 | 95 | def test_browse_branch |
|
96 | 96 | assert_equal 0, @repository.changesets.count |
|
97 | 97 | @repository.fetch_changesets |
|
98 | 98 | @project.reload |
|
99 | 99 | assert_equal NUM_REV, @repository.changesets.count |
|
100 | 100 | get :show, :id => PRJ_ID, :rev => 'test_branch' |
|
101 | 101 | assert_response :success |
|
102 | 102 | assert_template 'show' |
|
103 | 103 | assert_not_nil assigns(:entries) |
|
104 | 104 | assert_equal 4, assigns(:entries).size |
|
105 | 105 | assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} |
|
106 | 106 | assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} |
|
107 | 107 | assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} |
|
108 | 108 | assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'} |
|
109 | 109 | assert_not_nil assigns(:changesets) |
|
110 | 110 | assert assigns(:changesets).size > 0 |
|
111 | 111 | end |
|
112 | 112 | |
|
113 | 113 | def test_browse_tag |
|
114 | 114 | assert_equal 0, @repository.changesets.count |
|
115 | 115 | @repository.fetch_changesets |
|
116 | 116 | @project.reload |
|
117 | 117 | assert_equal NUM_REV, @repository.changesets.count |
|
118 | 118 | [ |
|
119 | 119 | "tag00.lightweight", |
|
120 | 120 | "tag01.annotated", |
|
121 | 121 | ].each do |t1| |
|
122 | 122 | get :show, :id => PRJ_ID, :rev => t1 |
|
123 | 123 | assert_response :success |
|
124 | 124 | assert_template 'show' |
|
125 | 125 | assert_not_nil assigns(:entries) |
|
126 | 126 | assert assigns(:entries).size > 0 |
|
127 | 127 | assert_not_nil assigns(:changesets) |
|
128 | 128 | assert assigns(:changesets).size > 0 |
|
129 | 129 | end |
|
130 | 130 | end |
|
131 | 131 | |
|
132 | 132 | def test_browse_directory |
|
133 | 133 | assert_equal 0, @repository.changesets.count |
|
134 | 134 | @repository.fetch_changesets |
|
135 | 135 | @project.reload |
|
136 | 136 | assert_equal NUM_REV, @repository.changesets.count |
|
137 | 137 | get :show, :id => PRJ_ID, :path => ['images'] |
|
138 | 138 | assert_response :success |
|
139 | 139 | assert_template 'show' |
|
140 | 140 | assert_not_nil assigns(:entries) |
|
141 | 141 | assert_equal ['edit.png'], assigns(:entries).collect(&:name) |
|
142 | 142 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} |
|
143 | 143 | assert_not_nil entry |
|
144 | 144 | assert_equal 'file', entry.kind |
|
145 | 145 | assert_equal 'images/edit.png', entry.path |
|
146 | 146 | assert_not_nil assigns(:changesets) |
|
147 | 147 | assert assigns(:changesets).size > 0 |
|
148 | 148 | end |
|
149 | 149 | |
|
150 | 150 | def test_browse_at_given_revision |
|
151 | 151 | assert_equal 0, @repository.changesets.count |
|
152 | 152 | @repository.fetch_changesets |
|
153 | 153 | @project.reload |
|
154 | 154 | assert_equal NUM_REV, @repository.changesets.count |
|
155 | 155 | get :show, :id => PRJ_ID, :path => ['images'], |
|
156 | 156 | :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518' |
|
157 | 157 | assert_response :success |
|
158 | 158 | assert_template 'show' |
|
159 | 159 | assert_not_nil assigns(:entries) |
|
160 | 160 | assert_equal ['delete.png'], assigns(:entries).collect(&:name) |
|
161 | 161 | assert_not_nil assigns(:changesets) |
|
162 | 162 | assert assigns(:changesets).size > 0 |
|
163 | 163 | end |
|
164 | 164 | |
|
165 | 165 | def test_changes |
|
166 | 166 | get :changes, :id => PRJ_ID, :path => ['images', 'edit.png'] |
|
167 | 167 | assert_response :success |
|
168 | 168 | assert_template 'changes' |
|
169 | 169 | assert_tag :tag => 'h2', :content => 'edit.png' |
|
170 | 170 | end |
|
171 | 171 | |
|
172 | 172 | def test_entry_show |
|
173 | 173 | get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'] |
|
174 | 174 | assert_response :success |
|
175 | 175 | assert_template 'entry' |
|
176 | 176 | # Line 19 |
|
177 | 177 | assert_tag :tag => 'th', |
|
178 | 178 | :content => '11', |
|
179 | 179 | :attributes => { :class => 'line-num' }, |
|
180 | 180 | :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ } |
|
181 | 181 | end |
|
182 | 182 | |
|
183 | 183 | def test_entry_show_latin_1 |
|
184 | 184 | if @ruby19_non_utf8_pass |
|
185 | 185 | puts_ruby19_non_utf8_pass() |
|
186 | 186 | elsif JRUBY_SKIP |
|
187 | 187 | puts JRUBY_SKIP_STR |
|
188 | 188 | else |
|
189 | 189 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do |
|
190 | 190 | ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1| |
|
191 | 191 | get :entry, :id => PRJ_ID, |
|
192 | 192 | :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1 |
|
193 | 193 | assert_response :success |
|
194 | 194 | assert_template 'entry' |
|
195 | 195 | assert_tag :tag => 'th', |
|
196 | 196 | :content => '1', |
|
197 | 197 | :attributes => { :class => 'line-num' }, |
|
198 | 198 | :sibling => { :tag => 'td', |
|
199 | 199 | :content => /test-#{@char_1}.txt/ } |
|
200 | 200 | end |
|
201 | 201 | end |
|
202 | 202 | end |
|
203 | 203 | end |
|
204 | 204 | |
|
205 | 205 | def test_entry_download |
|
206 | 206 | get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'], |
|
207 | 207 | :format => 'raw' |
|
208 | 208 | assert_response :success |
|
209 | 209 | # File content |
|
210 | 210 | assert @response.body.include?('WITHOUT ANY WARRANTY') |
|
211 | 211 | end |
|
212 | 212 | |
|
213 | 213 | def test_directory_entry |
|
214 | 214 | get :entry, :id => PRJ_ID, :path => ['sources'] |
|
215 | 215 | assert_response :success |
|
216 | 216 | assert_template 'show' |
|
217 | 217 | assert_not_nil assigns(:entry) |
|
218 | 218 | assert_equal 'sources', assigns(:entry).name |
|
219 | 219 | end |
|
220 | 220 | |
|
221 | 221 | def test_diff |
|
222 | 222 | assert_equal 0, @repository.changesets.count |
|
223 | 223 | @repository.fetch_changesets |
|
224 | 224 | @project.reload |
|
225 | 225 | assert_equal NUM_REV, @repository.changesets.count |
|
226 | 226 | # Full diff of changeset 2f9c0091 |
|
227 | 227 | ['inline', 'sbs'].each do |dt| |
|
228 | 228 | get :diff, |
|
229 | 229 | :id => PRJ_ID, |
|
230 | 230 | :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7', |
|
231 | 231 | :type => dt |
|
232 | 232 | assert_response :success |
|
233 | 233 | assert_template 'diff' |
|
234 | 234 | # Line 22 removed |
|
235 | 235 | assert_tag :tag => 'th', |
|
236 | 236 | :content => /22/, |
|
237 | 237 | :sibling => { :tag => 'td', |
|
238 | 238 | :attributes => { :class => /diff_out/ }, |
|
239 | 239 | :content => /def remove/ } |
|
240 | 240 | assert_tag :tag => 'h2', :content => /2f9c0091/ |
|
241 | 241 | end |
|
242 | 242 | end |
|
243 | 243 | |
|
244 | 244 | def test_diff_truncated |
|
245 | 245 | assert_equal 0, @repository.changesets.count |
|
246 | 246 | @repository.fetch_changesets |
|
247 | 247 | @project.reload |
|
248 | 248 | assert_equal NUM_REV, @repository.changesets.count |
|
249 | 249 | Setting.diff_max_lines_displayed = 5 |
|
250 | 250 | |
|
251 | 251 | # Truncated diff of changeset 2f9c0091 |
|
252 | 252 | with_cache do |
|
253 | 253 | get :diff, :id => PRJ_ID, :type => 'inline', |
|
254 | 254 | :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7' |
|
255 | 255 | assert_response :success |
|
256 | 256 | assert @response.body.include?("... This diff was truncated") |
|
257 | 257 | |
|
258 | 258 | Setting.default_language = 'fr' |
|
259 | 259 | get :diff, :id => PRJ_ID, :type => 'inline', |
|
260 | 260 | :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7' |
|
261 | 261 | assert_response :success |
|
262 | 262 | assert ! @response.body.include?("... This diff was truncated") |
|
263 | 263 | assert @response.body.include?("... Ce diff") |
|
264 | 264 | end |
|
265 | 265 | end |
|
266 | 266 | |
|
267 | 267 | def test_diff_two_revs |
|
268 | 268 | assert_equal 0, @repository.changesets.count |
|
269 | 269 | @repository.fetch_changesets |
|
270 | 270 | @project.reload |
|
271 | 271 | assert_equal NUM_REV, @repository.changesets.count |
|
272 | 272 | ['inline', 'sbs'].each do |dt| |
|
273 | 273 | get :diff, |
|
274 | 274 | :id => PRJ_ID, |
|
275 | 275 | :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1', |
|
276 | 276 | :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7', |
|
277 | 277 | :type => dt |
|
278 | 278 | assert_response :success |
|
279 | 279 | assert_template 'diff' |
|
280 | 280 | diff = assigns(:diff) |
|
281 | 281 | assert_not_nil diff |
|
282 | 282 | assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/ |
|
283 | 283 | end |
|
284 | 284 | end |
|
285 | 285 | |
|
286 | 286 | def test_diff_latin_1 |
|
287 | 287 | if @ruby19_non_utf8_pass |
|
288 | 288 | puts_ruby19_non_utf8_pass() |
|
289 | 289 | else |
|
290 | 290 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do |
|
291 | 291 | ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1| |
|
292 | 292 | ['inline', 'sbs'].each do |dt| |
|
293 | 293 | get :diff, :id => PRJ_ID, :rev => r1, :type => dt |
|
294 | 294 | assert_response :success |
|
295 | 295 | assert_template 'diff' |
|
296 | 296 | assert_tag :tag => 'thead', |
|
297 | 297 | :descendant => { |
|
298 | 298 | :tag => 'th', |
|
299 | 299 | :attributes => { :class => 'filename' } , |
|
300 | 300 | :content => /latin-1-dir\/test-#{@char_1}.txt/ , |
|
301 | 301 | }, |
|
302 | 302 | :sibling => { |
|
303 | 303 | :tag => 'tbody', |
|
304 | 304 | :descendant => { |
|
305 | 305 | :tag => 'td', |
|
306 | 306 | :attributes => { :class => /diff_in/ }, |
|
307 | 307 | :content => /test-#{@char_1}.txt/ |
|
308 | 308 | } |
|
309 | 309 | } |
|
310 | 310 | end |
|
311 | 311 | end |
|
312 | 312 | end |
|
313 | 313 | end |
|
314 | 314 | end |
|
315 | 315 | |
|
316 | 316 | def test_save_diff_type |
|
317 | 317 | @request.session[:user_id] = 1 # admin |
|
318 | 318 | user = User.find(1) |
|
319 | 319 | get :diff, |
|
320 | 320 | :id => PRJ_ID, |
|
321 | 321 | :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7' |
|
322 | 322 | assert_response :success |
|
323 | 323 | assert_template 'diff' |
|
324 | 324 | user.reload |
|
325 | 325 | assert_equal "inline", user.pref[:diff_type] |
|
326 | 326 | get :diff, |
|
327 | 327 | :id => PRJ_ID, |
|
328 | 328 | :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7', |
|
329 | 329 | :type => 'sbs' |
|
330 | 330 | assert_response :success |
|
331 | 331 | assert_template 'diff' |
|
332 | 332 | user.reload |
|
333 | 333 | assert_equal "sbs", user.pref[:diff_type] |
|
334 | 334 | end |
|
335 | 335 | |
|
336 | 336 | def test_annotate |
|
337 | 337 | get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'] |
|
338 | 338 | assert_response :success |
|
339 | 339 | assert_template 'annotate' |
|
340 | 340 | # Line 24, changeset 2f9c0091 |
|
341 | 341 | assert_tag :tag => 'th', :content => '24', |
|
342 | 342 | :sibling => { |
|
343 | 343 | :tag => 'td', |
|
344 | 344 | :child => { |
|
345 | 345 | :tag => 'a', |
|
346 | 346 | :content => /2f9c0091/ |
|
347 | 347 | } |
|
348 | 348 | } |
|
349 | 349 | assert_tag :tag => 'th', :content => '24', |
|
350 | 350 | :sibling => { :tag => 'td', :content => /jsmith/ } |
|
351 | 351 | assert_tag :tag => 'th', :content => '24', |
|
352 | 352 | :sibling => { |
|
353 | 353 | :tag => 'td', |
|
354 | 354 | :child => { |
|
355 | 355 | :tag => 'a', |
|
356 | 356 | :content => /2f9c0091/ |
|
357 | 357 | } |
|
358 | 358 | } |
|
359 | 359 | assert_tag :tag => 'th', :content => '24', |
|
360 | 360 | :sibling => { :tag => 'td', :content => /watcher =/ } |
|
361 | 361 | end |
|
362 | 362 | |
|
363 | 363 | def test_annotate_at_given_revision |
|
364 | 364 | assert_equal 0, @repository.changesets.count |
|
365 | 365 | @repository.fetch_changesets |
|
366 | 366 | @project.reload |
|
367 | 367 | assert_equal NUM_REV, @repository.changesets.count |
|
368 | 368 | get :annotate, :id => PRJ_ID, :rev => 'deff7', |
|
369 | 369 | :path => ['sources', 'watchers_controller.rb'] |
|
370 | 370 | assert_response :success |
|
371 | 371 | assert_template 'annotate' |
|
372 | 372 | assert_tag :tag => 'h2', :content => /@ deff712f/ |
|
373 | 373 | end |
|
374 | 374 | |
|
375 | 375 | def test_annotate_binary_file |
|
376 | 376 | get :annotate, :id => PRJ_ID, :path => ['images', 'edit.png'] |
|
377 | 377 | assert_response 500 |
|
378 | 378 | assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ }, |
|
379 | 379 | :content => /cannot be annotated/ |
|
380 | 380 | end |
|
381 | 381 | |
|
382 | 382 | def test_annotate_error_when_too_big |
|
383 | 383 | with_settings :file_max_size_displayed => 1 do |
|
384 | 384 | get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'], :rev => 'deff712f' |
|
385 | 385 | assert_response 500 |
|
386 | 386 | assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ }, |
|
387 | 387 | :content => /exceeds the maximum text file size/ |
|
388 | 388 | |
|
389 | 389 | get :annotate, :id => PRJ_ID, :path => ['README'], :rev => '7234cb2' |
|
390 | 390 | assert_response :success |
|
391 | 391 | assert_template 'annotate' |
|
392 | 392 | end |
|
393 | 393 | end |
|
394 | 394 | |
|
395 | 395 | def test_annotate_latin_1 |
|
396 | 396 | if @ruby19_non_utf8_pass |
|
397 | 397 | puts_ruby19_non_utf8_pass() |
|
398 | 398 | elsif JRUBY_SKIP |
|
399 | 399 | puts JRUBY_SKIP_STR |
|
400 | 400 | else |
|
401 | 401 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do |
|
402 | 402 | ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1| |
|
403 | 403 | get :annotate, :id => PRJ_ID, |
|
404 | 404 | :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1 |
|
405 | 405 | assert_tag :tag => 'th', |
|
406 | 406 | :content => '1', |
|
407 | 407 | :attributes => { :class => 'line-num' }, |
|
408 | 408 | :sibling => { :tag => 'td', |
|
409 | 409 | :content => /test-#{@char_1}.txt/ } |
|
410 | 410 | end |
|
411 | 411 | end |
|
412 | 412 | end |
|
413 | 413 | end |
|
414 | 414 | |
|
415 | 415 | def test_revision |
|
416 | 416 | assert_equal 0, @repository.changesets.count |
|
417 | 417 | @repository.fetch_changesets |
|
418 | 418 | @project.reload |
|
419 | 419 | assert_equal NUM_REV, @repository.changesets.count |
|
420 | 420 | ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r| |
|
421 | 421 | get :revision, :id => PRJ_ID, :rev => r |
|
422 | 422 | assert_response :success |
|
423 | 423 | assert_template 'revision' |
|
424 | 424 | end |
|
425 | 425 | end |
|
426 | 426 | |
|
427 | 427 | def test_empty_revision |
|
428 | 428 | assert_equal 0, @repository.changesets.count |
|
429 | 429 | @repository.fetch_changesets |
|
430 | 430 | @project.reload |
|
431 | 431 | assert_equal NUM_REV, @repository.changesets.count |
|
432 | 432 | ['', ' ', nil].each do |r| |
|
433 | 433 | get :revision, :id => PRJ_ID, :rev => r |
|
434 | 434 | assert_response 404 |
|
435 | 435 | assert_error_tag :content => /was not found/ |
|
436 | 436 | end |
|
437 | 437 | end |
|
438 | 438 | |
|
439 | 439 | def test_destroy_valid_repository |
|
440 | 440 | @request.session[:user_id] = 1 # admin |
|
441 | 441 | assert_equal 0, @repository.changesets.count |
|
442 | 442 | @repository.fetch_changesets |
|
443 | 443 | @project.reload |
|
444 | 444 | assert_equal NUM_REV, @repository.changesets.count |
|
445 | 445 | |
|
446 | 446 | assert_difference 'Repository.count', -1 do |
|
447 | 447 | delete :destroy, :id => @repository.id |
|
448 | 448 | end |
|
449 | 449 | assert_response 302 |
|
450 | 450 | @project.reload |
|
451 | 451 | assert_nil @project.repository |
|
452 | 452 | end |
|
453 | 453 | |
|
454 | 454 | def test_destroy_invalid_repository |
|
455 | 455 | @request.session[:user_id] = 1 # admin |
|
456 | 456 | @project.repository.destroy |
|
457 | 457 | @repository = Repository::Git.create!( |
|
458 | 458 | :project => @project, |
|
459 | 459 | :url => "/invalid", |
|
460 | 460 | :path_encoding => 'ISO-8859-1' |
|
461 | 461 | ) |
|
462 | 462 | @repository.fetch_changesets |
|
463 | 463 | @repository.reload |
|
464 | 464 | assert_equal 0, @repository.changesets.count |
|
465 | 465 | |
|
466 | 466 | assert_difference 'Repository.count', -1 do |
|
467 | 467 | delete :destroy, :id => @repository.id |
|
468 | 468 | end |
|
469 | 469 | assert_response 302 |
|
470 | 470 | @project.reload |
|
471 | 471 | assert_nil @project.repository |
|
472 | 472 | end |
|
473 | 473 | |
|
474 | 474 | private |
|
475 | 475 | |
|
476 | 476 | def puts_ruby19_non_utf8_pass |
|
477 | 477 | puts "TODO: This test fails in Ruby 1.9 " + |
|
478 | 478 | "and Encoding.default_external is not UTF-8. " + |
|
479 | 479 | "Current value is '#{Encoding.default_external.to_s}'" |
|
480 | 480 | end |
|
481 | 481 | else |
|
482 | 482 | puts "Git test repository NOT FOUND. Skipping functional tests !!!" |
|
483 | 483 | def test_fake; assert true end |
|
484 | 484 | end |
|
485 | 485 | |
|
486 | 486 | private |
|
487 | 487 | def with_cache(&block) |
|
488 | 488 | before = ActionController::Base.perform_caching |
|
489 | 489 | ActionController::Base.perform_caching = true |
|
490 | 490 | block.call |
|
491 | 491 | ActionController::Base.perform_caching = before |
|
492 | 492 | end |
|
493 | 493 | end |
@@ -1,494 +1,498 | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | 2 | |
|
3 | 3 | # This file includes UTF-8 "Felix Schäfer". |
|
4 | 4 | # We need to consider Ruby 1.9 compatibility. |
|
5 | 5 | |
|
6 | 6 | require File.expand_path('../../../../../../test_helper', __FILE__) |
|
7 | 7 | begin |
|
8 | 8 | require 'mocha' |
|
9 | 9 | |
|
10 | 10 | class GitAdapterTest < ActiveSupport::TestCase |
|
11 | 11 | REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s |
|
12 | 12 | |
|
13 | 13 | FELIX_UTF8 = "Felix Schäfer" |
|
14 | 14 | FELIX_HEX = "Felix Sch\xC3\xA4fer" |
|
15 | 15 | CHAR_1_HEX = "\xc3\x9c" |
|
16 | 16 | |
|
17 | 17 | ## Ruby uses ANSI api to fork a process on Windows. |
|
18 | 18 | ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem |
|
19 | 19 | ## and these are incompatible with ASCII. |
|
20 | 20 | # WINDOWS_PASS = Redmine::Platform.mswin? |
|
21 | 21 | WINDOWS_PASS = false |
|
22 | 22 | |
|
23 | 23 | ## Git, Mercurial and CVS path encodings are binary. |
|
24 | 24 | ## Subversion supports URL encoding for path. |
|
25 | 25 | ## Redmine Mercurial adapter and extension use URL encoding. |
|
26 | 26 | ## Git accepts only binary path in command line parameter. |
|
27 | 27 | ## So, there is no way to use binary command line parameter in JRuby. |
|
28 | 28 | JRUBY_SKIP = (RUBY_PLATFORM == 'java') |
|
29 | 29 | JRUBY_SKIP_STR = "TODO: This test fails in JRuby" |
|
30 | 30 | |
|
31 | 31 | if File.directory?(REPOSITORY_PATH) |
|
32 | 32 | def setup |
|
33 | 33 | adapter_class = Redmine::Scm::Adapters::GitAdapter |
|
34 | 34 | assert adapter_class |
|
35 | 35 | assert adapter_class.client_command |
|
36 | 36 | assert_equal true, adapter_class.client_available |
|
37 | 37 | assert_equal true, adapter_class.client_version_above?([1]) |
|
38 | 38 | assert_equal true, adapter_class.client_version_above?([1, 0]) |
|
39 | 39 | |
|
40 | 40 | @adapter = Redmine::Scm::Adapters::GitAdapter.new( |
|
41 | 41 | REPOSITORY_PATH, |
|
42 | 42 | nil, |
|
43 | 43 | nil, |
|
44 | 44 | nil, |
|
45 | 45 | 'ISO-8859-1' |
|
46 | 46 | ) |
|
47 | 47 | assert @adapter |
|
48 | 48 | @char_1 = CHAR_1_HEX.dup |
|
49 | 49 | if @char_1.respond_to?(:force_encoding) |
|
50 | 50 | @char_1.force_encoding('UTF-8') |
|
51 | 51 | end |
|
52 | 52 | end |
|
53 | 53 | |
|
54 | 54 | def test_scm_version |
|
55 | 55 | to_test = { "git version 1.7.3.4\n" => [1,7,3,4], |
|
56 | 56 | "1.6.1\n1.7\n1.8" => [1,6,1], |
|
57 | 57 | "1.6.2\r\n1.8.1\r\n1.9.1" => [1,6,2]} |
|
58 | 58 | to_test.each do |s, v| |
|
59 | 59 | test_scm_version_for(s, v) |
|
60 | 60 | end |
|
61 | 61 | end |
|
62 | 62 | |
|
63 | 63 | def test_branches |
|
64 | 64 | brs = [] |
|
65 | 65 | @adapter.branches.each do |b| |
|
66 | 66 | brs << b |
|
67 | 67 | end |
|
68 |
assert_equal |
|
|
68 | assert_equal 5, brs.length | |
|
69 | br_issue_8857 = brs[-5] | |
|
70 | assert_equal 'issue-8857', br_issue_8857.to_s | |
|
71 | assert_equal '2a682156a3b6e77a8bf9cd4590e8db757f3c6c78', br_issue_8857.revision | |
|
72 | assert_equal br_issue_8857.scmid, br_issue_8857.revision | |
|
69 | 73 | br_latin_1_path = brs[-4] |
|
70 | 74 | assert_equal 'latin-1-path-encoding', br_latin_1_path.to_s |
|
71 | 75 | assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', br_latin_1_path.revision |
|
72 | 76 | assert_equal br_latin_1_path.scmid, br_latin_1_path.revision |
|
73 | 77 | br_master = brs[-3] |
|
74 | 78 | assert_equal 'master', br_master.to_s |
|
75 | 79 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', br_master.revision |
|
76 | 80 | assert_equal br_master.scmid, br_master.revision |
|
77 | 81 | br_latin_1 = brs[-2] |
|
78 | 82 | assert_equal 'test-latin-1', br_latin_1.to_s |
|
79 | 83 | assert_equal '67e7792ce20ccae2e4bb73eed09bb397819c8834', br_latin_1.revision |
|
80 | 84 | assert_equal br_latin_1.scmid, br_latin_1.revision |
|
81 | 85 | br_test = brs[-1] |
|
82 | 86 | assert_equal 'test_branch', br_test.to_s |
|
83 | 87 | assert_equal 'fba357b886984ee71185ad2065e65fc0417d9b92', br_test.revision |
|
84 | 88 | assert_equal br_test.scmid, br_test.revision |
|
85 | 89 | end |
|
86 | 90 | |
|
87 | 91 | def test_tags |
|
88 | 92 | assert_equal [ |
|
89 | 93 | "tag00.lightweight", |
|
90 | 94 | "tag01.annotated", |
|
91 | 95 | ], @adapter.tags |
|
92 | 96 | end |
|
93 | 97 | |
|
94 | 98 | def test_revisions_master_all |
|
95 | 99 | revs1 = [] |
|
96 | 100 | @adapter.revisions('', nil, "master",{}) do |rev| |
|
97 | 101 | revs1 << rev |
|
98 | 102 | end |
|
99 | 103 | assert_equal 15, revs1.length |
|
100 | 104 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[ 0].identifier |
|
101 | 105 | assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs1[-1].identifier |
|
102 | 106 | |
|
103 | 107 | revs2 = [] |
|
104 | 108 | @adapter.revisions('', nil, "master", |
|
105 | 109 | {:reverse => true}) do |rev| |
|
106 | 110 | revs2 << rev |
|
107 | 111 | end |
|
108 | 112 | assert_equal 15, revs2.length |
|
109 | 113 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs2[-1].identifier |
|
110 | 114 | assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs2[ 0].identifier |
|
111 | 115 | end |
|
112 | 116 | |
|
113 | 117 | def test_revisions_master_merged_rev |
|
114 | 118 | revs1 = [] |
|
115 | 119 | @adapter.revisions('', |
|
116 | 120 | "713f4944648826f558cf548222f813dabe7cbb04", |
|
117 | 121 | "master", |
|
118 | 122 | {:reverse => true}) do |rev| |
|
119 | 123 | revs1 << rev |
|
120 | 124 | end |
|
121 | 125 | assert_equal 8, revs1.length |
|
122 | 126 | assert_equal 'fba357b886984ee71185ad2065e65fc0417d9b92', revs1[ 0].identifier |
|
123 | 127 | assert_equal '7e61ac704deecde634b51e59daa8110435dcb3da', revs1[ 1].identifier |
|
124 | 128 | # 4a07fe31b is not a child of 713f49446 |
|
125 | 129 | assert_equal '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8', revs1[ 2].identifier |
|
126 | 130 | # Merged revision |
|
127 | 131 | assert_equal '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf', revs1[ 3].identifier |
|
128 | 132 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[-1].identifier |
|
129 | 133 | |
|
130 | 134 | revs2 = [] |
|
131 | 135 | @adapter.revisions('', |
|
132 | 136 | "fba357b886984ee71185ad2065e65fc0417d9b92", |
|
133 | 137 | "master", |
|
134 | 138 | {:reverse => true}) do |rev| |
|
135 | 139 | revs2 << rev |
|
136 | 140 | end |
|
137 | 141 | assert_equal 7, revs2.length |
|
138 | 142 | assert_equal '7e61ac704deecde634b51e59daa8110435dcb3da', revs2[ 0].identifier |
|
139 | 143 | # 4a07fe31b is not a child of fba357b8869 |
|
140 | 144 | assert_equal '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8', revs2[ 1].identifier |
|
141 | 145 | # Merged revision |
|
142 | 146 | assert_equal '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf', revs2[ 2].identifier |
|
143 | 147 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs2[-1].identifier |
|
144 | 148 | end |
|
145 | 149 | |
|
146 | 150 | def test_revisions_branch_latin_1_path_encoding_all |
|
147 | 151 | revs1 = [] |
|
148 | 152 | @adapter.revisions('', nil, "latin-1-path-encoding",{}) do |rev| |
|
149 | 153 | revs1 << rev |
|
150 | 154 | end |
|
151 | 155 | assert_equal 8, revs1.length |
|
152 | 156 | assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs1[ 0].identifier |
|
153 | 157 | assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs1[-1].identifier |
|
154 | 158 | |
|
155 | 159 | revs2 = [] |
|
156 | 160 | @adapter.revisions('', nil, "latin-1-path-encoding", |
|
157 | 161 | {:reverse => true}) do |rev| |
|
158 | 162 | revs2 << rev |
|
159 | 163 | end |
|
160 | 164 | assert_equal 8, revs2.length |
|
161 | 165 | assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs2[-1].identifier |
|
162 | 166 | assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs2[ 0].identifier |
|
163 | 167 | end |
|
164 | 168 | |
|
165 | 169 | def test_revisions_branch_latin_1_path_encoding_with_rev |
|
166 | 170 | revs1 = [] |
|
167 | 171 | @adapter.revisions('', |
|
168 | 172 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
169 | 173 | "latin-1-path-encoding", |
|
170 | 174 | {:reverse => true}) do |rev| |
|
171 | 175 | revs1 << rev |
|
172 | 176 | end |
|
173 | 177 | assert_equal 7, revs1.length |
|
174 | 178 | assert_equal '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', revs1[ 0].identifier |
|
175 | 179 | assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs1[-1].identifier |
|
176 | 180 | |
|
177 | 181 | revs2 = [] |
|
178 | 182 | @adapter.revisions('', |
|
179 | 183 | '57ca437c0acbbcb749821fdf3726a1367056d364', |
|
180 | 184 | "latin-1-path-encoding", |
|
181 | 185 | {:reverse => true}) do |rev| |
|
182 | 186 | revs2 << rev |
|
183 | 187 | end |
|
184 | 188 | assert_equal 3, revs2.length |
|
185 | 189 | assert_equal '4fc55c43bf3d3dc2efb66145365ddc17639ce81e', revs2[ 0].identifier |
|
186 | 190 | assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs2[-1].identifier |
|
187 | 191 | end |
|
188 | 192 | |
|
189 | 193 | def test_revisions_invalid_rev |
|
190 | 194 | revs1 = [] |
|
191 | 195 | @adapter.revisions('', |
|
192 | 196 | '1234abcd', |
|
193 | 197 | "master", |
|
194 | 198 | {:reverse => true}) do |rev| |
|
195 | 199 | revs1 << rev |
|
196 | 200 | end |
|
197 | 201 | assert_equal [], revs1 |
|
198 | 202 | end |
|
199 | 203 | |
|
200 | 204 | def test_revisions_includes_master_two_revs |
|
201 | 205 | revs1 = [] |
|
202 | 206 | @adapter.revisions('', nil, nil, |
|
203 | 207 | {:reverse => true, |
|
204 | 208 | :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'], |
|
205 | 209 | :excludes => ['4f26664364207fa8b1af9f8722647ab2d4ac5d43']}) do |rev| |
|
206 | 210 | revs1 << rev |
|
207 | 211 | end |
|
208 | 212 | assert_equal 2, revs1.length |
|
209 | 213 | assert_equal 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b', revs1[ 0].identifier |
|
210 | 214 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[-1].identifier |
|
211 | 215 | end |
|
212 | 216 | |
|
213 | 217 | def test_revisions_includes_master_two_revs_from_origin |
|
214 | 218 | revs1 = [] |
|
215 | 219 | @adapter.revisions('', nil, nil, |
|
216 | 220 | {:reverse => true, |
|
217 | 221 | :includes => ['899a15dba03a3b350b89c3f537e4bbe02a03cdc9']}) do |rev| |
|
218 | 222 | revs1 << rev |
|
219 | 223 | end |
|
220 | 224 | assert_equal 2, revs1.length |
|
221 | 225 | assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs1[ 0].identifier |
|
222 | 226 | assert_equal '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', revs1[ 1].identifier |
|
223 | 227 | end |
|
224 | 228 | |
|
225 | 229 | def test_revisions_includes_merged_revs |
|
226 | 230 | revs1 = [] |
|
227 | 231 | @adapter.revisions('', nil, nil, |
|
228 | 232 | {:reverse => true, |
|
229 | 233 | :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'], |
|
230 | 234 | :excludes => ['fba357b886984ee71185ad2065e65fc0417d9b92']}) do |rev| |
|
231 | 235 | revs1 << rev |
|
232 | 236 | end |
|
233 | 237 | assert_equal 7, revs1.length |
|
234 | 238 | assert_equal '7e61ac704deecde634b51e59daa8110435dcb3da', revs1[ 0].identifier |
|
235 | 239 | assert_equal '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8', revs1[ 1].identifier |
|
236 | 240 | assert_equal '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf', revs1[ 2].identifier |
|
237 | 241 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[-1].identifier |
|
238 | 242 | end |
|
239 | 243 | |
|
240 | 244 | def test_revisions_includes_two_heads |
|
241 | 245 | revs1 = [] |
|
242 | 246 | @adapter.revisions('', nil, nil, |
|
243 | 247 | {:reverse => true, |
|
244 | 248 | :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', |
|
245 | 249 | '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127'], |
|
246 | 250 | :excludes => ['4f26664364207fa8b1af9f8722647ab2d4ac5d43', |
|
247 | 251 | '4fc55c43bf3d3dc2efb66145365ddc17639ce81e']}) do |rev| |
|
248 | 252 | revs1 << rev |
|
249 | 253 | end |
|
250 | 254 | assert_equal 4, revs1.length |
|
251 | 255 | assert_equal 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b', revs1[ 0].identifier |
|
252 | 256 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[ 1].identifier |
|
253 | 257 | assert_equal '64f1f3e89ad1cb57976ff0ad99a107012ba3481d', revs1[-2].identifier |
|
254 | 258 | assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs1[-1].identifier |
|
255 | 259 | end |
|
256 | 260 | |
|
257 | 261 | def test_revisions_invalid_rev_excludes |
|
258 | 262 | revs1 = [] |
|
259 | 263 | @adapter.revisions('', nil, nil, |
|
260 | 264 | {:reverse => true, |
|
261 | 265 | :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'], |
|
262 | 266 | :excludes => ['0123abcd4567']}) do |rev| |
|
263 | 267 | revs1 << rev |
|
264 | 268 | end |
|
265 | 269 | assert_equal [], revs1 |
|
266 | 270 | end |
|
267 | 271 | |
|
268 | 272 | def test_getting_revisions_with_spaces_in_filename |
|
269 | 273 | assert_equal 1, @adapter.revisions("filemane with spaces.txt", |
|
270 | 274 | nil, "master").length |
|
271 | 275 | end |
|
272 | 276 | |
|
273 | 277 | def test_parents |
|
274 | 278 | revs1 = [] |
|
275 | 279 | @adapter.revisions('', |
|
276 | 280 | nil, |
|
277 | 281 | "master", |
|
278 | 282 | {:reverse => true}) do |rev| |
|
279 | 283 | revs1 << rev |
|
280 | 284 | end |
|
281 | 285 | assert_equal 15, revs1.length |
|
282 | 286 | assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", |
|
283 | 287 | revs1[0].identifier |
|
284 | 288 | assert_equal nil, revs1[0].parents |
|
285 | 289 | assert_equal "899a15dba03a3b350b89c3f537e4bbe02a03cdc9", |
|
286 | 290 | revs1[1].identifier |
|
287 | 291 | assert_equal 1, revs1[1].parents.length |
|
288 | 292 | assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", |
|
289 | 293 | revs1[1].parents[0] |
|
290 | 294 | assert_equal "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf", |
|
291 | 295 | revs1[10].identifier |
|
292 | 296 | assert_equal 2, revs1[10].parents.length |
|
293 | 297 | assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", |
|
294 | 298 | revs1[10].parents[0] |
|
295 | 299 | assert_equal "7e61ac704deecde634b51e59daa8110435dcb3da", |
|
296 | 300 | revs1[10].parents[1] |
|
297 | 301 | end |
|
298 | 302 | |
|
299 | 303 | def test_getting_revisions_with_leading_and_trailing_spaces_in_filename |
|
300 | 304 | assert_equal " filename with a leading space.txt ", |
|
301 | 305 | @adapter.revisions(" filename with a leading space.txt ", |
|
302 | 306 | nil, "master")[0].paths[0][:path] |
|
303 | 307 | end |
|
304 | 308 | |
|
305 | 309 | def test_getting_entries_with_leading_and_trailing_spaces_in_filename |
|
306 | 310 | assert_equal " filename with a leading space.txt ", |
|
307 | 311 | @adapter.entries('', |
|
308 | 312 | '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c')[3].name |
|
309 | 313 | end |
|
310 | 314 | |
|
311 | 315 | def test_annotate |
|
312 | 316 | annotate = @adapter.annotate('sources/watchers_controller.rb') |
|
313 | 317 | assert_kind_of Redmine::Scm::Adapters::Annotate, annotate |
|
314 | 318 | assert_equal 41, annotate.lines.size |
|
315 | 319 | assert_equal "# This program is free software; you can redistribute it and/or", |
|
316 | 320 | annotate.lines[4].strip |
|
317 | 321 | assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", |
|
318 | 322 | annotate.revisions[4].identifier |
|
319 | 323 | assert_equal "jsmith", annotate.revisions[4].author |
|
320 | 324 | end |
|
321 | 325 | |
|
322 | 326 | def test_annotate_moved_file |
|
323 | 327 | annotate = @adapter.annotate('renamed_test.txt') |
|
324 | 328 | assert_kind_of Redmine::Scm::Adapters::Annotate, annotate |
|
325 | 329 | assert_equal 2, annotate.lines.size |
|
326 | 330 | end |
|
327 | 331 | |
|
328 | 332 | def test_last_rev |
|
329 | 333 | last_rev = @adapter.lastrev("README", |
|
330 | 334 | "4f26664364207fa8b1af9f8722647ab2d4ac5d43") |
|
331 | 335 | assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.scmid |
|
332 | 336 | assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.identifier |
|
333 | 337 | assert_equal "Adam Soltys <asoltys@gmail.com>", last_rev.author |
|
334 | 338 | assert_equal "2009-06-24 05:27:38".to_time, last_rev.time |
|
335 | 339 | end |
|
336 | 340 | |
|
337 | 341 | def test_last_rev_with_spaces_in_filename |
|
338 | 342 | last_rev = @adapter.lastrev("filemane with spaces.txt", |
|
339 | 343 | "ed5bb786bbda2dee66a2d50faf51429dbc043a7b") |
|
340 | 344 | str_felix_utf8 = FELIX_UTF8.dup |
|
341 | 345 | str_felix_hex = FELIX_HEX.dup |
|
342 | 346 | last_rev_author = last_rev.author |
|
343 | 347 | if last_rev_author.respond_to?(:force_encoding) |
|
344 | 348 | last_rev_author.force_encoding('UTF-8') |
|
345 | 349 | end |
|
346 | 350 | assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.scmid |
|
347 | 351 | assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.identifier |
|
348 | 352 | assert_equal "#{str_felix_utf8} <felix@fachschaften.org>", |
|
349 | 353 | last_rev.author |
|
350 | 354 | assert_equal "#{str_felix_hex} <felix@fachschaften.org>", |
|
351 | 355 | last_rev.author |
|
352 | 356 | assert_equal "2010-09-18 19:59:46".to_time, last_rev.time |
|
353 | 357 | end |
|
354 | 358 | |
|
355 | 359 | def test_latin_1_path |
|
356 | 360 | if WINDOWS_PASS |
|
357 | 361 | # |
|
358 | 362 | elsif JRUBY_SKIP |
|
359 | 363 | puts JRUBY_SKIP_STR |
|
360 | 364 | else |
|
361 | 365 | p2 = "latin-1-dir/test-#{@char_1}-2.txt" |
|
362 | 366 | ['4fc55c43bf3d3dc2efb66145365ddc17639ce81e', '4fc55c43bf3'].each do |r1| |
|
363 | 367 | assert @adapter.diff(p2, r1) |
|
364 | 368 | assert @adapter.cat(p2, r1) |
|
365 | 369 | assert_equal 1, @adapter.annotate(p2, r1).lines.length |
|
366 | 370 | ['64f1f3e89ad1cb57976ff0ad99a107012ba3481d', '64f1f3e89ad1cb5797'].each do |r2| |
|
367 | 371 | assert @adapter.diff(p2, r1, r2) |
|
368 | 372 | end |
|
369 | 373 | end |
|
370 | 374 | end |
|
371 | 375 | end |
|
372 | 376 | |
|
373 | 377 | def test_entries_tag |
|
374 | 378 | entries1 = @adapter.entries(nil, 'tag01.annotated', |
|
375 | 379 | options = {:report_last_commit => true}) |
|
376 | 380 | assert entries1 |
|
377 | 381 | assert_equal 3, entries1.size |
|
378 | 382 | assert_equal 'sources', entries1[1].name |
|
379 | 383 | assert_equal 'sources', entries1[1].path |
|
380 | 384 | assert_equal 'dir', entries1[1].kind |
|
381 | 385 | readme = entries1[2] |
|
382 | 386 | assert_equal 'README', readme.name |
|
383 | 387 | assert_equal 'README', readme.path |
|
384 | 388 | assert_equal 'file', readme.kind |
|
385 | 389 | assert_equal 27, readme.size |
|
386 | 390 | assert_equal '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', readme.lastrev.identifier |
|
387 | 391 | assert_equal Time.gm(2007, 12, 14, 9, 24, 1), readme.lastrev.time |
|
388 | 392 | end |
|
389 | 393 | |
|
390 | 394 | def test_entries_branch |
|
391 | 395 | entries1 = @adapter.entries(nil, 'test_branch', |
|
392 | 396 | options = {:report_last_commit => true}) |
|
393 | 397 | assert entries1 |
|
394 | 398 | assert_equal 4, entries1.size |
|
395 | 399 | assert_equal 'sources', entries1[1].name |
|
396 | 400 | assert_equal 'sources', entries1[1].path |
|
397 | 401 | assert_equal 'dir', entries1[1].kind |
|
398 | 402 | readme = entries1[2] |
|
399 | 403 | assert_equal 'README', readme.name |
|
400 | 404 | assert_equal 'README', readme.path |
|
401 | 405 | assert_equal 'file', readme.kind |
|
402 | 406 | assert_equal 159, readme.size |
|
403 | 407 | assert_equal '713f4944648826f558cf548222f813dabe7cbb04', readme.lastrev.identifier |
|
404 | 408 | assert_equal Time.gm(2009, 6, 19, 4, 37, 23), readme.lastrev.time |
|
405 | 409 | end |
|
406 | 410 | |
|
407 | 411 | def test_entries_latin_1_files |
|
408 | 412 | entries1 = @adapter.entries('latin-1-dir', '64f1f3e8') |
|
409 | 413 | assert entries1 |
|
410 | 414 | assert_equal 3, entries1.size |
|
411 | 415 | f1 = entries1[1] |
|
412 | 416 | assert_equal "test-#{@char_1}-2.txt", f1.name |
|
413 | 417 | assert_equal "latin-1-dir/test-#{@char_1}-2.txt", f1.path |
|
414 | 418 | assert_equal 'file', f1.kind |
|
415 | 419 | end |
|
416 | 420 | |
|
417 | 421 | def test_entries_latin_1_dir |
|
418 | 422 | if WINDOWS_PASS |
|
419 | 423 | # |
|
420 | 424 | elsif JRUBY_SKIP |
|
421 | 425 | puts JRUBY_SKIP_STR |
|
422 | 426 | else |
|
423 | 427 | entries1 = @adapter.entries("latin-1-dir/test-#{@char_1}-subdir", |
|
424 | 428 | '1ca7f5ed') |
|
425 | 429 | assert entries1 |
|
426 | 430 | assert_equal 3, entries1.size |
|
427 | 431 | f1 = entries1[1] |
|
428 | 432 | assert_equal "test-#{@char_1}-2.txt", f1.name |
|
429 | 433 | assert_equal "latin-1-dir/test-#{@char_1}-subdir/test-#{@char_1}-2.txt", f1.path |
|
430 | 434 | assert_equal 'file', f1.kind |
|
431 | 435 | end |
|
432 | 436 | end |
|
433 | 437 | |
|
434 | 438 | def test_path_encoding_default_utf8 |
|
435 | 439 | adpt1 = Redmine::Scm::Adapters::GitAdapter.new( |
|
436 | 440 | REPOSITORY_PATH |
|
437 | 441 | ) |
|
438 | 442 | assert_equal "UTF-8", adpt1.path_encoding |
|
439 | 443 | adpt2 = Redmine::Scm::Adapters::GitAdapter.new( |
|
440 | 444 | REPOSITORY_PATH, |
|
441 | 445 | nil, |
|
442 | 446 | nil, |
|
443 | 447 | nil, |
|
444 | 448 | "" |
|
445 | 449 | ) |
|
446 | 450 | assert_equal "UTF-8", adpt2.path_encoding |
|
447 | 451 | end |
|
448 | 452 | |
|
449 | 453 | def test_cat_path_invalid |
|
450 | 454 | assert_nil @adapter.cat('invalid') |
|
451 | 455 | end |
|
452 | 456 | |
|
453 | 457 | def test_cat_revision_invalid |
|
454 | 458 | assert @adapter.cat('README') |
|
455 | 459 | assert_nil @adapter.cat('README', 'abcd1234efgh') |
|
456 | 460 | end |
|
457 | 461 | |
|
458 | 462 | def test_diff_path_invalid |
|
459 | 463 | assert_equal [], @adapter.diff('invalid', '713f4944648826f5') |
|
460 | 464 | end |
|
461 | 465 | |
|
462 | 466 | def test_diff_revision_invalid |
|
463 | 467 | assert_nil @adapter.diff(nil, 'abcd1234efgh') |
|
464 | 468 | assert_nil @adapter.diff(nil, '713f4944648826f5', 'abcd1234efgh') |
|
465 | 469 | assert_nil @adapter.diff(nil, 'abcd1234efgh', '713f4944648826f5') |
|
466 | 470 | end |
|
467 | 471 | |
|
468 | 472 | def test_annotate_path_invalid |
|
469 | 473 | assert_nil @adapter.annotate('invalid') |
|
470 | 474 | end |
|
471 | 475 | |
|
472 | 476 | def test_annotate_revision_invalid |
|
473 | 477 | assert @adapter.annotate('README') |
|
474 | 478 | assert_nil @adapter.annotate('README', 'abcd1234efgh') |
|
475 | 479 | end |
|
476 | 480 | |
|
477 | 481 | private |
|
478 | 482 | |
|
479 | 483 | def test_scm_version_for(scm_command_version, version) |
|
480 | 484 | @adapter.class.expects(:scm_version_from_command_line).returns(scm_command_version) |
|
481 | 485 | assert_equal version, @adapter.class.scm_command_version |
|
482 | 486 | end |
|
483 | 487 | |
|
484 | 488 | else |
|
485 | 489 | puts "Git test repository NOT FOUND. Skipping unit tests !!!" |
|
486 | 490 | def test_fake; assert true end |
|
487 | 491 | end |
|
488 | 492 | end |
|
489 | 493 | |
|
490 | 494 | rescue LoadError |
|
491 | 495 | class GitMochaFake < ActiveSupport::TestCase |
|
492 | 496 | def test_fake; assert(false, "Requires mocha to run those tests") end |
|
493 | 497 | end |
|
494 | 498 | end |
@@ -1,515 +1,513 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2011 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class RepositoryGitTest < ActiveSupport::TestCase |
|
21 | 21 | fixtures :projects, :repositories, :enabled_modules, :users, :roles |
|
22 | 22 | |
|
23 | 23 | REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s |
|
24 | 24 | REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin? |
|
25 | 25 | |
|
26 |
NUM_REV = 2 |
|
|
26 | NUM_REV = 28 | |
|
27 | 27 | |
|
28 | 28 | FELIX_HEX = "Felix Sch\xC3\xA4fer" |
|
29 | 29 | CHAR_1_HEX = "\xc3\x9c" |
|
30 | 30 | |
|
31 | 31 | ## Ruby uses ANSI api to fork a process on Windows. |
|
32 | 32 | ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem |
|
33 | 33 | ## and these are incompatible with ASCII. |
|
34 | 34 | # WINDOWS_PASS = Redmine::Platform.mswin? |
|
35 | 35 | WINDOWS_PASS = false |
|
36 | 36 | |
|
37 | 37 | ## Git, Mercurial and CVS path encodings are binary. |
|
38 | 38 | ## Subversion supports URL encoding for path. |
|
39 | 39 | ## Redmine Mercurial adapter and extension use URL encoding. |
|
40 | 40 | ## Git accepts only binary path in command line parameter. |
|
41 | 41 | ## So, there is no way to use binary command line parameter in JRuby. |
|
42 | 42 | JRUBY_SKIP = (RUBY_PLATFORM == 'java') |
|
43 | 43 | JRUBY_SKIP_STR = "TODO: This test fails in JRuby" |
|
44 | 44 | |
|
45 | 45 | if File.directory?(REPOSITORY_PATH) |
|
46 | 46 | def setup |
|
47 | 47 | klass = Repository::Git |
|
48 | 48 | assert_equal "Git", klass.scm_name |
|
49 | 49 | assert klass.scm_adapter_class |
|
50 | 50 | assert_not_equal "", klass.scm_command |
|
51 | 51 | assert_equal true, klass.scm_available |
|
52 | 52 | |
|
53 | 53 | @project = Project.find(3) |
|
54 | 54 | @repository = Repository::Git.create( |
|
55 | 55 | :project => @project, |
|
56 | 56 | :url => REPOSITORY_PATH, |
|
57 | 57 | :path_encoding => 'ISO-8859-1' |
|
58 | 58 | ) |
|
59 | 59 | assert @repository |
|
60 | 60 | @char_1 = CHAR_1_HEX.dup |
|
61 | 61 | if @char_1.respond_to?(:force_encoding) |
|
62 | 62 | @char_1.force_encoding('UTF-8') |
|
63 | 63 | end |
|
64 | 64 | end |
|
65 | 65 | |
|
66 | 66 | def test_fetch_changesets_from_scratch |
|
67 | 67 | assert_nil @repository.extra_info |
|
68 | 68 | |
|
69 | 69 | assert_equal 0, @repository.changesets.count |
|
70 | 70 | @repository.fetch_changesets |
|
71 | 71 | @project.reload |
|
72 | 72 | |
|
73 | 73 | assert_equal NUM_REV, @repository.changesets.count |
|
74 |
assert_equal 3 |
|
|
74 | assert_equal 39, @repository.changes.count | |
|
75 | 75 | |
|
76 | 76 | commit = @repository.changesets.find(:first, :order => 'committed_on ASC') |
|
77 | 77 | assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments |
|
78 | 78 | assert_equal "jsmith <jsmith@foo.bar>", commit.committer |
|
79 | 79 | assert_equal User.find_by_login('jsmith'), commit.user |
|
80 | 80 | # TODO: add a commit with commit time <> author time to the test repository |
|
81 | 81 | assert_equal "2007-12-14 09:22:52".to_time, commit.committed_on |
|
82 | 82 | assert_equal "2007-12-14".to_date, commit.commit_date |
|
83 | 83 | assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.revision |
|
84 | 84 | assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.scmid |
|
85 | 85 | assert_equal 3, commit.changes.count |
|
86 | 86 | change = commit.changes.sort_by(&:path).first |
|
87 | 87 | assert_equal "README", change.path |
|
88 | 88 | assert_equal "A", change.action |
|
89 | 89 | |
|
90 |
assert_equal |
|
|
90 | assert_equal 5, @repository.extra_info["branches"].size | |
|
91 | 91 | end |
|
92 | 92 | |
|
93 | 93 | def test_fetch_changesets_incremental |
|
94 | 94 | assert_equal 0, @repository.changesets.count |
|
95 | 95 | @repository.fetch_changesets |
|
96 | 96 | @project.reload |
|
97 | 97 | assert_equal NUM_REV, @repository.changesets.count |
|
98 | assert_equal 33, @repository.changes.count | |
|
99 | 98 | extra_info_db = @repository.extra_info["branches"] |
|
100 | assert_equal 4, extra_info_db.size | |
|
101 | 99 | assert_equal "1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127", |
|
102 | 100 | extra_info_db["latin-1-path-encoding"]["last_scmid"] |
|
103 | 101 | assert_equal "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c", |
|
104 | 102 | extra_info_db["master"]["last_scmid"] |
|
105 | 103 | |
|
106 | 104 | del_revs = [ |
|
107 | 105 | "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c", |
|
108 | 106 | "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", |
|
109 | 107 | "4f26664364207fa8b1af9f8722647ab2d4ac5d43", |
|
110 | 108 | "deff712f05a90d96edbd70facc47d944be5897e3", |
|
111 | 109 | "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf", |
|
112 | 110 | "7e61ac704deecde634b51e59daa8110435dcb3da", |
|
113 | 111 | ] |
|
114 | 112 | @repository.changesets.each do |rev| |
|
115 | 113 | rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s } |
|
116 | 114 | end |
|
117 | 115 | @project.reload |
|
118 | 116 | cs1 = @repository.changesets |
|
119 |
assert_equal |
|
|
117 | assert_equal 22, cs1.count | |
|
120 | 118 | h = @repository.extra_info.dup |
|
121 | 119 | h["branches"]["master"]["last_scmid"] = |
|
122 | 120 | "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8" |
|
123 | 121 | @repository.merge_extra_info(h) |
|
124 | 122 | @repository.save |
|
125 | 123 | @project.reload |
|
126 | 124 | extra_info_db_1 = @repository.extra_info["branches"] |
|
127 | 125 | assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", |
|
128 | 126 | extra_info_db_1["master"]["last_scmid"] |
|
129 | 127 | |
|
130 | 128 | @repository.fetch_changesets |
|
131 | 129 | @project.reload |
|
132 | 130 | assert_equal NUM_REV, @repository.changesets.count |
|
133 | 131 | end |
|
134 | 132 | |
|
135 | 133 | def test_fetch_changesets_invalid_rev |
|
136 | 134 | assert_equal 0, @repository.changesets.count |
|
137 | 135 | @repository.fetch_changesets |
|
138 | 136 | @project.reload |
|
139 | 137 | assert_equal NUM_REV, @repository.changesets.count |
|
140 | 138 | extra_info_db = @repository.extra_info["branches"] |
|
141 |
assert_equal |
|
|
139 | assert_equal 5, extra_info_db.size | |
|
142 | 140 | assert_equal "1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127", |
|
143 | 141 | extra_info_db["latin-1-path-encoding"]["last_scmid"] |
|
144 | 142 | assert_equal "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c", |
|
145 | 143 | extra_info_db["master"]["last_scmid"] |
|
146 | 144 | |
|
147 | 145 | del_revs = [ |
|
148 | 146 | "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c", |
|
149 | 147 | "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", |
|
150 | 148 | "4f26664364207fa8b1af9f8722647ab2d4ac5d43", |
|
151 | 149 | "deff712f05a90d96edbd70facc47d944be5897e3", |
|
152 | 150 | "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf", |
|
153 | 151 | "7e61ac704deecde634b51e59daa8110435dcb3da", |
|
154 | 152 | ] |
|
155 | 153 | @repository.changesets.each do |rev| |
|
156 | 154 | rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s } |
|
157 | 155 | end |
|
158 | 156 | @project.reload |
|
159 | 157 | cs1 = @repository.changesets |
|
160 |
assert_equal |
|
|
158 | assert_equal 22, cs1.count | |
|
161 | 159 | h = @repository.extra_info.dup |
|
162 | 160 | h["branches"]["master"]["last_scmid"] = |
|
163 | 161 | "abcd1234efgh" |
|
164 | 162 | @repository.merge_extra_info(h) |
|
165 | 163 | @repository.save |
|
166 | 164 | @project.reload |
|
167 | 165 | extra_info_db_1 = @repository.extra_info["branches"] |
|
168 | 166 | assert_equal "abcd1234efgh", |
|
169 | 167 | extra_info_db_1["master"]["last_scmid"] |
|
170 | 168 | |
|
171 | 169 | @repository.fetch_changesets |
|
172 | 170 | @project.reload |
|
173 |
assert_equal |
|
|
171 | assert_equal 22, @repository.changesets.count | |
|
174 | 172 | end |
|
175 | 173 | |
|
176 | 174 | def test_parents |
|
177 | 175 | assert_equal 0, @repository.changesets.count |
|
178 | 176 | @repository.fetch_changesets |
|
179 | 177 | @project.reload |
|
180 | 178 | assert_equal NUM_REV, @repository.changesets.count |
|
181 | 179 | r1 = @repository.find_changeset_by_name("7234cb2750b63") |
|
182 | 180 | assert_equal [], r1.parents |
|
183 | 181 | r2 = @repository.find_changeset_by_name("899a15dba03a3") |
|
184 | 182 | assert_equal 1, r2.parents.length |
|
185 | 183 | assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", |
|
186 | 184 | r2.parents[0].identifier |
|
187 | 185 | r3 = @repository.find_changeset_by_name("32ae898b720c2") |
|
188 | 186 | assert_equal 2, r3.parents.length |
|
189 | 187 | r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort |
|
190 | 188 | assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", r4[0] |
|
191 | 189 | assert_equal "7e61ac704deecde634b51e59daa8110435dcb3da", r4[1] |
|
192 | 190 | end |
|
193 | 191 | |
|
194 | 192 | def test_db_consistent_ordering_init |
|
195 | 193 | assert_nil @repository.extra_info |
|
196 | 194 | assert_equal 0, @repository.changesets.count |
|
197 | 195 | @repository.fetch_changesets |
|
198 | 196 | @project.reload |
|
199 | 197 | assert_equal 1, @repository.extra_info["db_consistent"]["ordering"] |
|
200 | 198 | end |
|
201 | 199 | |
|
202 | 200 | def test_db_consistent_ordering_before_1_2 |
|
203 | 201 | assert_nil @repository.extra_info |
|
204 | 202 | assert_equal 0, @repository.changesets.count |
|
205 | 203 | @repository.fetch_changesets |
|
206 | 204 | @project.reload |
|
207 | 205 | assert_equal NUM_REV, @repository.changesets.count |
|
208 | 206 | assert_not_nil @repository.extra_info |
|
209 | 207 | @repository.write_attribute(:extra_info, nil) |
|
210 | 208 | @repository.save |
|
211 | 209 | assert_nil @repository.extra_info |
|
212 | 210 | assert_equal NUM_REV, @repository.changesets.count |
|
213 | 211 | @repository.fetch_changesets |
|
214 | 212 | @project.reload |
|
215 | 213 | assert_equal 0, @repository.extra_info["db_consistent"]["ordering"] |
|
216 | 214 | |
|
217 | 215 | del_revs = [ |
|
218 | 216 | "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c", |
|
219 | 217 | "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", |
|
220 | 218 | "4f26664364207fa8b1af9f8722647ab2d4ac5d43", |
|
221 | 219 | "deff712f05a90d96edbd70facc47d944be5897e3", |
|
222 | 220 | "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf", |
|
223 | 221 | "7e61ac704deecde634b51e59daa8110435dcb3da", |
|
224 | 222 | ] |
|
225 | 223 | @repository.changesets.each do |rev| |
|
226 | 224 | rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s } |
|
227 | 225 | end |
|
228 | 226 | @project.reload |
|
229 | 227 | cs1 = @repository.changesets |
|
230 |
assert_equal |
|
|
228 | assert_equal NUM_REV - 6, cs1.count | |
|
231 | 229 | assert_equal 0, @repository.extra_info["db_consistent"]["ordering"] |
|
232 | 230 | h = @repository.extra_info.dup |
|
233 | 231 | h["branches"]["master"]["last_scmid"] = |
|
234 | 232 | "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8" |
|
235 | 233 | @repository.merge_extra_info(h) |
|
236 | 234 | @repository.save |
|
237 | 235 | @project.reload |
|
238 | 236 | extra_info_db_1 = @repository.extra_info["branches"] |
|
239 | 237 | assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", |
|
240 | 238 | extra_info_db_1["master"]["last_scmid"] |
|
241 | 239 | |
|
242 | 240 | @repository.fetch_changesets |
|
243 | 241 | assert_equal NUM_REV, @repository.changesets.count |
|
244 | 242 | assert_equal 0, @repository.extra_info["db_consistent"]["ordering"] |
|
245 | 243 | end |
|
246 | 244 | |
|
247 | 245 | def test_heads_from_branches_hash |
|
248 | 246 | assert_nil @repository.extra_info |
|
249 | 247 | assert_equal 0, @repository.changesets.count |
|
250 | 248 | assert_equal [], @repository.heads_from_branches_hash |
|
251 | 249 | h = {} |
|
252 | 250 | h["branches"] = {} |
|
253 | 251 | h["branches"]["test1"] = {} |
|
254 | 252 | h["branches"]["test1"]["last_scmid"] = "1234abcd" |
|
255 | 253 | h["branches"]["test2"] = {} |
|
256 | 254 | h["branches"]["test2"]["last_scmid"] = "abcd1234" |
|
257 | 255 | @repository.merge_extra_info(h) |
|
258 | 256 | @repository.save |
|
259 | 257 | @project.reload |
|
260 | 258 | assert_equal ["1234abcd", "abcd1234"], @repository.heads_from_branches_hash.sort |
|
261 | 259 | end |
|
262 | 260 | |
|
263 | 261 | def test_latest_changesets |
|
264 | 262 | assert_equal 0, @repository.changesets.count |
|
265 | 263 | @repository.fetch_changesets |
|
266 | 264 | @project.reload |
|
267 | 265 | assert_equal NUM_REV, @repository.changesets.count |
|
268 | 266 | # with limit |
|
269 | 267 | changesets = @repository.latest_changesets('', 'master', 2) |
|
270 | 268 | assert_equal 2, changesets.size |
|
271 | 269 | |
|
272 | 270 | # with path |
|
273 | 271 | changesets = @repository.latest_changesets('images', 'master') |
|
274 | 272 | assert_equal [ |
|
275 | 273 | 'deff712f05a90d96edbd70facc47d944be5897e3', |
|
276 | 274 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
277 | 275 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
278 | 276 | ], changesets.collect(&:revision) |
|
279 | 277 | |
|
280 | 278 | changesets = @repository.latest_changesets('README', nil) |
|
281 | 279 | assert_equal [ |
|
282 | 280 | '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf', |
|
283 | 281 | '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8', |
|
284 | 282 | '713f4944648826f558cf548222f813dabe7cbb04', |
|
285 | 283 | '61b685fbe55ab05b5ac68402d5720c1a6ac973d1', |
|
286 | 284 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
287 | 285 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
288 | 286 | ], changesets.collect(&:revision) |
|
289 | 287 | |
|
290 | 288 | # with path, revision and limit |
|
291 | 289 | changesets = @repository.latest_changesets('images', '899a15dba') |
|
292 | 290 | assert_equal [ |
|
293 | 291 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
294 | 292 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
295 | 293 | ], changesets.collect(&:revision) |
|
296 | 294 | |
|
297 | 295 | changesets = @repository.latest_changesets('images', '899a15dba', 1) |
|
298 | 296 | assert_equal [ |
|
299 | 297 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
300 | 298 | ], changesets.collect(&:revision) |
|
301 | 299 | |
|
302 | 300 | changesets = @repository.latest_changesets('README', '899a15dba') |
|
303 | 301 | assert_equal [ |
|
304 | 302 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
305 | 303 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
306 | 304 | ], changesets.collect(&:revision) |
|
307 | 305 | |
|
308 | 306 | changesets = @repository.latest_changesets('README', '899a15dba', 1) |
|
309 | 307 | assert_equal [ |
|
310 | 308 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
311 | 309 | ], changesets.collect(&:revision) |
|
312 | 310 | |
|
313 | 311 | # with path, tag and limit |
|
314 | 312 | changesets = @repository.latest_changesets('images', 'tag01.annotated') |
|
315 | 313 | assert_equal [ |
|
316 | 314 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
317 | 315 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
318 | 316 | ], changesets.collect(&:revision) |
|
319 | 317 | |
|
320 | 318 | changesets = @repository.latest_changesets('images', 'tag01.annotated', 1) |
|
321 | 319 | assert_equal [ |
|
322 | 320 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
323 | 321 | ], changesets.collect(&:revision) |
|
324 | 322 | |
|
325 | 323 | changesets = @repository.latest_changesets('README', 'tag01.annotated') |
|
326 | 324 | assert_equal [ |
|
327 | 325 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
328 | 326 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
329 | 327 | ], changesets.collect(&:revision) |
|
330 | 328 | |
|
331 | 329 | changesets = @repository.latest_changesets('README', 'tag01.annotated', 1) |
|
332 | 330 | assert_equal [ |
|
333 | 331 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
334 | 332 | ], changesets.collect(&:revision) |
|
335 | 333 | |
|
336 | 334 | # with path, branch and limit |
|
337 | 335 | changesets = @repository.latest_changesets('images', 'test_branch') |
|
338 | 336 | assert_equal [ |
|
339 | 337 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
340 | 338 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
341 | 339 | ], changesets.collect(&:revision) |
|
342 | 340 | |
|
343 | 341 | changesets = @repository.latest_changesets('images', 'test_branch', 1) |
|
344 | 342 | assert_equal [ |
|
345 | 343 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
346 | 344 | ], changesets.collect(&:revision) |
|
347 | 345 | |
|
348 | 346 | changesets = @repository.latest_changesets('README', 'test_branch') |
|
349 | 347 | assert_equal [ |
|
350 | 348 | '713f4944648826f558cf548222f813dabe7cbb04', |
|
351 | 349 | '61b685fbe55ab05b5ac68402d5720c1a6ac973d1', |
|
352 | 350 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
353 | 351 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
354 | 352 | ], changesets.collect(&:revision) |
|
355 | 353 | |
|
356 | 354 | changesets = @repository.latest_changesets('README', 'test_branch', 2) |
|
357 | 355 | assert_equal [ |
|
358 | 356 | '713f4944648826f558cf548222f813dabe7cbb04', |
|
359 | 357 | '61b685fbe55ab05b5ac68402d5720c1a6ac973d1', |
|
360 | 358 | ], changesets.collect(&:revision) |
|
361 | 359 | |
|
362 | 360 | if JRUBY_SKIP |
|
363 | 361 | puts JRUBY_SKIP_STR |
|
364 | 362 | else |
|
365 | 363 | # latin-1 encoding path |
|
366 | 364 | changesets = @repository.latest_changesets( |
|
367 | 365 | "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89') |
|
368 | 366 | assert_equal [ |
|
369 | 367 | '64f1f3e89ad1cb57976ff0ad99a107012ba3481d', |
|
370 | 368 | '4fc55c43bf3d3dc2efb66145365ddc17639ce81e', |
|
371 | 369 | ], changesets.collect(&:revision) |
|
372 | 370 | |
|
373 | 371 | changesets = @repository.latest_changesets( |
|
374 | 372 | "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89', 1) |
|
375 | 373 | assert_equal [ |
|
376 | 374 | '64f1f3e89ad1cb57976ff0ad99a107012ba3481d', |
|
377 | 375 | ], changesets.collect(&:revision) |
|
378 | 376 | end |
|
379 | 377 | end |
|
380 | 378 | |
|
381 | 379 | def test_latest_changesets_latin_1_dir |
|
382 | 380 | if WINDOWS_PASS |
|
383 | 381 | # |
|
384 | 382 | elsif JRUBY_SKIP |
|
385 | 383 | puts JRUBY_SKIP_STR |
|
386 | 384 | else |
|
387 | 385 | assert_equal 0, @repository.changesets.count |
|
388 | 386 | @repository.fetch_changesets |
|
389 | 387 | @project.reload |
|
390 | 388 | assert_equal NUM_REV, @repository.changesets.count |
|
391 | 389 | changesets = @repository.latest_changesets( |
|
392 | 390 | "latin-1-dir/test-#{@char_1}-subdir", '1ca7f5ed') |
|
393 | 391 | assert_equal [ |
|
394 | 392 | '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', |
|
395 | 393 | ], changesets.collect(&:revision) |
|
396 | 394 | end |
|
397 | 395 | end |
|
398 | 396 | |
|
399 | 397 | def test_find_changeset_by_name |
|
400 | 398 | assert_equal 0, @repository.changesets.count |
|
401 | 399 | @repository.fetch_changesets |
|
402 | 400 | @project.reload |
|
403 | 401 | assert_equal NUM_REV, @repository.changesets.count |
|
404 | 402 | ['7234cb2750b63f47bff735edc50a1c0a433c2518', '7234cb2750b'].each do |r| |
|
405 | 403 | assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
406 | 404 | @repository.find_changeset_by_name(r).revision |
|
407 | 405 | end |
|
408 | 406 | end |
|
409 | 407 | |
|
410 | 408 | def test_find_changeset_by_empty_name |
|
411 | 409 | assert_equal 0, @repository.changesets.count |
|
412 | 410 | @repository.fetch_changesets |
|
413 | 411 | @project.reload |
|
414 | 412 | assert_equal NUM_REV, @repository.changesets.count |
|
415 | 413 | ['', ' ', nil].each do |r| |
|
416 | 414 | assert_nil @repository.find_changeset_by_name(r) |
|
417 | 415 | end |
|
418 | 416 | end |
|
419 | 417 | |
|
420 | 418 | def test_identifier |
|
421 | 419 | assert_equal 0, @repository.changesets.count |
|
422 | 420 | @repository.fetch_changesets |
|
423 | 421 | @project.reload |
|
424 | 422 | assert_equal NUM_REV, @repository.changesets.count |
|
425 | 423 | c = @repository.changesets.find_by_revision( |
|
426 | 424 | '7234cb2750b63f47bff735edc50a1c0a433c2518') |
|
427 | 425 | assert_equal c.scmid, c.identifier |
|
428 | 426 | end |
|
429 | 427 | |
|
430 | 428 | def test_format_identifier |
|
431 | 429 | assert_equal 0, @repository.changesets.count |
|
432 | 430 | @repository.fetch_changesets |
|
433 | 431 | @project.reload |
|
434 | 432 | assert_equal NUM_REV, @repository.changesets.count |
|
435 | 433 | c = @repository.changesets.find_by_revision( |
|
436 | 434 | '7234cb2750b63f47bff735edc50a1c0a433c2518') |
|
437 | 435 | assert_equal '7234cb27', c.format_identifier |
|
438 | 436 | end |
|
439 | 437 | |
|
440 | 438 | def test_activities |
|
441 | 439 | c = Changeset.new(:repository => @repository, |
|
442 | 440 | :committed_on => Time.now, |
|
443 | 441 | :revision => 'abc7234cb2750b63f47bff735edc50a1c0a433c2', |
|
444 | 442 | :scmid => 'abc7234cb2750b63f47bff735edc50a1c0a433c2', |
|
445 | 443 | :comments => 'test') |
|
446 | 444 | assert c.event_title.include?('abc7234c:') |
|
447 | 445 | assert_equal 'abc7234cb2750b63f47bff735edc50a1c0a433c2', c.event_url[:rev] |
|
448 | 446 | end |
|
449 | 447 | |
|
450 | 448 | def test_log_utf8 |
|
451 | 449 | assert_equal 0, @repository.changesets.count |
|
452 | 450 | @repository.fetch_changesets |
|
453 | 451 | @project.reload |
|
454 | 452 | assert_equal NUM_REV, @repository.changesets.count |
|
455 | 453 | str_felix_hex = FELIX_HEX.dup |
|
456 | 454 | if str_felix_hex.respond_to?(:force_encoding) |
|
457 | 455 | str_felix_hex.force_encoding('UTF-8') |
|
458 | 456 | end |
|
459 | 457 | c = @repository.changesets.find_by_revision( |
|
460 | 458 | 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b') |
|
461 | 459 | assert_equal "#{str_felix_hex} <felix@fachschaften.org>", c.committer |
|
462 | 460 | end |
|
463 | 461 | |
|
464 | 462 | def test_previous |
|
465 | 463 | assert_equal 0, @repository.changesets.count |
|
466 | 464 | @repository.fetch_changesets |
|
467 | 465 | @project.reload |
|
468 | 466 | assert_equal NUM_REV, @repository.changesets.count |
|
469 | 467 | %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1| |
|
470 | 468 | changeset = @repository.find_changeset_by_name(r1) |
|
471 | 469 | %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2| |
|
472 | 470 | assert_equal @repository.find_changeset_by_name(r2), changeset.previous |
|
473 | 471 | end |
|
474 | 472 | end |
|
475 | 473 | end |
|
476 | 474 | |
|
477 | 475 | def test_previous_nil |
|
478 | 476 | assert_equal 0, @repository.changesets.count |
|
479 | 477 | @repository.fetch_changesets |
|
480 | 478 | @project.reload |
|
481 | 479 | assert_equal NUM_REV, @repository.changesets.count |
|
482 | %w|7234cb2750b63f47bff735edc50a1c0a433c2518 7234cb2|.each do |r1| | |
|
480 | %w|95488a44bc25f7d1f97d775a31359539ff333a63 95488a44b|.each do |r1| | |
|
483 | 481 | changeset = @repository.find_changeset_by_name(r1) |
|
484 | 482 | assert_nil changeset.previous |
|
485 | 483 | end |
|
486 | 484 | end |
|
487 | 485 | |
|
488 | 486 | def test_next |
|
489 | 487 | assert_equal 0, @repository.changesets.count |
|
490 | 488 | @repository.fetch_changesets |
|
491 | 489 | @project.reload |
|
492 | 490 | assert_equal NUM_REV, @repository.changesets.count |
|
493 | 491 | %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2| |
|
494 | 492 | changeset = @repository.find_changeset_by_name(r2) |
|
495 | 493 | %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1| |
|
496 | 494 | assert_equal @repository.find_changeset_by_name(r1), changeset.next |
|
497 | 495 | end |
|
498 | 496 | end |
|
499 | 497 | end |
|
500 | 498 | |
|
501 | 499 | def test_next_nil |
|
502 | 500 | assert_equal 0, @repository.changesets.count |
|
503 | 501 | @repository.fetch_changesets |
|
504 | 502 | @project.reload |
|
505 | 503 | assert_equal NUM_REV, @repository.changesets.count |
|
506 | 504 | %w|67e7792ce20ccae2e4bb73eed09bb397819c8834 67e7792ce20cca|.each do |r1| |
|
507 | 505 | changeset = @repository.find_changeset_by_name(r1) |
|
508 | 506 | assert_nil changeset.next |
|
509 | 507 | end |
|
510 | 508 | end |
|
511 | 509 | else |
|
512 | 510 | puts "Git test repository NOT FOUND. Skipping unit tests !!!" |
|
513 | 511 | def test_fake; assert true end |
|
514 | 512 | end |
|
515 | 513 | end |
General Comments 0
You need to be logged in to leave comments.
Login now