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