@@ -1,538 +1,531 | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | 2 | |
|
3 | # This file includes UTF-8 "Felix Schäfer". | |
|
4 | # We need to consider Ruby 1.9 compatibility. | |
|
5 | ||
|
6 | 3 | require File.expand_path('../../../../../../test_helper', __FILE__) |
|
7 | 4 | begin |
|
8 | 5 | require 'mocha' |
|
9 | 6 | |
|
10 | 7 | class GitAdapterTest < ActiveSupport::TestCase |
|
11 | 8 | REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s |
|
12 | 9 | |
|
13 | FELIX_UTF8 = "Felix Schäfer" | |
|
14 | 10 | FELIX_HEX = "Felix Sch\xC3\xA4fer" |
|
15 | 11 | CHAR_1_HEX = "\xc3\x9c" |
|
16 | 12 | |
|
17 | 13 | ## Ruby uses ANSI api to fork a process on Windows. |
|
18 | 14 | ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem |
|
19 | 15 | ## and these are incompatible with ASCII. |
|
20 | 16 | # WINDOWS_PASS = Redmine::Platform.mswin? |
|
21 | 17 | WINDOWS_PASS = false |
|
22 | 18 | |
|
23 | 19 | ## Git, Mercurial and CVS path encodings are binary. |
|
24 | 20 | ## Subversion supports URL encoding for path. |
|
25 | 21 | ## Redmine Mercurial adapter and extension use URL encoding. |
|
26 | 22 | ## Git accepts only binary path in command line parameter. |
|
27 | 23 | ## So, there is no way to use binary command line parameter in JRuby. |
|
28 | 24 | JRUBY_SKIP = (RUBY_PLATFORM == 'java') |
|
29 | 25 | JRUBY_SKIP_STR = "TODO: This test fails in JRuby" |
|
30 | 26 | |
|
31 | 27 | if File.directory?(REPOSITORY_PATH) |
|
32 | 28 | def setup |
|
33 | 29 | adapter_class = Redmine::Scm::Adapters::GitAdapter |
|
34 | 30 | assert adapter_class |
|
35 | 31 | assert adapter_class.client_command |
|
36 | 32 | assert_equal true, adapter_class.client_available |
|
37 | 33 | assert_equal true, adapter_class.client_version_above?([1]) |
|
38 | 34 | assert_equal true, adapter_class.client_version_above?([1, 0]) |
|
39 | 35 | |
|
40 | 36 | @adapter = Redmine::Scm::Adapters::GitAdapter.new( |
|
41 | 37 | REPOSITORY_PATH, |
|
42 | 38 | nil, |
|
43 | 39 | nil, |
|
44 | 40 | nil, |
|
45 | 41 | 'ISO-8859-1' |
|
46 | 42 | ) |
|
47 | 43 | assert @adapter |
|
48 | 44 | @char_1 = CHAR_1_HEX.dup |
|
49 | 45 | if @char_1.respond_to?(:force_encoding) |
|
50 | 46 | @char_1.force_encoding('UTF-8') |
|
51 | 47 | end |
|
52 | 48 | end |
|
53 | 49 | |
|
54 | 50 | def test_scm_version |
|
55 | 51 | to_test = { "git version 1.7.3.4\n" => [1,7,3,4], |
|
56 | 52 | "1.6.1\n1.7\n1.8" => [1,6,1], |
|
57 | 53 | "1.6.2\r\n1.8.1\r\n1.9.1" => [1,6,2]} |
|
58 | 54 | to_test.each do |s, v| |
|
59 | 55 | test_scm_version_for(s, v) |
|
60 | 56 | end |
|
61 | 57 | end |
|
62 | 58 | |
|
63 | 59 | def test_branches |
|
64 | 60 | brs = [] |
|
65 | 61 | @adapter.branches.each do |b| |
|
66 | 62 | brs << b |
|
67 | 63 | end |
|
68 | 64 | assert_equal 6, brs.length |
|
69 | 65 | br_issue_8857 = brs[0] |
|
70 | 66 | assert_equal 'issue-8857', br_issue_8857.to_s |
|
71 | 67 | assert_equal '2a682156a3b6e77a8bf9cd4590e8db757f3c6c78', br_issue_8857.revision |
|
72 | 68 | assert_equal br_issue_8857.scmid, br_issue_8857.revision |
|
73 | 69 | assert_equal false, br_issue_8857.is_default |
|
74 | 70 | br_latin_1_path = brs[1] |
|
75 | 71 | assert_equal 'latin-1-path-encoding', br_latin_1_path.to_s |
|
76 | 72 | assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', br_latin_1_path.revision |
|
77 | 73 | assert_equal br_latin_1_path.scmid, br_latin_1_path.revision |
|
78 | 74 | assert_equal false, br_latin_1_path.is_default |
|
79 | 75 | br_master = brs[2] |
|
80 | 76 | assert_equal 'master', br_master.to_s |
|
81 | 77 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', br_master.revision |
|
82 | 78 | assert_equal br_master.scmid, br_master.revision |
|
83 | 79 | assert_equal false, br_master.is_default |
|
84 | 80 | br_master_20120212 = brs[3] |
|
85 | 81 | assert_equal 'master-20120212', br_master_20120212.to_s |
|
86 | 82 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', br_master_20120212.revision |
|
87 | 83 | assert_equal br_master_20120212.scmid, br_master_20120212.revision |
|
88 | 84 | assert_equal true, br_master_20120212.is_default |
|
89 | 85 | br_latin_1 = brs[-2] |
|
90 | 86 | assert_equal 'test-latin-1', br_latin_1.to_s |
|
91 | 87 | assert_equal '67e7792ce20ccae2e4bb73eed09bb397819c8834', br_latin_1.revision |
|
92 | 88 | assert_equal br_latin_1.scmid, br_latin_1.revision |
|
93 | 89 | assert_equal false, br_latin_1.is_default |
|
94 | 90 | br_test = brs[-1] |
|
95 | 91 | assert_equal 'test_branch', br_test.to_s |
|
96 | 92 | assert_equal 'fba357b886984ee71185ad2065e65fc0417d9b92', br_test.revision |
|
97 | 93 | assert_equal br_test.scmid, br_test.revision |
|
98 | 94 | assert_equal false, br_test.is_default |
|
99 | 95 | end |
|
100 | 96 | |
|
101 | 97 | def test_default_branch |
|
102 | 98 | assert_equal 'master-20120212', @adapter.default_branch |
|
103 | 99 | end |
|
104 | 100 | |
|
105 | 101 | def test_tags |
|
106 | 102 | assert_equal [ |
|
107 | 103 | "tag00.lightweight", |
|
108 | 104 | "tag01.annotated", |
|
109 | 105 | ], @adapter.tags |
|
110 | 106 | end |
|
111 | 107 | |
|
112 | 108 | def test_revisions_master_all |
|
113 | 109 | revs1 = [] |
|
114 | 110 | @adapter.revisions('', nil, "master",{}) do |rev| |
|
115 | 111 | revs1 << rev |
|
116 | 112 | end |
|
117 | 113 | assert_equal 15, revs1.length |
|
118 | 114 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[ 0].identifier |
|
119 | 115 | assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs1[-1].identifier |
|
120 | 116 | |
|
121 | 117 | revs2 = [] |
|
122 | 118 | @adapter.revisions('', nil, "master", |
|
123 | 119 | {:reverse => true}) do |rev| |
|
124 | 120 | revs2 << rev |
|
125 | 121 | end |
|
126 | 122 | assert_equal 15, revs2.length |
|
127 | 123 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs2[-1].identifier |
|
128 | 124 | assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs2[ 0].identifier |
|
129 | 125 | end |
|
130 | 126 | |
|
131 | 127 | def test_revisions_master_merged_rev |
|
132 | 128 | revs1 = [] |
|
133 | 129 | @adapter.revisions('', |
|
134 | 130 | "713f4944648826f558cf548222f813dabe7cbb04", |
|
135 | 131 | "master", |
|
136 | 132 | {:reverse => true}) do |rev| |
|
137 | 133 | revs1 << rev |
|
138 | 134 | end |
|
139 | 135 | assert_equal 8, revs1.length |
|
140 | 136 | assert_equal 'fba357b886984ee71185ad2065e65fc0417d9b92', revs1[ 0].identifier |
|
141 | 137 | assert_equal '7e61ac704deecde634b51e59daa8110435dcb3da', revs1[ 1].identifier |
|
142 | 138 | # 4a07fe31b is not a child of 713f49446 |
|
143 | 139 | assert_equal '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8', revs1[ 2].identifier |
|
144 | 140 | # Merged revision |
|
145 | 141 | assert_equal '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf', revs1[ 3].identifier |
|
146 | 142 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[-1].identifier |
|
147 | 143 | |
|
148 | 144 | revs2 = [] |
|
149 | 145 | @adapter.revisions('', |
|
150 | 146 | "fba357b886984ee71185ad2065e65fc0417d9b92", |
|
151 | 147 | "master", |
|
152 | 148 | {:reverse => true}) do |rev| |
|
153 | 149 | revs2 << rev |
|
154 | 150 | end |
|
155 | 151 | assert_equal 7, revs2.length |
|
156 | 152 | assert_equal '7e61ac704deecde634b51e59daa8110435dcb3da', revs2[ 0].identifier |
|
157 | 153 | # 4a07fe31b is not a child of fba357b8869 |
|
158 | 154 | assert_equal '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8', revs2[ 1].identifier |
|
159 | 155 | # Merged revision |
|
160 | 156 | assert_equal '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf', revs2[ 2].identifier |
|
161 | 157 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs2[-1].identifier |
|
162 | 158 | end |
|
163 | 159 | |
|
164 | 160 | def test_revisions_branch_latin_1_path_encoding_all |
|
165 | 161 | revs1 = [] |
|
166 | 162 | @adapter.revisions('', nil, "latin-1-path-encoding",{}) do |rev| |
|
167 | 163 | revs1 << rev |
|
168 | 164 | end |
|
169 | 165 | assert_equal 8, revs1.length |
|
170 | 166 | assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs1[ 0].identifier |
|
171 | 167 | assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs1[-1].identifier |
|
172 | 168 | |
|
173 | 169 | revs2 = [] |
|
174 | 170 | @adapter.revisions('', nil, "latin-1-path-encoding", |
|
175 | 171 | {:reverse => true}) do |rev| |
|
176 | 172 | revs2 << rev |
|
177 | 173 | end |
|
178 | 174 | assert_equal 8, revs2.length |
|
179 | 175 | assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs2[-1].identifier |
|
180 | 176 | assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs2[ 0].identifier |
|
181 | 177 | end |
|
182 | 178 | |
|
183 | 179 | def test_revisions_branch_latin_1_path_encoding_with_rev |
|
184 | 180 | revs1 = [] |
|
185 | 181 | @adapter.revisions('', |
|
186 | 182 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
187 | 183 | "latin-1-path-encoding", |
|
188 | 184 | {:reverse => true}) do |rev| |
|
189 | 185 | revs1 << rev |
|
190 | 186 | end |
|
191 | 187 | assert_equal 7, revs1.length |
|
192 | 188 | assert_equal '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', revs1[ 0].identifier |
|
193 | 189 | assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs1[-1].identifier |
|
194 | 190 | |
|
195 | 191 | revs2 = [] |
|
196 | 192 | @adapter.revisions('', |
|
197 | 193 | '57ca437c0acbbcb749821fdf3726a1367056d364', |
|
198 | 194 | "latin-1-path-encoding", |
|
199 | 195 | {:reverse => true}) do |rev| |
|
200 | 196 | revs2 << rev |
|
201 | 197 | end |
|
202 | 198 | assert_equal 3, revs2.length |
|
203 | 199 | assert_equal '4fc55c43bf3d3dc2efb66145365ddc17639ce81e', revs2[ 0].identifier |
|
204 | 200 | assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs2[-1].identifier |
|
205 | 201 | end |
|
206 | 202 | |
|
207 | 203 | def test_revisions_invalid_rev |
|
208 | 204 | assert_equal [], @adapter.revisions('', '1234abcd', "master") |
|
209 | 205 | assert_raise Redmine::Scm::Adapters::CommandFailed do |
|
210 | 206 | revs1 = [] |
|
211 | 207 | @adapter.revisions('', |
|
212 | 208 | '1234abcd', |
|
213 | 209 | "master", |
|
214 | 210 | {:reverse => true}) do |rev| |
|
215 | 211 | revs1 << rev |
|
216 | 212 | end |
|
217 | 213 | end |
|
218 | 214 | end |
|
219 | 215 | |
|
220 | 216 | def test_revisions_includes_master_two_revs |
|
221 | 217 | revs1 = [] |
|
222 | 218 | @adapter.revisions('', nil, nil, |
|
223 | 219 | {:reverse => true, |
|
224 | 220 | :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'], |
|
225 | 221 | :excludes => ['4f26664364207fa8b1af9f8722647ab2d4ac5d43']}) do |rev| |
|
226 | 222 | revs1 << rev |
|
227 | 223 | end |
|
228 | 224 | assert_equal 2, revs1.length |
|
229 | 225 | assert_equal 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b', revs1[ 0].identifier |
|
230 | 226 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[-1].identifier |
|
231 | 227 | end |
|
232 | 228 | |
|
233 | 229 | def test_revisions_includes_master_two_revs_from_origin |
|
234 | 230 | revs1 = [] |
|
235 | 231 | @adapter.revisions('', nil, nil, |
|
236 | 232 | {:reverse => true, |
|
237 | 233 | :includes => ['899a15dba03a3b350b89c3f537e4bbe02a03cdc9'], |
|
238 | 234 | :excludes => []}) do |rev| |
|
239 | 235 | revs1 << rev |
|
240 | 236 | end |
|
241 | 237 | assert_equal 2, revs1.length |
|
242 | 238 | assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs1[ 0].identifier |
|
243 | 239 | assert_equal '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', revs1[ 1].identifier |
|
244 | 240 | end |
|
245 | 241 | |
|
246 | 242 | def test_revisions_includes_merged_revs |
|
247 | 243 | revs1 = [] |
|
248 | 244 | @adapter.revisions('', nil, nil, |
|
249 | 245 | {:reverse => true, |
|
250 | 246 | :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'], |
|
251 | 247 | :excludes => ['fba357b886984ee71185ad2065e65fc0417d9b92']}) do |rev| |
|
252 | 248 | revs1 << rev |
|
253 | 249 | end |
|
254 | 250 | assert_equal 7, revs1.length |
|
255 | 251 | assert_equal '7e61ac704deecde634b51e59daa8110435dcb3da', revs1[ 0].identifier |
|
256 | 252 | assert_equal '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8', revs1[ 1].identifier |
|
257 | 253 | assert_equal '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf', revs1[ 2].identifier |
|
258 | 254 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[-1].identifier |
|
259 | 255 | end |
|
260 | 256 | |
|
261 | 257 | def test_revisions_includes_two_heads |
|
262 | 258 | revs1 = [] |
|
263 | 259 | @adapter.revisions('', nil, nil, |
|
264 | 260 | {:reverse => true, |
|
265 | 261 | :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', |
|
266 | 262 | '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127'], |
|
267 | 263 | :excludes => ['4f26664364207fa8b1af9f8722647ab2d4ac5d43', |
|
268 | 264 | '4fc55c43bf3d3dc2efb66145365ddc17639ce81e']}) do |rev| |
|
269 | 265 | revs1 << rev |
|
270 | 266 | end |
|
271 | 267 | assert_equal 4, revs1.length |
|
272 | 268 | assert_equal 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b', revs1[ 0].identifier |
|
273 | 269 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[ 1].identifier |
|
274 | 270 | assert_equal '64f1f3e89ad1cb57976ff0ad99a107012ba3481d', revs1[-2].identifier |
|
275 | 271 | assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs1[-1].identifier |
|
276 | 272 | end |
|
277 | 273 | |
|
278 | 274 | def test_revisions_disjointed_histories_revisions |
|
279 | 275 | revs1 = [] |
|
280 | 276 | @adapter.revisions('', nil, nil, |
|
281 | 277 | {:reverse => true, |
|
282 | 278 | :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', |
|
283 | 279 | '92397af84d22f27389c822848ecd5b463c181583'], |
|
284 | 280 | :excludes => ['95488a44bc25f7d1f97d775a31359539ff333a63', |
|
285 | 281 | '4f26664364207fa8b1af9f8722647ab2d4ac5d43'] }) do |rev| |
|
286 | 282 | revs1 << rev |
|
287 | 283 | end |
|
288 | 284 | assert_equal 4, revs1.length |
|
289 | 285 | assert_equal 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b', revs1[ 0].identifier |
|
290 | 286 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[ 1].identifier |
|
291 | 287 | assert_equal 'bc201c95999c4f10d018b0aa03b541cd6a2ff0ee', revs1[-2].identifier |
|
292 | 288 | assert_equal '92397af84d22f27389c822848ecd5b463c181583', revs1[-1].identifier |
|
293 | 289 | end |
|
294 | 290 | |
|
295 | 291 | def test_revisions_invalid_rev_excludes |
|
296 | 292 | assert_equal [], |
|
297 | 293 | @adapter.revisions('', nil, nil, |
|
298 | 294 | {:reverse => true, |
|
299 | 295 | :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'], |
|
300 | 296 | :excludes => ['0123abcd4567']}) |
|
301 | 297 | assert_raise Redmine::Scm::Adapters::CommandFailed do |
|
302 | 298 | revs1 = [] |
|
303 | 299 | @adapter.revisions('', nil, nil, |
|
304 | 300 | {:reverse => true, |
|
305 | 301 | :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'], |
|
306 | 302 | :excludes => ['0123abcd4567']}) do |rev| |
|
307 | 303 | revs1 << rev |
|
308 | 304 | end |
|
309 | 305 | end |
|
310 | 306 | end |
|
311 | 307 | |
|
312 | 308 | def test_getting_revisions_with_spaces_in_filename |
|
313 | 309 | assert_equal 1, @adapter.revisions("filemane with spaces.txt", |
|
314 | 310 | nil, "master").length |
|
315 | 311 | end |
|
316 | 312 | |
|
317 | 313 | def test_parents |
|
318 | 314 | revs1 = [] |
|
319 | 315 | @adapter.revisions('', |
|
320 | 316 | nil, |
|
321 | 317 | "master", |
|
322 | 318 | {:reverse => true}) do |rev| |
|
323 | 319 | revs1 << rev |
|
324 | 320 | end |
|
325 | 321 | assert_equal 15, revs1.length |
|
326 | 322 | assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", |
|
327 | 323 | revs1[0].identifier |
|
328 | 324 | assert_equal nil, revs1[0].parents |
|
329 | 325 | assert_equal "899a15dba03a3b350b89c3f537e4bbe02a03cdc9", |
|
330 | 326 | revs1[1].identifier |
|
331 | 327 | assert_equal 1, revs1[1].parents.length |
|
332 | 328 | assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", |
|
333 | 329 | revs1[1].parents[0] |
|
334 | 330 | assert_equal "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf", |
|
335 | 331 | revs1[10].identifier |
|
336 | 332 | assert_equal 2, revs1[10].parents.length |
|
337 | 333 | assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", |
|
338 | 334 | revs1[10].parents[0] |
|
339 | 335 | assert_equal "7e61ac704deecde634b51e59daa8110435dcb3da", |
|
340 | 336 | revs1[10].parents[1] |
|
341 | 337 | end |
|
342 | 338 | |
|
343 | 339 | def test_getting_revisions_with_leading_and_trailing_spaces_in_filename |
|
344 | 340 | assert_equal " filename with a leading space.txt ", |
|
345 | 341 | @adapter.revisions(" filename with a leading space.txt ", |
|
346 | 342 | nil, "master")[0].paths[0][:path] |
|
347 | 343 | end |
|
348 | 344 | |
|
349 | 345 | def test_getting_entries_with_leading_and_trailing_spaces_in_filename |
|
350 | 346 | assert_equal " filename with a leading space.txt ", |
|
351 | 347 | @adapter.entries('', |
|
352 | 348 | '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c')[3].name |
|
353 | 349 | end |
|
354 | 350 | |
|
355 | 351 | def test_annotate |
|
356 | 352 | annotate = @adapter.annotate('sources/watchers_controller.rb') |
|
357 | 353 | assert_kind_of Redmine::Scm::Adapters::Annotate, annotate |
|
358 | 354 | assert_equal 41, annotate.lines.size |
|
359 | 355 | assert_equal "# This program is free software; you can redistribute it and/or", |
|
360 | 356 | annotate.lines[4].strip |
|
361 | 357 | assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", |
|
362 | 358 | annotate.revisions[4].identifier |
|
363 | 359 | assert_equal "jsmith", annotate.revisions[4].author |
|
364 | 360 | end |
|
365 | 361 | |
|
366 | 362 | def test_annotate_moved_file |
|
367 | 363 | annotate = @adapter.annotate('renamed_test.txt') |
|
368 | 364 | assert_kind_of Redmine::Scm::Adapters::Annotate, annotate |
|
369 | 365 | assert_equal 2, annotate.lines.size |
|
370 | 366 | end |
|
371 | 367 | |
|
372 | 368 | def test_last_rev |
|
373 | 369 | last_rev = @adapter.lastrev("README", |
|
374 | 370 | "4f26664364207fa8b1af9f8722647ab2d4ac5d43") |
|
375 | 371 | assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.scmid |
|
376 | 372 | assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.identifier |
|
377 | 373 | assert_equal "Adam Soltys <asoltys@gmail.com>", last_rev.author |
|
378 | 374 | assert_equal "2009-06-24 05:27:38".to_time, last_rev.time |
|
379 | 375 | end |
|
380 | 376 | |
|
381 | 377 | def test_last_rev_with_spaces_in_filename |
|
382 | 378 | last_rev = @adapter.lastrev("filemane with spaces.txt", |
|
383 | 379 | "ed5bb786bbda2dee66a2d50faf51429dbc043a7b") |
|
384 | str_felix_utf8 = FELIX_UTF8.dup | |
|
385 | 380 | str_felix_hex = FELIX_HEX.dup |
|
386 | 381 | last_rev_author = last_rev.author |
|
387 | 382 | if last_rev_author.respond_to?(:force_encoding) |
|
388 | 383 | last_rev_author.force_encoding('UTF-8') |
|
389 | 384 | end |
|
390 | 385 | assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.scmid |
|
391 | 386 | assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.identifier |
|
392 | assert_equal "#{str_felix_utf8} <felix@fachschaften.org>", | |
|
393 | last_rev.author | |
|
394 | 387 | assert_equal "#{str_felix_hex} <felix@fachschaften.org>", |
|
395 | 388 | last_rev.author |
|
396 | 389 | assert_equal "2010-09-18 19:59:46".to_time, last_rev.time |
|
397 | 390 | end |
|
398 | 391 | |
|
399 | 392 | def test_latin_1_path |
|
400 | 393 | if WINDOWS_PASS |
|
401 | 394 | # |
|
402 | 395 | elsif JRUBY_SKIP |
|
403 | 396 | puts JRUBY_SKIP_STR |
|
404 | 397 | else |
|
405 | 398 | p2 = "latin-1-dir/test-#{@char_1}-2.txt" |
|
406 | 399 | ['4fc55c43bf3d3dc2efb66145365ddc17639ce81e', '4fc55c43bf3'].each do |r1| |
|
407 | 400 | assert @adapter.diff(p2, r1) |
|
408 | 401 | assert @adapter.cat(p2, r1) |
|
409 | 402 | assert_equal 1, @adapter.annotate(p2, r1).lines.length |
|
410 | 403 | ['64f1f3e89ad1cb57976ff0ad99a107012ba3481d', '64f1f3e89ad1cb5797'].each do |r2| |
|
411 | 404 | assert @adapter.diff(p2, r1, r2) |
|
412 | 405 | end |
|
413 | 406 | end |
|
414 | 407 | end |
|
415 | 408 | end |
|
416 | 409 | |
|
417 | 410 | def test_entries_tag |
|
418 | 411 | entries1 = @adapter.entries(nil, 'tag01.annotated', |
|
419 | 412 | options = {:report_last_commit => true}) |
|
420 | 413 | assert entries1 |
|
421 | 414 | assert_equal 3, entries1.size |
|
422 | 415 | assert_equal 'sources', entries1[1].name |
|
423 | 416 | assert_equal 'sources', entries1[1].path |
|
424 | 417 | assert_equal 'dir', entries1[1].kind |
|
425 | 418 | readme = entries1[2] |
|
426 | 419 | assert_equal 'README', readme.name |
|
427 | 420 | assert_equal 'README', readme.path |
|
428 | 421 | assert_equal 'file', readme.kind |
|
429 | 422 | assert_equal 27, readme.size |
|
430 | 423 | assert_equal '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', readme.lastrev.identifier |
|
431 | 424 | assert_equal Time.gm(2007, 12, 14, 9, 24, 1), readme.lastrev.time |
|
432 | 425 | end |
|
433 | 426 | |
|
434 | 427 | def test_entries_branch |
|
435 | 428 | entries1 = @adapter.entries(nil, 'test_branch', |
|
436 | 429 | options = {:report_last_commit => true}) |
|
437 | 430 | assert entries1 |
|
438 | 431 | assert_equal 4, entries1.size |
|
439 | 432 | assert_equal 'sources', entries1[1].name |
|
440 | 433 | assert_equal 'sources', entries1[1].path |
|
441 | 434 | assert_equal 'dir', entries1[1].kind |
|
442 | 435 | readme = entries1[2] |
|
443 | 436 | assert_equal 'README', readme.name |
|
444 | 437 | assert_equal 'README', readme.path |
|
445 | 438 | assert_equal 'file', readme.kind |
|
446 | 439 | assert_equal 159, readme.size |
|
447 | 440 | assert_equal '713f4944648826f558cf548222f813dabe7cbb04', readme.lastrev.identifier |
|
448 | 441 | assert_equal Time.gm(2009, 6, 19, 4, 37, 23), readme.lastrev.time |
|
449 | 442 | end |
|
450 | 443 | |
|
451 | 444 | def test_entries_latin_1_files |
|
452 | 445 | entries1 = @adapter.entries('latin-1-dir', '64f1f3e8') |
|
453 | 446 | assert entries1 |
|
454 | 447 | assert_equal 3, entries1.size |
|
455 | 448 | f1 = entries1[1] |
|
456 | 449 | assert_equal "test-#{@char_1}-2.txt", f1.name |
|
457 | 450 | assert_equal "latin-1-dir/test-#{@char_1}-2.txt", f1.path |
|
458 | 451 | assert_equal 'file', f1.kind |
|
459 | 452 | end |
|
460 | 453 | |
|
461 | 454 | def test_entries_latin_1_dir |
|
462 | 455 | if WINDOWS_PASS |
|
463 | 456 | # |
|
464 | 457 | elsif JRUBY_SKIP |
|
465 | 458 | puts JRUBY_SKIP_STR |
|
466 | 459 | else |
|
467 | 460 | entries1 = @adapter.entries("latin-1-dir/test-#{@char_1}-subdir", |
|
468 | 461 | '1ca7f5ed') |
|
469 | 462 | assert entries1 |
|
470 | 463 | assert_equal 3, entries1.size |
|
471 | 464 | f1 = entries1[1] |
|
472 | 465 | assert_equal "test-#{@char_1}-2.txt", f1.name |
|
473 | 466 | assert_equal "latin-1-dir/test-#{@char_1}-subdir/test-#{@char_1}-2.txt", f1.path |
|
474 | 467 | assert_equal 'file', f1.kind |
|
475 | 468 | end |
|
476 | 469 | end |
|
477 | 470 | |
|
478 | 471 | def test_path_encoding_default_utf8 |
|
479 | 472 | adpt1 = Redmine::Scm::Adapters::GitAdapter.new( |
|
480 | 473 | REPOSITORY_PATH |
|
481 | 474 | ) |
|
482 | 475 | assert_equal "UTF-8", adpt1.path_encoding |
|
483 | 476 | adpt2 = Redmine::Scm::Adapters::GitAdapter.new( |
|
484 | 477 | REPOSITORY_PATH, |
|
485 | 478 | nil, |
|
486 | 479 | nil, |
|
487 | 480 | nil, |
|
488 | 481 | "" |
|
489 | 482 | ) |
|
490 | 483 | assert_equal "UTF-8", adpt2.path_encoding |
|
491 | 484 | end |
|
492 | 485 | |
|
493 | 486 | def test_cat_path_invalid |
|
494 | 487 | assert_nil @adapter.cat('invalid') |
|
495 | 488 | end |
|
496 | 489 | |
|
497 | 490 | def test_cat_revision_invalid |
|
498 | 491 | assert @adapter.cat('README') |
|
499 | 492 | assert_nil @adapter.cat('README', 'abcd1234efgh') |
|
500 | 493 | end |
|
501 | 494 | |
|
502 | 495 | def test_diff_path_invalid |
|
503 | 496 | assert_equal [], @adapter.diff('invalid', '713f4944648826f5') |
|
504 | 497 | end |
|
505 | 498 | |
|
506 | 499 | def test_diff_revision_invalid |
|
507 | 500 | assert_nil @adapter.diff(nil, 'abcd1234efgh') |
|
508 | 501 | assert_nil @adapter.diff(nil, '713f4944648826f5', 'abcd1234efgh') |
|
509 | 502 | assert_nil @adapter.diff(nil, 'abcd1234efgh', '713f4944648826f5') |
|
510 | 503 | end |
|
511 | 504 | |
|
512 | 505 | def test_annotate_path_invalid |
|
513 | 506 | assert_nil @adapter.annotate('invalid') |
|
514 | 507 | end |
|
515 | 508 | |
|
516 | 509 | def test_annotate_revision_invalid |
|
517 | 510 | assert @adapter.annotate('README') |
|
518 | 511 | assert_nil @adapter.annotate('README', 'abcd1234efgh') |
|
519 | 512 | end |
|
520 | 513 | |
|
521 | 514 | private |
|
522 | 515 | |
|
523 | 516 | def test_scm_version_for(scm_command_version, version) |
|
524 | 517 | @adapter.class.expects(:scm_version_from_command_line).returns(scm_command_version) |
|
525 | 518 | assert_equal version, @adapter.class.scm_command_version |
|
526 | 519 | end |
|
527 | 520 | |
|
528 | 521 | else |
|
529 | 522 | puts "Git test repository NOT FOUND. Skipping unit tests !!!" |
|
530 | 523 | def test_fake; assert true end |
|
531 | 524 | end |
|
532 | 525 | end |
|
533 | 526 | |
|
534 | 527 | rescue LoadError |
|
535 | 528 | class GitMochaFake < ActiveSupport::TestCase |
|
536 | 529 | def test_fake; assert(false, "Requires mocha to run those tests") end |
|
537 | 530 | end |
|
538 | 531 | end |
General Comments 0
You need to be logged in to leave comments.
Login now