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