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