@@ -1,596 +1,596 | |||
|
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 | 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_fetch_changesets_from_scratch |
|
101 | 101 | assert_nil @repository.extra_info |
|
102 | 102 | |
|
103 | 103 | assert_equal 0, @repository.changesets.count |
|
104 | 104 | @repository.fetch_changesets |
|
105 | 105 | @project.reload |
|
106 | 106 | |
|
107 | 107 | assert_equal NUM_REV, @repository.changesets.count |
|
108 | 108 | assert_equal 39, @repository.changes.count |
|
109 | 109 | |
|
110 | 110 | commit = @repository.changesets.find_by_revision("7234cb2750b63f47bff735edc50a1c0a433c2518") |
|
111 | 111 | assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.scmid |
|
112 | 112 | assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments |
|
113 | 113 | assert_equal "jsmith <jsmith@foo.bar>", commit.committer |
|
114 | 114 | assert_equal User.find_by_login('jsmith'), commit.user |
|
115 | 115 | # TODO: add a commit with commit time <> author time to the test repository |
|
116 | 116 | assert_equal "2007-12-14 09:22:52".to_time, commit.committed_on |
|
117 | 117 | assert_equal "2007-12-14".to_date, commit.commit_date |
|
118 | 118 | assert_equal 3, commit.changes.count |
|
119 | 119 | change = commit.changes.sort_by(&:path).first |
|
120 | 120 | assert_equal "README", change.path |
|
121 | 121 | assert_equal nil, change.from_path |
|
122 | 122 | assert_equal "A", change.action |
|
123 | 123 | |
|
124 | 124 | assert_equal NUM_HEAD, @repository.extra_info["heads"].size |
|
125 | 125 | end |
|
126 | 126 | |
|
127 | 127 | def test_fetch_changesets_incremental |
|
128 | 128 | assert_equal 0, @repository.changesets.count |
|
129 | 129 | @repository.fetch_changesets |
|
130 | 130 | @project.reload |
|
131 | 131 | assert_equal NUM_REV, @repository.changesets.count |
|
132 | 132 | extra_info_heads = @repository.extra_info["heads"].dup |
|
133 | 133 | assert_equal NUM_HEAD, extra_info_heads.size |
|
134 | 134 | extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" } |
|
135 | 135 | assert_equal 4, extra_info_heads.size |
|
136 | 136 | |
|
137 | 137 | del_revs = [ |
|
138 | 138 | "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c", |
|
139 | 139 | "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", |
|
140 | 140 | "4f26664364207fa8b1af9f8722647ab2d4ac5d43", |
|
141 | 141 | "deff712f05a90d96edbd70facc47d944be5897e3", |
|
142 | 142 | "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf", |
|
143 | 143 | "7e61ac704deecde634b51e59daa8110435dcb3da", |
|
144 | 144 | ] |
|
145 | 145 | @repository.changesets.each do |rev| |
|
146 | 146 | rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s } |
|
147 | 147 | end |
|
148 | 148 | @project.reload |
|
149 | 149 | cs1 = @repository.changesets |
|
150 | 150 | assert_equal NUM_REV - 6, cs1.count |
|
151 | 151 | extra_info_heads << "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8" |
|
152 | 152 | h = {} |
|
153 | 153 | h["heads"] = extra_info_heads |
|
154 | 154 | @repository.merge_extra_info(h) |
|
155 | 155 | @repository.save |
|
156 | 156 | @project.reload |
|
157 | 157 | assert @repository.extra_info["heads"].index("4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8") |
|
158 | 158 | @repository.fetch_changesets |
|
159 | 159 | @project.reload |
|
160 | 160 | assert_equal NUM_REV, @repository.changesets.count |
|
161 | 161 | assert_equal NUM_HEAD, @repository.extra_info["heads"].size |
|
162 | 162 | assert @repository.extra_info["heads"].index("83ca5fd546063a3c7dc2e568ba3355661a9e2b2c") |
|
163 | 163 | end |
|
164 | 164 | |
|
165 | 165 | def test_fetch_changesets_history_editing |
|
166 | 166 | assert_equal 0, @repository.changesets.count |
|
167 | 167 | @repository.fetch_changesets |
|
168 | 168 | @project.reload |
|
169 | 169 | assert_equal NUM_REV, @repository.changesets.count |
|
170 | 170 | extra_info_heads = @repository.extra_info["heads"].dup |
|
171 | 171 | assert_equal NUM_HEAD, extra_info_heads.size |
|
172 | 172 | extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" } |
|
173 | 173 | assert_equal 4, extra_info_heads.size |
|
174 | 174 | |
|
175 | 175 | del_revs = [ |
|
176 | 176 | "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c", |
|
177 | 177 | "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", |
|
178 | 178 | "4f26664364207fa8b1af9f8722647ab2d4ac5d43", |
|
179 | 179 | "deff712f05a90d96edbd70facc47d944be5897e3", |
|
180 | 180 | "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf", |
|
181 | 181 | "7e61ac704deecde634b51e59daa8110435dcb3da", |
|
182 | 182 | ] |
|
183 | 183 | @repository.changesets.each do |rev| |
|
184 | 184 | rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s } |
|
185 | 185 | end |
|
186 | 186 | @project.reload |
|
187 | 187 | assert_equal NUM_REV - 6, @repository.changesets.count |
|
188 | 188 | |
|
189 | 189 | c = Changeset.new(:repository => @repository, |
|
190 | 190 | :committed_on => Time.now, |
|
191 | 191 | :revision => "abcd1234efgh", |
|
192 | 192 | :scmid => "abcd1234efgh", |
|
193 | 193 | :comments => 'test') |
|
194 | 194 | assert c.save |
|
195 | 195 | @project.reload |
|
196 | 196 | assert_equal NUM_REV - 5, @repository.changesets.count |
|
197 | 197 | |
|
198 | 198 | extra_info_heads << "1234abcd5678" |
|
199 | 199 | h = {} |
|
200 | 200 | h["heads"] = extra_info_heads |
|
201 | 201 | @repository.merge_extra_info(h) |
|
202 | 202 | @repository.save |
|
203 | 203 | @project.reload |
|
204 | 204 | h1 = @repository.extra_info["heads"].dup |
|
205 | 205 | assert h1.index("1234abcd5678") |
|
206 | 206 | assert_equal 5, h1.size |
|
207 | 207 | |
|
208 | 208 | @repository.fetch_changesets |
|
209 | 209 | @project.reload |
|
210 | 210 | assert_equal NUM_REV - 5, @repository.changesets.count |
|
211 | 211 | h2 = @repository.extra_info["heads"].dup |
|
212 | 212 | assert_equal h1, h2 |
|
213 | 213 | end |
|
214 | 214 | |
|
215 | 215 | def test_keep_extra_report_last_commit_in_clear_changesets |
|
216 | 216 | assert_nil @repository.extra_info |
|
217 | 217 | h = {} |
|
218 | h["extra_report_last_commit"] = 1 | |
|
218 | h["extra_report_last_commit"] = "1" | |
|
219 | 219 | @repository.merge_extra_info(h) |
|
220 | 220 | @repository.save |
|
221 | 221 | @project.reload |
|
222 | 222 | |
|
223 | 223 | assert_equal 0, @repository.changesets.count |
|
224 | 224 | @repository.fetch_changesets |
|
225 | 225 | @project.reload |
|
226 | 226 | |
|
227 | 227 | assert_equal NUM_REV, @repository.changesets.count |
|
228 | 228 | @repository.send(:clear_changesets) |
|
229 | 229 | assert_equal 1, @repository.extra_info.size |
|
230 | assert_equal 1, @repository.extra_info["extra_report_last_commit"] | |
|
230 | assert_equal "1", @repository.extra_info["extra_report_last_commit"] | |
|
231 | 231 | end |
|
232 | 232 | |
|
233 | 233 | def test_refetch_after_clear_changesets |
|
234 | 234 | assert_nil @repository.extra_info |
|
235 | 235 | assert_equal 0, @repository.changesets.count |
|
236 | 236 | @repository.fetch_changesets |
|
237 | 237 | @project.reload |
|
238 | 238 | assert_equal NUM_REV, @repository.changesets.count |
|
239 | 239 | |
|
240 | 240 | @repository.send(:clear_changesets) |
|
241 | 241 | @project.reload |
|
242 | 242 | assert_equal 0, @repository.changesets.count |
|
243 | 243 | |
|
244 | 244 | @repository.fetch_changesets |
|
245 | 245 | @project.reload |
|
246 | 246 | assert_equal NUM_REV, @repository.changesets.count |
|
247 | 247 | end |
|
248 | 248 | |
|
249 | 249 | def test_parents |
|
250 | 250 | assert_equal 0, @repository.changesets.count |
|
251 | 251 | @repository.fetch_changesets |
|
252 | 252 | @project.reload |
|
253 | 253 | assert_equal NUM_REV, @repository.changesets.count |
|
254 | 254 | r1 = @repository.find_changeset_by_name("7234cb2750b63") |
|
255 | 255 | assert_equal [], r1.parents |
|
256 | 256 | r2 = @repository.find_changeset_by_name("899a15dba03a3") |
|
257 | 257 | assert_equal 1, r2.parents.length |
|
258 | 258 | assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", |
|
259 | 259 | r2.parents[0].identifier |
|
260 | 260 | r3 = @repository.find_changeset_by_name("32ae898b720c2") |
|
261 | 261 | assert_equal 2, r3.parents.length |
|
262 | 262 | r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort |
|
263 | 263 | assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", r4[0] |
|
264 | 264 | assert_equal "7e61ac704deecde634b51e59daa8110435dcb3da", r4[1] |
|
265 | 265 | end |
|
266 | 266 | |
|
267 | 267 | def test_db_consistent_ordering_init |
|
268 | 268 | assert_nil @repository.extra_info |
|
269 | 269 | assert_equal 0, @repository.changesets.count |
|
270 | 270 | @repository.fetch_changesets |
|
271 | 271 | @project.reload |
|
272 | 272 | assert_equal 1, @repository.extra_info["db_consistent"]["ordering"] |
|
273 | 273 | end |
|
274 | 274 | |
|
275 | 275 | def test_db_consistent_ordering_before_1_2 |
|
276 | 276 | assert_nil @repository.extra_info |
|
277 | 277 | assert_equal 0, @repository.changesets.count |
|
278 | 278 | @repository.fetch_changesets |
|
279 | 279 | @project.reload |
|
280 | 280 | assert_equal NUM_REV, @repository.changesets.count |
|
281 | 281 | assert_not_nil @repository.extra_info |
|
282 | 282 | h = {} |
|
283 | 283 | h["heads"] = [] |
|
284 | 284 | h["branches"] = {} |
|
285 | 285 | h["db_consistent"] = {} |
|
286 | 286 | @repository.merge_extra_info(h) |
|
287 | 287 | @repository.save |
|
288 | 288 | assert_equal NUM_REV, @repository.changesets.count |
|
289 | 289 | @repository.fetch_changesets |
|
290 | 290 | @project.reload |
|
291 | 291 | assert_equal 0, @repository.extra_info["db_consistent"]["ordering"] |
|
292 | 292 | |
|
293 | 293 | extra_info_heads = @repository.extra_info["heads"].dup |
|
294 | 294 | extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" } |
|
295 | 295 | del_revs = [ |
|
296 | 296 | "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c", |
|
297 | 297 | "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", |
|
298 | 298 | "4f26664364207fa8b1af9f8722647ab2d4ac5d43", |
|
299 | 299 | "deff712f05a90d96edbd70facc47d944be5897e3", |
|
300 | 300 | "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf", |
|
301 | 301 | "7e61ac704deecde634b51e59daa8110435dcb3da", |
|
302 | 302 | ] |
|
303 | 303 | @repository.changesets.each do |rev| |
|
304 | 304 | rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s } |
|
305 | 305 | end |
|
306 | 306 | @project.reload |
|
307 | 307 | cs1 = @repository.changesets |
|
308 | 308 | assert_equal NUM_REV - 6, cs1.count |
|
309 | 309 | assert_equal 0, @repository.extra_info["db_consistent"]["ordering"] |
|
310 | 310 | |
|
311 | 311 | extra_info_heads << "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8" |
|
312 | 312 | h = {} |
|
313 | 313 | h["heads"] = extra_info_heads |
|
314 | 314 | @repository.merge_extra_info(h) |
|
315 | 315 | @repository.save |
|
316 | 316 | @project.reload |
|
317 | 317 | assert @repository.extra_info["heads"].index("4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8") |
|
318 | 318 | @repository.fetch_changesets |
|
319 | 319 | @project.reload |
|
320 | 320 | assert_equal NUM_REV, @repository.changesets.count |
|
321 | 321 | assert_equal NUM_HEAD, @repository.extra_info["heads"].size |
|
322 | 322 | |
|
323 | 323 | assert_equal 0, @repository.extra_info["db_consistent"]["ordering"] |
|
324 | 324 | end |
|
325 | 325 | |
|
326 | 326 | def test_heads_from_branches_hash |
|
327 | 327 | assert_nil @repository.extra_info |
|
328 | 328 | assert_equal 0, @repository.changesets.count |
|
329 | 329 | assert_equal [], @repository.heads_from_branches_hash |
|
330 | 330 | h = {} |
|
331 | 331 | h["branches"] = {} |
|
332 | 332 | h["branches"]["test1"] = {} |
|
333 | 333 | h["branches"]["test1"]["last_scmid"] = "1234abcd" |
|
334 | 334 | h["branches"]["test2"] = {} |
|
335 | 335 | h["branches"]["test2"]["last_scmid"] = "abcd1234" |
|
336 | 336 | @repository.merge_extra_info(h) |
|
337 | 337 | @repository.save |
|
338 | 338 | @project.reload |
|
339 | 339 | assert_equal ["1234abcd", "abcd1234"], @repository.heads_from_branches_hash.sort |
|
340 | 340 | end |
|
341 | 341 | |
|
342 | 342 | def test_latest_changesets |
|
343 | 343 | assert_equal 0, @repository.changesets.count |
|
344 | 344 | @repository.fetch_changesets |
|
345 | 345 | @project.reload |
|
346 | 346 | assert_equal NUM_REV, @repository.changesets.count |
|
347 | 347 | # with limit |
|
348 | 348 | changesets = @repository.latest_changesets('', 'master', 2) |
|
349 | 349 | assert_equal 2, changesets.size |
|
350 | 350 | |
|
351 | 351 | # with path |
|
352 | 352 | changesets = @repository.latest_changesets('images', 'master') |
|
353 | 353 | assert_equal [ |
|
354 | 354 | 'deff712f05a90d96edbd70facc47d944be5897e3', |
|
355 | 355 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
356 | 356 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
357 | 357 | ], changesets.collect(&:revision) |
|
358 | 358 | |
|
359 | 359 | changesets = @repository.latest_changesets('README', nil) |
|
360 | 360 | assert_equal [ |
|
361 | 361 | '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf', |
|
362 | 362 | '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8', |
|
363 | 363 | '713f4944648826f558cf548222f813dabe7cbb04', |
|
364 | 364 | '61b685fbe55ab05b5ac68402d5720c1a6ac973d1', |
|
365 | 365 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
366 | 366 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
367 | 367 | ], changesets.collect(&:revision) |
|
368 | 368 | |
|
369 | 369 | # with path, revision and limit |
|
370 | 370 | changesets = @repository.latest_changesets('images', '899a15dba') |
|
371 | 371 | assert_equal [ |
|
372 | 372 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
373 | 373 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
374 | 374 | ], changesets.collect(&:revision) |
|
375 | 375 | |
|
376 | 376 | changesets = @repository.latest_changesets('images', '899a15dba', 1) |
|
377 | 377 | assert_equal [ |
|
378 | 378 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
379 | 379 | ], changesets.collect(&:revision) |
|
380 | 380 | |
|
381 | 381 | changesets = @repository.latest_changesets('README', '899a15dba') |
|
382 | 382 | assert_equal [ |
|
383 | 383 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
384 | 384 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
385 | 385 | ], changesets.collect(&:revision) |
|
386 | 386 | |
|
387 | 387 | changesets = @repository.latest_changesets('README', '899a15dba', 1) |
|
388 | 388 | assert_equal [ |
|
389 | 389 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
390 | 390 | ], changesets.collect(&:revision) |
|
391 | 391 | |
|
392 | 392 | # with path, tag and limit |
|
393 | 393 | changesets = @repository.latest_changesets('images', 'tag01.annotated') |
|
394 | 394 | assert_equal [ |
|
395 | 395 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
396 | 396 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
397 | 397 | ], changesets.collect(&:revision) |
|
398 | 398 | |
|
399 | 399 | changesets = @repository.latest_changesets('images', 'tag01.annotated', 1) |
|
400 | 400 | assert_equal [ |
|
401 | 401 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
402 | 402 | ], changesets.collect(&:revision) |
|
403 | 403 | |
|
404 | 404 | changesets = @repository.latest_changesets('README', 'tag01.annotated') |
|
405 | 405 | assert_equal [ |
|
406 | 406 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
407 | 407 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
408 | 408 | ], changesets.collect(&:revision) |
|
409 | 409 | |
|
410 | 410 | changesets = @repository.latest_changesets('README', 'tag01.annotated', 1) |
|
411 | 411 | assert_equal [ |
|
412 | 412 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
413 | 413 | ], changesets.collect(&:revision) |
|
414 | 414 | |
|
415 | 415 | # with path, branch and limit |
|
416 | 416 | changesets = @repository.latest_changesets('images', 'test_branch') |
|
417 | 417 | assert_equal [ |
|
418 | 418 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
419 | 419 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
420 | 420 | ], changesets.collect(&:revision) |
|
421 | 421 | |
|
422 | 422 | changesets = @repository.latest_changesets('images', 'test_branch', 1) |
|
423 | 423 | assert_equal [ |
|
424 | 424 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
425 | 425 | ], changesets.collect(&:revision) |
|
426 | 426 | |
|
427 | 427 | changesets = @repository.latest_changesets('README', 'test_branch') |
|
428 | 428 | assert_equal [ |
|
429 | 429 | '713f4944648826f558cf548222f813dabe7cbb04', |
|
430 | 430 | '61b685fbe55ab05b5ac68402d5720c1a6ac973d1', |
|
431 | 431 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
432 | 432 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
433 | 433 | ], changesets.collect(&:revision) |
|
434 | 434 | |
|
435 | 435 | changesets = @repository.latest_changesets('README', 'test_branch', 2) |
|
436 | 436 | assert_equal [ |
|
437 | 437 | '713f4944648826f558cf548222f813dabe7cbb04', |
|
438 | 438 | '61b685fbe55ab05b5ac68402d5720c1a6ac973d1', |
|
439 | 439 | ], changesets.collect(&:revision) |
|
440 | 440 | |
|
441 | 441 | if WINDOWS_PASS |
|
442 | 442 | puts WINDOWS_SKIP_STR |
|
443 | 443 | elsif JRUBY_SKIP |
|
444 | 444 | puts JRUBY_SKIP_STR |
|
445 | 445 | else |
|
446 | 446 | # latin-1 encoding path |
|
447 | 447 | changesets = @repository.latest_changesets( |
|
448 | 448 | "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89') |
|
449 | 449 | assert_equal [ |
|
450 | 450 | '64f1f3e89ad1cb57976ff0ad99a107012ba3481d', |
|
451 | 451 | '4fc55c43bf3d3dc2efb66145365ddc17639ce81e', |
|
452 | 452 | ], changesets.collect(&:revision) |
|
453 | 453 | |
|
454 | 454 | changesets = @repository.latest_changesets( |
|
455 | 455 | "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89', 1) |
|
456 | 456 | assert_equal [ |
|
457 | 457 | '64f1f3e89ad1cb57976ff0ad99a107012ba3481d', |
|
458 | 458 | ], changesets.collect(&:revision) |
|
459 | 459 | end |
|
460 | 460 | end |
|
461 | 461 | |
|
462 | 462 | def test_latest_changesets_latin_1_dir |
|
463 | 463 | if WINDOWS_PASS |
|
464 | 464 | puts WINDOWS_SKIP_STR |
|
465 | 465 | elsif JRUBY_SKIP |
|
466 | 466 | puts JRUBY_SKIP_STR |
|
467 | 467 | else |
|
468 | 468 | assert_equal 0, @repository.changesets.count |
|
469 | 469 | @repository.fetch_changesets |
|
470 | 470 | @project.reload |
|
471 | 471 | assert_equal NUM_REV, @repository.changesets.count |
|
472 | 472 | changesets = @repository.latest_changesets( |
|
473 | 473 | "latin-1-dir/test-#{@char_1}-subdir", '1ca7f5ed') |
|
474 | 474 | assert_equal [ |
|
475 | 475 | '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', |
|
476 | 476 | ], changesets.collect(&:revision) |
|
477 | 477 | end |
|
478 | 478 | end |
|
479 | 479 | |
|
480 | 480 | def test_find_changeset_by_name |
|
481 | 481 | assert_equal 0, @repository.changesets.count |
|
482 | 482 | @repository.fetch_changesets |
|
483 | 483 | @project.reload |
|
484 | 484 | assert_equal NUM_REV, @repository.changesets.count |
|
485 | 485 | ['7234cb2750b63f47bff735edc50a1c0a433c2518', '7234cb2750b'].each do |r| |
|
486 | 486 | assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
487 | 487 | @repository.find_changeset_by_name(r).revision |
|
488 | 488 | end |
|
489 | 489 | end |
|
490 | 490 | |
|
491 | 491 | def test_find_changeset_by_empty_name |
|
492 | 492 | assert_equal 0, @repository.changesets.count |
|
493 | 493 | @repository.fetch_changesets |
|
494 | 494 | @project.reload |
|
495 | 495 | assert_equal NUM_REV, @repository.changesets.count |
|
496 | 496 | ['', ' ', nil].each do |r| |
|
497 | 497 | assert_nil @repository.find_changeset_by_name(r) |
|
498 | 498 | end |
|
499 | 499 | end |
|
500 | 500 | |
|
501 | 501 | def test_identifier |
|
502 | 502 | assert_equal 0, @repository.changesets.count |
|
503 | 503 | @repository.fetch_changesets |
|
504 | 504 | @project.reload |
|
505 | 505 | assert_equal NUM_REV, @repository.changesets.count |
|
506 | 506 | c = @repository.changesets.find_by_revision( |
|
507 | 507 | '7234cb2750b63f47bff735edc50a1c0a433c2518') |
|
508 | 508 | assert_equal c.scmid, c.identifier |
|
509 | 509 | end |
|
510 | 510 | |
|
511 | 511 | def test_format_identifier |
|
512 | 512 | assert_equal 0, @repository.changesets.count |
|
513 | 513 | @repository.fetch_changesets |
|
514 | 514 | @project.reload |
|
515 | 515 | assert_equal NUM_REV, @repository.changesets.count |
|
516 | 516 | c = @repository.changesets.find_by_revision( |
|
517 | 517 | '7234cb2750b63f47bff735edc50a1c0a433c2518') |
|
518 | 518 | assert_equal '7234cb27', c.format_identifier |
|
519 | 519 | end |
|
520 | 520 | |
|
521 | 521 | def test_activities |
|
522 | 522 | c = Changeset.new(:repository => @repository, |
|
523 | 523 | :committed_on => Time.now, |
|
524 | 524 | :revision => 'abc7234cb2750b63f47bff735edc50a1c0a433c2', |
|
525 | 525 | :scmid => 'abc7234cb2750b63f47bff735edc50a1c0a433c2', |
|
526 | 526 | :comments => 'test') |
|
527 | 527 | assert c.event_title.include?('abc7234c:') |
|
528 | 528 | assert_equal 'abc7234cb2750b63f47bff735edc50a1c0a433c2', c.event_url[:rev] |
|
529 | 529 | end |
|
530 | 530 | |
|
531 | 531 | def test_log_utf8 |
|
532 | 532 | assert_equal 0, @repository.changesets.count |
|
533 | 533 | @repository.fetch_changesets |
|
534 | 534 | @project.reload |
|
535 | 535 | assert_equal NUM_REV, @repository.changesets.count |
|
536 | 536 | str_felix_hex = FELIX_HEX.dup |
|
537 | 537 | if str_felix_hex.respond_to?(:force_encoding) |
|
538 | 538 | str_felix_hex.force_encoding('UTF-8') |
|
539 | 539 | end |
|
540 | 540 | c = @repository.changesets.find_by_revision( |
|
541 | 541 | 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b') |
|
542 | 542 | assert_equal "#{str_felix_hex} <felix@fachschaften.org>", c.committer |
|
543 | 543 | end |
|
544 | 544 | |
|
545 | 545 | def test_previous |
|
546 | 546 | assert_equal 0, @repository.changesets.count |
|
547 | 547 | @repository.fetch_changesets |
|
548 | 548 | @project.reload |
|
549 | 549 | assert_equal NUM_REV, @repository.changesets.count |
|
550 | 550 | %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1| |
|
551 | 551 | changeset = @repository.find_changeset_by_name(r1) |
|
552 | 552 | %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2| |
|
553 | 553 | assert_equal @repository.find_changeset_by_name(r2), changeset.previous |
|
554 | 554 | end |
|
555 | 555 | end |
|
556 | 556 | end |
|
557 | 557 | |
|
558 | 558 | def test_previous_nil |
|
559 | 559 | assert_equal 0, @repository.changesets.count |
|
560 | 560 | @repository.fetch_changesets |
|
561 | 561 | @project.reload |
|
562 | 562 | assert_equal NUM_REV, @repository.changesets.count |
|
563 | 563 | %w|7234cb2750b63f47bff735edc50a1c0a433c2518 7234cb275|.each do |r1| |
|
564 | 564 | changeset = @repository.find_changeset_by_name(r1) |
|
565 | 565 | assert_nil changeset.previous |
|
566 | 566 | end |
|
567 | 567 | end |
|
568 | 568 | |
|
569 | 569 | def test_next |
|
570 | 570 | assert_equal 0, @repository.changesets.count |
|
571 | 571 | @repository.fetch_changesets |
|
572 | 572 | @project.reload |
|
573 | 573 | assert_equal NUM_REV, @repository.changesets.count |
|
574 | 574 | %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2| |
|
575 | 575 | changeset = @repository.find_changeset_by_name(r2) |
|
576 | 576 | %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1| |
|
577 | 577 | assert_equal @repository.find_changeset_by_name(r1), changeset.next |
|
578 | 578 | end |
|
579 | 579 | end |
|
580 | 580 | end |
|
581 | 581 | |
|
582 | 582 | def test_next_nil |
|
583 | 583 | assert_equal 0, @repository.changesets.count |
|
584 | 584 | @repository.fetch_changesets |
|
585 | 585 | @project.reload |
|
586 | 586 | assert_equal NUM_REV, @repository.changesets.count |
|
587 | 587 | %w|2a682156a3b6e77a8bf9cd4590e8db757f3c6c78 2a682156a3b6e77a|.each do |r1| |
|
588 | 588 | changeset = @repository.find_changeset_by_name(r1) |
|
589 | 589 | assert_nil changeset.next |
|
590 | 590 | end |
|
591 | 591 | end |
|
592 | 592 | else |
|
593 | 593 | puts "Git test repository NOT FOUND. Skipping unit tests !!!" |
|
594 | 594 | def test_fake; assert true end |
|
595 | 595 | end |
|
596 | 596 | end |
General Comments 0
You need to be logged in to leave comments.
Login now