@@ -1,601 +1,601 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2012 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 | include Redmine::I18n |
|
24 | 24 | |
|
25 | 25 | REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s |
|
26 | 26 | REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin? |
|
27 | 27 | |
|
28 | 28 | NUM_REV = 28 |
|
29 | 29 | NUM_HEAD = 6 |
|
30 | 30 | |
|
31 | 31 | FELIX_HEX = "Felix Sch\xC3\xA4fer" |
|
32 | 32 | CHAR_1_HEX = "\xc3\x9c" |
|
33 | 33 | |
|
34 | 34 | ## Git, Mercurial and CVS path encodings are binary. |
|
35 | 35 | ## Subversion supports URL encoding for path. |
|
36 | 36 | ## Redmine Mercurial adapter and extension use URL encoding. |
|
37 | 37 | ## Git accepts only binary path in command line parameter. |
|
38 | 38 | ## So, there is no way to use binary command line parameter in JRuby. |
|
39 | 39 | JRUBY_SKIP = (RUBY_PLATFORM == 'java') |
|
40 | 40 | JRUBY_SKIP_STR = "TODO: This test fails in JRuby" |
|
41 | 41 | |
|
42 | 42 | def setup |
|
43 | 43 | @project = Project.find(3) |
|
44 | 44 | @repository = Repository::Git.create( |
|
45 | 45 | :project => @project, |
|
46 | 46 | :url => REPOSITORY_PATH, |
|
47 | 47 | :path_encoding => 'ISO-8859-1' |
|
48 | 48 | ) |
|
49 | 49 | assert @repository |
|
50 | 50 | @char_1 = CHAR_1_HEX.dup |
|
51 | 51 | if @char_1.respond_to?(:force_encoding) |
|
52 | 52 | @char_1.force_encoding('UTF-8') |
|
53 | 53 | end |
|
54 | 54 | end |
|
55 | 55 | |
|
56 | 56 | def test_blank_path_to_repository_error_message |
|
57 | 57 | set_language_if_valid 'en' |
|
58 | 58 | repo = Repository::Git.new( |
|
59 | 59 | :project => @project, |
|
60 | 60 | :identifier => 'test' |
|
61 | 61 | ) |
|
62 | 62 | assert !repo.save |
|
63 | 63 | assert_include "Path to repository can't be blank", |
|
64 | 64 | repo.errors.full_messages |
|
65 | 65 | end |
|
66 | 66 | |
|
67 | 67 | def test_blank_path_to_repository_error_message_fr |
|
68 | 68 | set_language_if_valid 'fr' |
|
69 | 69 | str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)" |
|
70 | 70 | str.force_encoding('UTF-8') if str.respond_to?(:force_encoding) |
|
71 | 71 | repo = Repository::Git.new( |
|
72 | 72 | :project => @project, |
|
73 | 73 | :url => "", |
|
74 | 74 | :identifier => 'test', |
|
75 | 75 | :path_encoding => '' |
|
76 | 76 | ) |
|
77 | 77 | assert !repo.save |
|
78 | 78 | assert_include str, repo.errors.full_messages |
|
79 | 79 | end |
|
80 | 80 | |
|
81 | 81 | if File.directory?(REPOSITORY_PATH) |
|
82 | 82 | ## Ruby uses ANSI api to fork a process on Windows. |
|
83 | 83 | ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem |
|
84 | 84 | ## and these are incompatible with ASCII. |
|
85 | 85 | ## Git for Windows (msysGit) changed internal API from ANSI to Unicode in 1.7.10 |
|
86 | 86 | ## http://code.google.com/p/msysgit/issues/detail?id=80 |
|
87 | 87 | ## So, Latin-1 path tests fail on Japanese Windows |
|
88 | 88 | WINDOWS_PASS = (Redmine::Platform.mswin? && |
|
89 | 89 | Redmine::Scm::Adapters::GitAdapter.client_version_above?([1, 7, 10])) |
|
90 | 90 | WINDOWS_SKIP_STR = "TODO: This test fails in Git for Windows above 1.7.10" |
|
91 | 91 | |
|
92 | 92 | def test_scm_available |
|
93 | 93 | klass = Repository::Git |
|
94 | 94 | assert_equal "Git", klass.scm_name |
|
95 | 95 | assert klass.scm_adapter_class |
|
96 | 96 | assert_not_equal "", klass.scm_command |
|
97 | 97 | assert_equal true, klass.scm_available |
|
98 | 98 | end |
|
99 | 99 | |
|
100 | 100 | def test_entries |
|
101 | 101 | entries = @repository.entries |
|
102 | 102 | assert_kind_of Redmine::Scm::Adapters::Entries, entries |
|
103 | 103 | end |
|
104 | 104 | |
|
105 | 105 | def test_fetch_changesets_from_scratch |
|
106 | 106 | assert_nil @repository.extra_info |
|
107 | 107 | |
|
108 | 108 | assert_equal 0, @repository.changesets.count |
|
109 | 109 | @repository.fetch_changesets |
|
110 | 110 | @project.reload |
|
111 | 111 | |
|
112 | 112 | assert_equal NUM_REV, @repository.changesets.count |
|
113 | 113 | assert_equal 39, @repository.filechanges.count |
|
114 | 114 | |
|
115 | 115 | commit = @repository.changesets.find_by_revision("7234cb2750b63f47bff735edc50a1c0a433c2518") |
|
116 | 116 | assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.scmid |
|
117 | 117 | assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments |
|
118 | 118 | assert_equal "jsmith <jsmith@foo.bar>", commit.committer |
|
119 | 119 | assert_equal User.find_by_login('jsmith'), commit.user |
|
120 | 120 | # TODO: add a commit with commit time <> author time to the test repository |
|
121 | 121 | assert_equal "2007-12-14 09:22:52".to_time, commit.committed_on |
|
122 | 122 | assert_equal "2007-12-14".to_date, commit.commit_date |
|
123 | 123 | assert_equal 3, commit.filechanges.count |
|
124 | 124 | change = commit.filechanges.sort_by(&:path).first |
|
125 | 125 | assert_equal "README", change.path |
|
126 | 126 | assert_equal nil, change.from_path |
|
127 | 127 | assert_equal "A", change.action |
|
128 | 128 | |
|
129 | 129 | assert_equal NUM_HEAD, @repository.extra_info["heads"].size |
|
130 | 130 | end |
|
131 | 131 | |
|
132 | 132 | def test_fetch_changesets_incremental |
|
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 | extra_info_heads = @repository.extra_info["heads"].dup |
|
138 | 138 | assert_equal NUM_HEAD, extra_info_heads.size |
|
139 | 139 | extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" } |
|
140 | 140 | assert_equal 4, extra_info_heads.size |
|
141 | 141 | |
|
142 | 142 | del_revs = [ |
|
143 | 143 | "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c", |
|
144 | 144 | "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", |
|
145 | 145 | "4f26664364207fa8b1af9f8722647ab2d4ac5d43", |
|
146 | 146 | "deff712f05a90d96edbd70facc47d944be5897e3", |
|
147 | 147 | "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf", |
|
148 | 148 | "7e61ac704deecde634b51e59daa8110435dcb3da", |
|
149 | 149 | ] |
|
150 | 150 | @repository.changesets.each do |rev| |
|
151 | 151 | rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s } |
|
152 | 152 | end |
|
153 | 153 | @project.reload |
|
154 | 154 | cs1 = @repository.changesets |
|
155 | 155 | assert_equal NUM_REV - 6, cs1.count |
|
156 | 156 | extra_info_heads << "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8" |
|
157 | 157 | h = {} |
|
158 | 158 | h["heads"] = extra_info_heads |
|
159 | 159 | @repository.merge_extra_info(h) |
|
160 | 160 | @repository.save |
|
161 | 161 | @project.reload |
|
162 | 162 | assert @repository.extra_info["heads"].index("4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8") |
|
163 | 163 | @repository.fetch_changesets |
|
164 | 164 | @project.reload |
|
165 | 165 | assert_equal NUM_REV, @repository.changesets.count |
|
166 | 166 | assert_equal NUM_HEAD, @repository.extra_info["heads"].size |
|
167 | 167 | assert @repository.extra_info["heads"].index("83ca5fd546063a3c7dc2e568ba3355661a9e2b2c") |
|
168 | 168 | end |
|
169 | 169 | |
|
170 | 170 | def test_fetch_changesets_history_editing |
|
171 | 171 | assert_equal 0, @repository.changesets.count |
|
172 | 172 | @repository.fetch_changesets |
|
173 | 173 | @project.reload |
|
174 | 174 | assert_equal NUM_REV, @repository.changesets.count |
|
175 | 175 | extra_info_heads = @repository.extra_info["heads"].dup |
|
176 | 176 | assert_equal NUM_HEAD, extra_info_heads.size |
|
177 | 177 | extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" } |
|
178 | 178 | assert_equal 4, extra_info_heads.size |
|
179 | 179 | |
|
180 | 180 | del_revs = [ |
|
181 | 181 | "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c", |
|
182 | 182 | "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", |
|
183 | 183 | "4f26664364207fa8b1af9f8722647ab2d4ac5d43", |
|
184 | 184 | "deff712f05a90d96edbd70facc47d944be5897e3", |
|
185 | 185 | "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf", |
|
186 | 186 | "7e61ac704deecde634b51e59daa8110435dcb3da", |
|
187 | 187 | ] |
|
188 | 188 | @repository.changesets.each do |rev| |
|
189 | 189 | rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s } |
|
190 | 190 | end |
|
191 | 191 | @project.reload |
|
192 | 192 | assert_equal NUM_REV - 6, @repository.changesets.count |
|
193 | 193 | |
|
194 | 194 | c = Changeset.new(:repository => @repository, |
|
195 | 195 | :committed_on => Time.now, |
|
196 | 196 | :revision => "abcd1234efgh", |
|
197 | 197 | :scmid => "abcd1234efgh", |
|
198 | 198 | :comments => 'test') |
|
199 | 199 | assert c.save |
|
200 | 200 | @project.reload |
|
201 | 201 | assert_equal NUM_REV - 5, @repository.changesets.count |
|
202 | 202 | |
|
203 | 203 | extra_info_heads << "1234abcd5678" |
|
204 | 204 | h = {} |
|
205 | 205 | h["heads"] = extra_info_heads |
|
206 | 206 | @repository.merge_extra_info(h) |
|
207 | 207 | @repository.save |
|
208 | 208 | @project.reload |
|
209 | 209 | h1 = @repository.extra_info["heads"].dup |
|
210 | 210 | assert h1.index("1234abcd5678") |
|
211 | 211 | assert_equal 5, h1.size |
|
212 | 212 | |
|
213 | 213 | @repository.fetch_changesets |
|
214 | 214 | @project.reload |
|
215 | 215 | assert_equal NUM_REV - 5, @repository.changesets.count |
|
216 | 216 | h2 = @repository.extra_info["heads"].dup |
|
217 | 217 | assert_equal h1, h2 |
|
218 | 218 | end |
|
219 | 219 | |
|
220 | 220 | def test_keep_extra_report_last_commit_in_clear_changesets |
|
221 | 221 | assert_nil @repository.extra_info |
|
222 | 222 | h = {} |
|
223 | h["extra_report_last_commit"] = 1 | |
|
223 | h["extra_report_last_commit"] = "1" | |
|
224 | 224 | @repository.merge_extra_info(h) |
|
225 | 225 | @repository.save |
|
226 | 226 | @project.reload |
|
227 | 227 | |
|
228 | 228 | assert_equal 0, @repository.changesets.count |
|
229 | 229 | @repository.fetch_changesets |
|
230 | 230 | @project.reload |
|
231 | 231 | |
|
232 | 232 | assert_equal NUM_REV, @repository.changesets.count |
|
233 | 233 | @repository.send(:clear_changesets) |
|
234 | 234 | assert_equal 1, @repository.extra_info.size |
|
235 | assert_equal 1, @repository.extra_info["extra_report_last_commit"] | |
|
235 | assert_equal "1", @repository.extra_info["extra_report_last_commit"] | |
|
236 | 236 | end |
|
237 | 237 | |
|
238 | 238 | def test_refetch_after_clear_changesets |
|
239 | 239 | assert_nil @repository.extra_info |
|
240 | 240 | assert_equal 0, @repository.changesets.count |
|
241 | 241 | @repository.fetch_changesets |
|
242 | 242 | @project.reload |
|
243 | 243 | assert_equal NUM_REV, @repository.changesets.count |
|
244 | 244 | |
|
245 | 245 | @repository.send(:clear_changesets) |
|
246 | 246 | @project.reload |
|
247 | 247 | assert_equal 0, @repository.changesets.count |
|
248 | 248 | |
|
249 | 249 | @repository.fetch_changesets |
|
250 | 250 | @project.reload |
|
251 | 251 | assert_equal NUM_REV, @repository.changesets.count |
|
252 | 252 | end |
|
253 | 253 | |
|
254 | 254 | def test_parents |
|
255 | 255 | assert_equal 0, @repository.changesets.count |
|
256 | 256 | @repository.fetch_changesets |
|
257 | 257 | @project.reload |
|
258 | 258 | assert_equal NUM_REV, @repository.changesets.count |
|
259 | 259 | r1 = @repository.find_changeset_by_name("7234cb2750b63") |
|
260 | 260 | assert_equal [], r1.parents |
|
261 | 261 | r2 = @repository.find_changeset_by_name("899a15dba03a3") |
|
262 | 262 | assert_equal 1, r2.parents.length |
|
263 | 263 | assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", |
|
264 | 264 | r2.parents[0].identifier |
|
265 | 265 | r3 = @repository.find_changeset_by_name("32ae898b720c2") |
|
266 | 266 | assert_equal 2, r3.parents.length |
|
267 | 267 | r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort |
|
268 | 268 | assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", r4[0] |
|
269 | 269 | assert_equal "7e61ac704deecde634b51e59daa8110435dcb3da", r4[1] |
|
270 | 270 | end |
|
271 | 271 | |
|
272 | 272 | def test_db_consistent_ordering_init |
|
273 | 273 | assert_nil @repository.extra_info |
|
274 | 274 | assert_equal 0, @repository.changesets.count |
|
275 | 275 | @repository.fetch_changesets |
|
276 | 276 | @project.reload |
|
277 | 277 | assert_equal 1, @repository.extra_info["db_consistent"]["ordering"] |
|
278 | 278 | end |
|
279 | 279 | |
|
280 | 280 | def test_db_consistent_ordering_before_1_2 |
|
281 | 281 | assert_nil @repository.extra_info |
|
282 | 282 | assert_equal 0, @repository.changesets.count |
|
283 | 283 | @repository.fetch_changesets |
|
284 | 284 | @project.reload |
|
285 | 285 | assert_equal NUM_REV, @repository.changesets.count |
|
286 | 286 | assert_not_nil @repository.extra_info |
|
287 | 287 | h = {} |
|
288 | 288 | h["heads"] = [] |
|
289 | 289 | h["branches"] = {} |
|
290 | 290 | h["db_consistent"] = {} |
|
291 | 291 | @repository.merge_extra_info(h) |
|
292 | 292 | @repository.save |
|
293 | 293 | assert_equal NUM_REV, @repository.changesets.count |
|
294 | 294 | @repository.fetch_changesets |
|
295 | 295 | @project.reload |
|
296 | 296 | assert_equal 0, @repository.extra_info["db_consistent"]["ordering"] |
|
297 | 297 | |
|
298 | 298 | extra_info_heads = @repository.extra_info["heads"].dup |
|
299 | 299 | extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" } |
|
300 | 300 | del_revs = [ |
|
301 | 301 | "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c", |
|
302 | 302 | "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", |
|
303 | 303 | "4f26664364207fa8b1af9f8722647ab2d4ac5d43", |
|
304 | 304 | "deff712f05a90d96edbd70facc47d944be5897e3", |
|
305 | 305 | "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf", |
|
306 | 306 | "7e61ac704deecde634b51e59daa8110435dcb3da", |
|
307 | 307 | ] |
|
308 | 308 | @repository.changesets.each do |rev| |
|
309 | 309 | rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s } |
|
310 | 310 | end |
|
311 | 311 | @project.reload |
|
312 | 312 | cs1 = @repository.changesets |
|
313 | 313 | assert_equal NUM_REV - 6, cs1.count |
|
314 | 314 | assert_equal 0, @repository.extra_info["db_consistent"]["ordering"] |
|
315 | 315 | |
|
316 | 316 | extra_info_heads << "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8" |
|
317 | 317 | h = {} |
|
318 | 318 | h["heads"] = extra_info_heads |
|
319 | 319 | @repository.merge_extra_info(h) |
|
320 | 320 | @repository.save |
|
321 | 321 | @project.reload |
|
322 | 322 | assert @repository.extra_info["heads"].index("4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8") |
|
323 | 323 | @repository.fetch_changesets |
|
324 | 324 | @project.reload |
|
325 | 325 | assert_equal NUM_REV, @repository.changesets.count |
|
326 | 326 | assert_equal NUM_HEAD, @repository.extra_info["heads"].size |
|
327 | 327 | |
|
328 | 328 | assert_equal 0, @repository.extra_info["db_consistent"]["ordering"] |
|
329 | 329 | end |
|
330 | 330 | |
|
331 | 331 | def test_heads_from_branches_hash |
|
332 | 332 | assert_nil @repository.extra_info |
|
333 | 333 | assert_equal 0, @repository.changesets.count |
|
334 | 334 | assert_equal [], @repository.heads_from_branches_hash |
|
335 | 335 | h = {} |
|
336 | 336 | h["branches"] = {} |
|
337 | 337 | h["branches"]["test1"] = {} |
|
338 | 338 | h["branches"]["test1"]["last_scmid"] = "1234abcd" |
|
339 | 339 | h["branches"]["test2"] = {} |
|
340 | 340 | h["branches"]["test2"]["last_scmid"] = "abcd1234" |
|
341 | 341 | @repository.merge_extra_info(h) |
|
342 | 342 | @repository.save |
|
343 | 343 | @project.reload |
|
344 | 344 | assert_equal ["1234abcd", "abcd1234"], @repository.heads_from_branches_hash.sort |
|
345 | 345 | end |
|
346 | 346 | |
|
347 | 347 | def test_latest_changesets |
|
348 | 348 | assert_equal 0, @repository.changesets.count |
|
349 | 349 | @repository.fetch_changesets |
|
350 | 350 | @project.reload |
|
351 | 351 | assert_equal NUM_REV, @repository.changesets.count |
|
352 | 352 | # with limit |
|
353 | 353 | changesets = @repository.latest_changesets('', 'master', 2) |
|
354 | 354 | assert_equal 2, changesets.size |
|
355 | 355 | |
|
356 | 356 | # with path |
|
357 | 357 | changesets = @repository.latest_changesets('images', 'master') |
|
358 | 358 | assert_equal [ |
|
359 | 359 | 'deff712f05a90d96edbd70facc47d944be5897e3', |
|
360 | 360 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
361 | 361 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
362 | 362 | ], changesets.collect(&:revision) |
|
363 | 363 | |
|
364 | 364 | changesets = @repository.latest_changesets('README', nil) |
|
365 | 365 | assert_equal [ |
|
366 | 366 | '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf', |
|
367 | 367 | '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8', |
|
368 | 368 | '713f4944648826f558cf548222f813dabe7cbb04', |
|
369 | 369 | '61b685fbe55ab05b5ac68402d5720c1a6ac973d1', |
|
370 | 370 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
371 | 371 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
372 | 372 | ], changesets.collect(&:revision) |
|
373 | 373 | |
|
374 | 374 | # with path, revision and limit |
|
375 | 375 | changesets = @repository.latest_changesets('images', '899a15dba') |
|
376 | 376 | assert_equal [ |
|
377 | 377 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
378 | 378 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
379 | 379 | ], changesets.collect(&:revision) |
|
380 | 380 | |
|
381 | 381 | changesets = @repository.latest_changesets('images', '899a15dba', 1) |
|
382 | 382 | assert_equal [ |
|
383 | 383 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
384 | 384 | ], changesets.collect(&:revision) |
|
385 | 385 | |
|
386 | 386 | changesets = @repository.latest_changesets('README', '899a15dba') |
|
387 | 387 | assert_equal [ |
|
388 | 388 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
389 | 389 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
390 | 390 | ], changesets.collect(&:revision) |
|
391 | 391 | |
|
392 | 392 | changesets = @repository.latest_changesets('README', '899a15dba', 1) |
|
393 | 393 | assert_equal [ |
|
394 | 394 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
395 | 395 | ], changesets.collect(&:revision) |
|
396 | 396 | |
|
397 | 397 | # with path, tag and limit |
|
398 | 398 | changesets = @repository.latest_changesets('images', 'tag01.annotated') |
|
399 | 399 | assert_equal [ |
|
400 | 400 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
401 | 401 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
402 | 402 | ], changesets.collect(&:revision) |
|
403 | 403 | |
|
404 | 404 | changesets = @repository.latest_changesets('images', 'tag01.annotated', 1) |
|
405 | 405 | assert_equal [ |
|
406 | 406 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
407 | 407 | ], changesets.collect(&:revision) |
|
408 | 408 | |
|
409 | 409 | changesets = @repository.latest_changesets('README', 'tag01.annotated') |
|
410 | 410 | assert_equal [ |
|
411 | 411 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
412 | 412 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
413 | 413 | ], changesets.collect(&:revision) |
|
414 | 414 | |
|
415 | 415 | changesets = @repository.latest_changesets('README', 'tag01.annotated', 1) |
|
416 | 416 | assert_equal [ |
|
417 | 417 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
418 | 418 | ], changesets.collect(&:revision) |
|
419 | 419 | |
|
420 | 420 | # with path, branch and limit |
|
421 | 421 | changesets = @repository.latest_changesets('images', 'test_branch') |
|
422 | 422 | assert_equal [ |
|
423 | 423 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
424 | 424 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
425 | 425 | ], changesets.collect(&:revision) |
|
426 | 426 | |
|
427 | 427 | changesets = @repository.latest_changesets('images', 'test_branch', 1) |
|
428 | 428 | assert_equal [ |
|
429 | 429 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
430 | 430 | ], changesets.collect(&:revision) |
|
431 | 431 | |
|
432 | 432 | changesets = @repository.latest_changesets('README', 'test_branch') |
|
433 | 433 | assert_equal [ |
|
434 | 434 | '713f4944648826f558cf548222f813dabe7cbb04', |
|
435 | 435 | '61b685fbe55ab05b5ac68402d5720c1a6ac973d1', |
|
436 | 436 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
437 | 437 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
438 | 438 | ], changesets.collect(&:revision) |
|
439 | 439 | |
|
440 | 440 | changesets = @repository.latest_changesets('README', 'test_branch', 2) |
|
441 | 441 | assert_equal [ |
|
442 | 442 | '713f4944648826f558cf548222f813dabe7cbb04', |
|
443 | 443 | '61b685fbe55ab05b5ac68402d5720c1a6ac973d1', |
|
444 | 444 | ], changesets.collect(&:revision) |
|
445 | 445 | |
|
446 | 446 | if WINDOWS_PASS |
|
447 | 447 | puts WINDOWS_SKIP_STR |
|
448 | 448 | elsif JRUBY_SKIP |
|
449 | 449 | puts JRUBY_SKIP_STR |
|
450 | 450 | else |
|
451 | 451 | # latin-1 encoding path |
|
452 | 452 | changesets = @repository.latest_changesets( |
|
453 | 453 | "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89') |
|
454 | 454 | assert_equal [ |
|
455 | 455 | '64f1f3e89ad1cb57976ff0ad99a107012ba3481d', |
|
456 | 456 | '4fc55c43bf3d3dc2efb66145365ddc17639ce81e', |
|
457 | 457 | ], changesets.collect(&:revision) |
|
458 | 458 | |
|
459 | 459 | changesets = @repository.latest_changesets( |
|
460 | 460 | "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89', 1) |
|
461 | 461 | assert_equal [ |
|
462 | 462 | '64f1f3e89ad1cb57976ff0ad99a107012ba3481d', |
|
463 | 463 | ], changesets.collect(&:revision) |
|
464 | 464 | end |
|
465 | 465 | end |
|
466 | 466 | |
|
467 | 467 | def test_latest_changesets_latin_1_dir |
|
468 | 468 | if WINDOWS_PASS |
|
469 | 469 | puts WINDOWS_SKIP_STR |
|
470 | 470 | elsif JRUBY_SKIP |
|
471 | 471 | puts JRUBY_SKIP_STR |
|
472 | 472 | else |
|
473 | 473 | assert_equal 0, @repository.changesets.count |
|
474 | 474 | @repository.fetch_changesets |
|
475 | 475 | @project.reload |
|
476 | 476 | assert_equal NUM_REV, @repository.changesets.count |
|
477 | 477 | changesets = @repository.latest_changesets( |
|
478 | 478 | "latin-1-dir/test-#{@char_1}-subdir", '1ca7f5ed') |
|
479 | 479 | assert_equal [ |
|
480 | 480 | '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', |
|
481 | 481 | ], changesets.collect(&:revision) |
|
482 | 482 | end |
|
483 | 483 | end |
|
484 | 484 | |
|
485 | 485 | def test_find_changeset_by_name |
|
486 | 486 | assert_equal 0, @repository.changesets.count |
|
487 | 487 | @repository.fetch_changesets |
|
488 | 488 | @project.reload |
|
489 | 489 | assert_equal NUM_REV, @repository.changesets.count |
|
490 | 490 | ['7234cb2750b63f47bff735edc50a1c0a433c2518', '7234cb2750b'].each do |r| |
|
491 | 491 | assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
492 | 492 | @repository.find_changeset_by_name(r).revision |
|
493 | 493 | end |
|
494 | 494 | end |
|
495 | 495 | |
|
496 | 496 | def test_find_changeset_by_empty_name |
|
497 | 497 | assert_equal 0, @repository.changesets.count |
|
498 | 498 | @repository.fetch_changesets |
|
499 | 499 | @project.reload |
|
500 | 500 | assert_equal NUM_REV, @repository.changesets.count |
|
501 | 501 | ['', ' ', nil].each do |r| |
|
502 | 502 | assert_nil @repository.find_changeset_by_name(r) |
|
503 | 503 | end |
|
504 | 504 | end |
|
505 | 505 | |
|
506 | 506 | def test_identifier |
|
507 | 507 | assert_equal 0, @repository.changesets.count |
|
508 | 508 | @repository.fetch_changesets |
|
509 | 509 | @project.reload |
|
510 | 510 | assert_equal NUM_REV, @repository.changesets.count |
|
511 | 511 | c = @repository.changesets.find_by_revision( |
|
512 | 512 | '7234cb2750b63f47bff735edc50a1c0a433c2518') |
|
513 | 513 | assert_equal c.scmid, c.identifier |
|
514 | 514 | end |
|
515 | 515 | |
|
516 | 516 | def test_format_identifier |
|
517 | 517 | assert_equal 0, @repository.changesets.count |
|
518 | 518 | @repository.fetch_changesets |
|
519 | 519 | @project.reload |
|
520 | 520 | assert_equal NUM_REV, @repository.changesets.count |
|
521 | 521 | c = @repository.changesets.find_by_revision( |
|
522 | 522 | '7234cb2750b63f47bff735edc50a1c0a433c2518') |
|
523 | 523 | assert_equal '7234cb27', c.format_identifier |
|
524 | 524 | end |
|
525 | 525 | |
|
526 | 526 | def test_activities |
|
527 | 527 | c = Changeset.new(:repository => @repository, |
|
528 | 528 | :committed_on => Time.now, |
|
529 | 529 | :revision => 'abc7234cb2750b63f47bff735edc50a1c0a433c2', |
|
530 | 530 | :scmid => 'abc7234cb2750b63f47bff735edc50a1c0a433c2', |
|
531 | 531 | :comments => 'test') |
|
532 | 532 | assert c.event_title.include?('abc7234c:') |
|
533 | 533 | assert_equal 'abc7234cb2750b63f47bff735edc50a1c0a433c2', c.event_url[:rev] |
|
534 | 534 | end |
|
535 | 535 | |
|
536 | 536 | def test_log_utf8 |
|
537 | 537 | assert_equal 0, @repository.changesets.count |
|
538 | 538 | @repository.fetch_changesets |
|
539 | 539 | @project.reload |
|
540 | 540 | assert_equal NUM_REV, @repository.changesets.count |
|
541 | 541 | str_felix_hex = FELIX_HEX.dup |
|
542 | 542 | if str_felix_hex.respond_to?(:force_encoding) |
|
543 | 543 | str_felix_hex.force_encoding('UTF-8') |
|
544 | 544 | end |
|
545 | 545 | c = @repository.changesets.find_by_revision( |
|
546 | 546 | 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b') |
|
547 | 547 | assert_equal "#{str_felix_hex} <felix@fachschaften.org>", c.committer |
|
548 | 548 | end |
|
549 | 549 | |
|
550 | 550 | def test_previous |
|
551 | 551 | assert_equal 0, @repository.changesets.count |
|
552 | 552 | @repository.fetch_changesets |
|
553 | 553 | @project.reload |
|
554 | 554 | assert_equal NUM_REV, @repository.changesets.count |
|
555 | 555 | %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1| |
|
556 | 556 | changeset = @repository.find_changeset_by_name(r1) |
|
557 | 557 | %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2| |
|
558 | 558 | assert_equal @repository.find_changeset_by_name(r2), changeset.previous |
|
559 | 559 | end |
|
560 | 560 | end |
|
561 | 561 | end |
|
562 | 562 | |
|
563 | 563 | def test_previous_nil |
|
564 | 564 | assert_equal 0, @repository.changesets.count |
|
565 | 565 | @repository.fetch_changesets |
|
566 | 566 | @project.reload |
|
567 | 567 | assert_equal NUM_REV, @repository.changesets.count |
|
568 | 568 | %w|7234cb2750b63f47bff735edc50a1c0a433c2518 7234cb275|.each do |r1| |
|
569 | 569 | changeset = @repository.find_changeset_by_name(r1) |
|
570 | 570 | assert_nil changeset.previous |
|
571 | 571 | end |
|
572 | 572 | end |
|
573 | 573 | |
|
574 | 574 | def test_next |
|
575 | 575 | assert_equal 0, @repository.changesets.count |
|
576 | 576 | @repository.fetch_changesets |
|
577 | 577 | @project.reload |
|
578 | 578 | assert_equal NUM_REV, @repository.changesets.count |
|
579 | 579 | %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2| |
|
580 | 580 | changeset = @repository.find_changeset_by_name(r2) |
|
581 | 581 | %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1| |
|
582 | 582 | assert_equal @repository.find_changeset_by_name(r1), changeset.next |
|
583 | 583 | end |
|
584 | 584 | end |
|
585 | 585 | end |
|
586 | 586 | |
|
587 | 587 | def test_next_nil |
|
588 | 588 | assert_equal 0, @repository.changesets.count |
|
589 | 589 | @repository.fetch_changesets |
|
590 | 590 | @project.reload |
|
591 | 591 | assert_equal NUM_REV, @repository.changesets.count |
|
592 | 592 | %w|2a682156a3b6e77a8bf9cd4590e8db757f3c6c78 2a682156a3b6e77a|.each do |r1| |
|
593 | 593 | changeset = @repository.find_changeset_by_name(r1) |
|
594 | 594 | assert_nil changeset.next |
|
595 | 595 | end |
|
596 | 596 | end |
|
597 | 597 | else |
|
598 | 598 | puts "Git test repository NOT FOUND. Skipping unit tests !!!" |
|
599 | 599 | def test_fake; assert true end |
|
600 | 600 | end |
|
601 | 601 | end |
General Comments 0
You need to be logged in to leave comments.
Login now