You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

repository_git_test.rb 23KB

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