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