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