##// END OF EJS Templates
Rails3: scm: git: fix error of test_fetch_changesets_invalid_rev at unit model test...
Toshi MARUYAMA -
r6950:63d55cea85bf
parent child
Show More
@@ -1,456 +1,457
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
26 NUM_REV = 21
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 33, @repository.changes.count
74 assert_equal 33, @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 4, @repository.extra_info["branches"].size
90 assert_equal 4, @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 assert_equal 33, @repository.changes.count
98 assert_equal 33, @repository.changes.count
99 extra_info_db = @repository.extra_info["branches"]
99 extra_info_db = @repository.extra_info["branches"]
100 assert_equal 4, extra_info_db.size
100 assert_equal 4, extra_info_db.size
101 assert_equal "1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127",
101 assert_equal "1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127",
102 extra_info_db["latin-1-path-encoding"]["last_scmid"]
102 extra_info_db["latin-1-path-encoding"]["last_scmid"]
103 assert_equal "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
103 assert_equal "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
104 extra_info_db["master"]["last_scmid"]
104 extra_info_db["master"]["last_scmid"]
105
105
106 del_revs = [
106 del_revs = [
107 "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
107 "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
108 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
108 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
109 "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
109 "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
110 "deff712f05a90d96edbd70facc47d944be5897e3",
110 "deff712f05a90d96edbd70facc47d944be5897e3",
111 "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
111 "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
112 "7e61ac704deecde634b51e59daa8110435dcb3da",
112 "7e61ac704deecde634b51e59daa8110435dcb3da",
113 ]
113 ]
114 @repository.changesets.each do |rev|
114 @repository.changesets.each do |rev|
115 rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
115 rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
116 end
116 end
117 @project.reload
117 @project.reload
118 cs1 = @repository.changesets
118 cs1 = @repository.changesets
119 assert_equal 15, cs1.count
119 assert_equal 15, cs1.count
120 h = @repository.extra_info.dup
120 h = @repository.extra_info.dup
121 h["branches"]["master"]["last_scmid"] =
121 h["branches"]["master"]["last_scmid"] =
122 "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8"
122 "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8"
123 @repository.merge_extra_info(h)
123 @repository.merge_extra_info(h)
124 @repository.save
124 @repository.save
125 @project.reload
125 @project.reload
126 extra_info_db_1 = @repository.extra_info["branches"]
126 extra_info_db_1 = @repository.extra_info["branches"]
127 assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8",
127 assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8",
128 extra_info_db_1["master"]["last_scmid"]
128 extra_info_db_1["master"]["last_scmid"]
129
129
130 @repository.fetch_changesets
130 @repository.fetch_changesets
131 @project.reload
131 @project.reload
132 assert_equal NUM_REV, @repository.changesets.count
132 assert_equal NUM_REV, @repository.changesets.count
133 end
133 end
134
134
135 def test_fetch_changesets_invalid_rev
135 def test_fetch_changesets_invalid_rev
136 assert_equal 0, @repository.changesets.count
136 @repository.fetch_changesets
137 @repository.fetch_changesets
137 @repository.reload
138 @project.reload
138 assert_equal 21, @repository.changesets.count
139 assert_equal NUM_REV, @repository.changesets.count
139 assert_equal 33, @repository.changes.count
140 extra_info_db = @repository.extra_info["branches"]
140 extra_info_db = @repository.extra_info["branches"]
141 assert_equal 4, extra_info_db.size
141 assert_equal 4, extra_info_db.size
142 assert_equal "1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127",
142 assert_equal "1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127",
143 extra_info_db["latin-1-path-encoding"]["last_scmid"]
143 extra_info_db["latin-1-path-encoding"]["last_scmid"]
144 assert_equal "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
144 assert_equal "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
145 extra_info_db["master"]["last_scmid"]
145 extra_info_db["master"]["last_scmid"]
146
146
147 del_revs = [
147 del_revs = [
148 "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
148 "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
149 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
149 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
150 "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
150 "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
151 "deff712f05a90d96edbd70facc47d944be5897e3",
151 "deff712f05a90d96edbd70facc47d944be5897e3",
152 "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
152 "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
153 "7e61ac704deecde634b51e59daa8110435dcb3da",
153 "7e61ac704deecde634b51e59daa8110435dcb3da",
154 ]
154 ]
155 @repository.changesets.each do |rev|
155 @repository.changesets.each do |rev|
156 rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
156 rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
157 end
157 end
158 @repository.reload
158 @project.reload
159 cs1 = @repository.changesets
159 cs1 = @repository.changesets
160 assert_equal 15, cs1.count
160 assert_equal 15, cs1.count
161 h = @repository.extra_info.dup
161 h = @repository.extra_info.dup
162 h["branches"]["master"]["last_scmid"] =
162 h["branches"]["master"]["last_scmid"] =
163 "abcd1234efgh"
163 "abcd1234efgh"
164 @repository.merge_extra_info(h)
164 @repository.merge_extra_info(h)
165 @repository.save
165 @repository.save
166 @repository.reload
166 @project.reload
167 extra_info_db_1 = @repository.extra_info["branches"]
167 extra_info_db_1 = @repository.extra_info["branches"]
168 assert_equal "abcd1234efgh",
168 assert_equal "abcd1234efgh",
169 extra_info_db_1["master"]["last_scmid"]
169 extra_info_db_1["master"]["last_scmid"]
170
170
171 @repository.fetch_changesets
171 @repository.fetch_changesets
172 @project.reload
172 assert_equal 15, @repository.changesets.count
173 assert_equal 15, @repository.changesets.count
173 end
174 end
174
175
175 def test_db_consistent_ordering_init
176 def test_db_consistent_ordering_init
176 assert_nil @repository.extra_info
177 assert_nil @repository.extra_info
177 @repository.fetch_changesets
178 @repository.fetch_changesets
178 @repository.reload
179 @repository.reload
179 assert_equal 1, @repository.extra_info["db_consistent"]["ordering"]
180 assert_equal 1, @repository.extra_info["db_consistent"]["ordering"]
180 end
181 end
181
182
182 def test_db_consistent_ordering_before_1_2
183 def test_db_consistent_ordering_before_1_2
183 assert_nil @repository.extra_info
184 assert_nil @repository.extra_info
184 @repository.fetch_changesets
185 @repository.fetch_changesets
185 @repository.reload
186 @repository.reload
186 assert_equal 21, @repository.changesets.count
187 assert_equal 21, @repository.changesets.count
187 assert_not_nil @repository.extra_info
188 assert_not_nil @repository.extra_info
188 @repository.write_attribute(:extra_info, nil)
189 @repository.write_attribute(:extra_info, nil)
189 @repository.save
190 @repository.save
190 assert_nil @repository.extra_info
191 assert_nil @repository.extra_info
191 assert_equal 21, @repository.changesets.count
192 assert_equal 21, @repository.changesets.count
192 @repository.fetch_changesets
193 @repository.fetch_changesets
193 @repository.reload
194 @repository.reload
194 assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
195 assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
195
196
196 del_revs = [
197 del_revs = [
197 "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
198 "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
198 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
199 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
199 "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
200 "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
200 "deff712f05a90d96edbd70facc47d944be5897e3",
201 "deff712f05a90d96edbd70facc47d944be5897e3",
201 "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
202 "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
202 "7e61ac704deecde634b51e59daa8110435dcb3da",
203 "7e61ac704deecde634b51e59daa8110435dcb3da",
203 ]
204 ]
204 @repository.changesets.each do |rev|
205 @repository.changesets.each do |rev|
205 rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
206 rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
206 end
207 end
207 @repository.reload
208 @repository.reload
208 cs1 = @repository.changesets
209 cs1 = @repository.changesets
209 assert_equal 15, cs1.count
210 assert_equal 15, cs1.count
210 assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
211 assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
211 h = @repository.extra_info.dup
212 h = @repository.extra_info.dup
212 h["branches"]["master"]["last_scmid"] =
213 h["branches"]["master"]["last_scmid"] =
213 "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8"
214 "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8"
214 @repository.merge_extra_info(h)
215 @repository.merge_extra_info(h)
215 @repository.save
216 @repository.save
216 @repository.reload
217 @repository.reload
217 extra_info_db_1 = @repository.extra_info["branches"]
218 extra_info_db_1 = @repository.extra_info["branches"]
218 assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8",
219 assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8",
219 extra_info_db_1["master"]["last_scmid"]
220 extra_info_db_1["master"]["last_scmid"]
220
221
221 @repository.fetch_changesets
222 @repository.fetch_changesets
222 assert_equal 21, @repository.changesets.count
223 assert_equal 21, @repository.changesets.count
223 assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
224 assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
224 end
225 end
225
226
226 def test_latest_changesets
227 def test_latest_changesets
227 @repository.fetch_changesets
228 @repository.fetch_changesets
228 @repository.reload
229 @repository.reload
229 # with limit
230 # with limit
230 changesets = @repository.latest_changesets('', nil, 2)
231 changesets = @repository.latest_changesets('', nil, 2)
231 assert_equal 2, changesets.size
232 assert_equal 2, changesets.size
232
233
233 # with path
234 # with path
234 changesets = @repository.latest_changesets('images', nil)
235 changesets = @repository.latest_changesets('images', nil)
235 assert_equal [
236 assert_equal [
236 'deff712f05a90d96edbd70facc47d944be5897e3',
237 'deff712f05a90d96edbd70facc47d944be5897e3',
237 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
238 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
238 '7234cb2750b63f47bff735edc50a1c0a433c2518',
239 '7234cb2750b63f47bff735edc50a1c0a433c2518',
239 ], changesets.collect(&:revision)
240 ], changesets.collect(&:revision)
240
241
241 changesets = @repository.latest_changesets('README', nil)
242 changesets = @repository.latest_changesets('README', nil)
242 assert_equal [
243 assert_equal [
243 '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf',
244 '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf',
244 '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8',
245 '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8',
245 '713f4944648826f558cf548222f813dabe7cbb04',
246 '713f4944648826f558cf548222f813dabe7cbb04',
246 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
247 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
247 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
248 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
248 '7234cb2750b63f47bff735edc50a1c0a433c2518',
249 '7234cb2750b63f47bff735edc50a1c0a433c2518',
249 ], changesets.collect(&:revision)
250 ], changesets.collect(&:revision)
250
251
251 # with path, revision and limit
252 # with path, revision and limit
252 changesets = @repository.latest_changesets('images', '899a15dba')
253 changesets = @repository.latest_changesets('images', '899a15dba')
253 assert_equal [
254 assert_equal [
254 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
255 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
255 '7234cb2750b63f47bff735edc50a1c0a433c2518',
256 '7234cb2750b63f47bff735edc50a1c0a433c2518',
256 ], changesets.collect(&:revision)
257 ], changesets.collect(&:revision)
257
258
258 changesets = @repository.latest_changesets('images', '899a15dba', 1)
259 changesets = @repository.latest_changesets('images', '899a15dba', 1)
259 assert_equal [
260 assert_equal [
260 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
261 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
261 ], changesets.collect(&:revision)
262 ], changesets.collect(&:revision)
262
263
263 changesets = @repository.latest_changesets('README', '899a15dba')
264 changesets = @repository.latest_changesets('README', '899a15dba')
264 assert_equal [
265 assert_equal [
265 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
266 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
266 '7234cb2750b63f47bff735edc50a1c0a433c2518',
267 '7234cb2750b63f47bff735edc50a1c0a433c2518',
267 ], changesets.collect(&:revision)
268 ], changesets.collect(&:revision)
268
269
269 changesets = @repository.latest_changesets('README', '899a15dba', 1)
270 changesets = @repository.latest_changesets('README', '899a15dba', 1)
270 assert_equal [
271 assert_equal [
271 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
272 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
272 ], changesets.collect(&:revision)
273 ], changesets.collect(&:revision)
273
274
274 # with path, tag and limit
275 # with path, tag and limit
275 changesets = @repository.latest_changesets('images', 'tag01.annotated')
276 changesets = @repository.latest_changesets('images', 'tag01.annotated')
276 assert_equal [
277 assert_equal [
277 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
278 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
278 '7234cb2750b63f47bff735edc50a1c0a433c2518',
279 '7234cb2750b63f47bff735edc50a1c0a433c2518',
279 ], changesets.collect(&:revision)
280 ], changesets.collect(&:revision)
280
281
281 changesets = @repository.latest_changesets('images', 'tag01.annotated', 1)
282 changesets = @repository.latest_changesets('images', 'tag01.annotated', 1)
282 assert_equal [
283 assert_equal [
283 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
284 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
284 ], changesets.collect(&:revision)
285 ], changesets.collect(&:revision)
285
286
286 changesets = @repository.latest_changesets('README', 'tag01.annotated')
287 changesets = @repository.latest_changesets('README', 'tag01.annotated')
287 assert_equal [
288 assert_equal [
288 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
289 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
289 '7234cb2750b63f47bff735edc50a1c0a433c2518',
290 '7234cb2750b63f47bff735edc50a1c0a433c2518',
290 ], changesets.collect(&:revision)
291 ], changesets.collect(&:revision)
291
292
292 changesets = @repository.latest_changesets('README', 'tag01.annotated', 1)
293 changesets = @repository.latest_changesets('README', 'tag01.annotated', 1)
293 assert_equal [
294 assert_equal [
294 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
295 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
295 ], changesets.collect(&:revision)
296 ], changesets.collect(&:revision)
296
297
297 # with path, branch and limit
298 # with path, branch and limit
298 changesets = @repository.latest_changesets('images', 'test_branch')
299 changesets = @repository.latest_changesets('images', 'test_branch')
299 assert_equal [
300 assert_equal [
300 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
301 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
301 '7234cb2750b63f47bff735edc50a1c0a433c2518',
302 '7234cb2750b63f47bff735edc50a1c0a433c2518',
302 ], changesets.collect(&:revision)
303 ], changesets.collect(&:revision)
303
304
304 changesets = @repository.latest_changesets('images', 'test_branch', 1)
305 changesets = @repository.latest_changesets('images', 'test_branch', 1)
305 assert_equal [
306 assert_equal [
306 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
307 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
307 ], changesets.collect(&:revision)
308 ], changesets.collect(&:revision)
308
309
309 changesets = @repository.latest_changesets('README', 'test_branch')
310 changesets = @repository.latest_changesets('README', 'test_branch')
310 assert_equal [
311 assert_equal [
311 '713f4944648826f558cf548222f813dabe7cbb04',
312 '713f4944648826f558cf548222f813dabe7cbb04',
312 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
313 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
313 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
314 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
314 '7234cb2750b63f47bff735edc50a1c0a433c2518',
315 '7234cb2750b63f47bff735edc50a1c0a433c2518',
315 ], changesets.collect(&:revision)
316 ], changesets.collect(&:revision)
316
317
317 changesets = @repository.latest_changesets('README', 'test_branch', 2)
318 changesets = @repository.latest_changesets('README', 'test_branch', 2)
318 assert_equal [
319 assert_equal [
319 '713f4944648826f558cf548222f813dabe7cbb04',
320 '713f4944648826f558cf548222f813dabe7cbb04',
320 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
321 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
321 ], changesets.collect(&:revision)
322 ], changesets.collect(&:revision)
322
323
323 if JRUBY_SKIP
324 if JRUBY_SKIP
324 puts JRUBY_SKIP_STR
325 puts JRUBY_SKIP_STR
325 else
326 else
326 # latin-1 encoding path
327 # latin-1 encoding path
327 changesets = @repository.latest_changesets(
328 changesets = @repository.latest_changesets(
328 "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89')
329 "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89')
329 assert_equal [
330 assert_equal [
330 '64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
331 '64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
331 '4fc55c43bf3d3dc2efb66145365ddc17639ce81e',
332 '4fc55c43bf3d3dc2efb66145365ddc17639ce81e',
332 ], changesets.collect(&:revision)
333 ], changesets.collect(&:revision)
333
334
334 changesets = @repository.latest_changesets(
335 changesets = @repository.latest_changesets(
335 "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89', 1)
336 "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89', 1)
336 assert_equal [
337 assert_equal [
337 '64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
338 '64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
338 ], changesets.collect(&:revision)
339 ], changesets.collect(&:revision)
339 end
340 end
340 end
341 end
341
342
342 def test_latest_changesets_latin_1_dir
343 def test_latest_changesets_latin_1_dir
343 if WINDOWS_PASS
344 if WINDOWS_PASS
344 #
345 #
345 elsif JRUBY_SKIP
346 elsif JRUBY_SKIP
346 puts JRUBY_SKIP_STR
347 puts JRUBY_SKIP_STR
347 else
348 else
348 @repository.fetch_changesets
349 @repository.fetch_changesets
349 @repository.reload
350 @repository.reload
350 changesets = @repository.latest_changesets(
351 changesets = @repository.latest_changesets(
351 "latin-1-dir/test-#{@char_1}-subdir", '1ca7f5ed')
352 "latin-1-dir/test-#{@char_1}-subdir", '1ca7f5ed')
352 assert_equal [
353 assert_equal [
353 '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127',
354 '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127',
354 ], changesets.collect(&:revision)
355 ], changesets.collect(&:revision)
355 end
356 end
356 end
357 end
357
358
358 def test_find_changeset_by_name
359 def test_find_changeset_by_name
359 @repository.fetch_changesets
360 @repository.fetch_changesets
360 @repository.reload
361 @repository.reload
361 ['7234cb2750b63f47bff735edc50a1c0a433c2518', '7234cb2750b'].each do |r|
362 ['7234cb2750b63f47bff735edc50a1c0a433c2518', '7234cb2750b'].each do |r|
362 assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518',
363 assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518',
363 @repository.find_changeset_by_name(r).revision
364 @repository.find_changeset_by_name(r).revision
364 end
365 end
365 end
366 end
366
367
367 def test_find_changeset_by_empty_name
368 def test_find_changeset_by_empty_name
368 @repository.fetch_changesets
369 @repository.fetch_changesets
369 @repository.reload
370 @repository.reload
370 ['', ' ', nil].each do |r|
371 ['', ' ', nil].each do |r|
371 assert_nil @repository.find_changeset_by_name(r)
372 assert_nil @repository.find_changeset_by_name(r)
372 end
373 end
373 end
374 end
374
375
375 def test_identifier
376 def test_identifier
376 @repository.fetch_changesets
377 @repository.fetch_changesets
377 @repository.reload
378 @repository.reload
378 c = @repository.changesets.find_by_revision(
379 c = @repository.changesets.find_by_revision(
379 '7234cb2750b63f47bff735edc50a1c0a433c2518')
380 '7234cb2750b63f47bff735edc50a1c0a433c2518')
380 assert_equal c.scmid, c.identifier
381 assert_equal c.scmid, c.identifier
381 end
382 end
382
383
383 def test_format_identifier
384 def test_format_identifier
384 @repository.fetch_changesets
385 @repository.fetch_changesets
385 @repository.reload
386 @repository.reload
386 c = @repository.changesets.find_by_revision(
387 c = @repository.changesets.find_by_revision(
387 '7234cb2750b63f47bff735edc50a1c0a433c2518')
388 '7234cb2750b63f47bff735edc50a1c0a433c2518')
388 assert_equal '7234cb27', c.format_identifier
389 assert_equal '7234cb27', c.format_identifier
389 end
390 end
390
391
391 def test_activities
392 def test_activities
392 c = Changeset.new(:repository => @repository,
393 c = Changeset.new(:repository => @repository,
393 :committed_on => Time.now,
394 :committed_on => Time.now,
394 :revision => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
395 :revision => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
395 :scmid => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
396 :scmid => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
396 :comments => 'test')
397 :comments => 'test')
397 assert c.event_title.include?('abc7234c:')
398 assert c.event_title.include?('abc7234c:')
398 assert_equal 'abc7234cb2750b63f47bff735edc50a1c0a433c2', c.event_url[:rev]
399 assert_equal 'abc7234cb2750b63f47bff735edc50a1c0a433c2', c.event_url[:rev]
399 end
400 end
400
401
401 def test_log_utf8
402 def test_log_utf8
402 @repository.fetch_changesets
403 @repository.fetch_changesets
403 @repository.reload
404 @repository.reload
404 str_felix_hex = FELIX_HEX.dup
405 str_felix_hex = FELIX_HEX.dup
405 if str_felix_hex.respond_to?(:force_encoding)
406 if str_felix_hex.respond_to?(:force_encoding)
406 str_felix_hex.force_encoding('UTF-8')
407 str_felix_hex.force_encoding('UTF-8')
407 end
408 end
408 c = @repository.changesets.find_by_revision(
409 c = @repository.changesets.find_by_revision(
409 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b')
410 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b')
410 assert_equal "#{str_felix_hex} <felix@fachschaften.org>", c.committer
411 assert_equal "#{str_felix_hex} <felix@fachschaften.org>", c.committer
411 end
412 end
412
413
413 def test_previous
414 def test_previous
414 @repository.fetch_changesets
415 @repository.fetch_changesets
415 @repository.reload
416 @repository.reload
416 %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1|
417 %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1|
417 changeset = @repository.find_changeset_by_name(r1)
418 changeset = @repository.find_changeset_by_name(r1)
418 %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2|
419 %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2|
419 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
420 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
420 end
421 end
421 end
422 end
422 end
423 end
423
424
424 def test_previous_nil
425 def test_previous_nil
425 @repository.fetch_changesets
426 @repository.fetch_changesets
426 @repository.reload
427 @repository.reload
427 %w|7234cb2750b63f47bff735edc50a1c0a433c2518 7234cb2|.each do |r1|
428 %w|7234cb2750b63f47bff735edc50a1c0a433c2518 7234cb2|.each do |r1|
428 changeset = @repository.find_changeset_by_name(r1)
429 changeset = @repository.find_changeset_by_name(r1)
429 assert_nil changeset.previous
430 assert_nil changeset.previous
430 end
431 end
431 end
432 end
432
433
433 def test_next
434 def test_next
434 @repository.fetch_changesets
435 @repository.fetch_changesets
435 @repository.reload
436 @repository.reload
436 %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2|
437 %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2|
437 changeset = @repository.find_changeset_by_name(r2)
438 changeset = @repository.find_changeset_by_name(r2)
438 %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1|
439 %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1|
439 assert_equal @repository.find_changeset_by_name(r1), changeset.next
440 assert_equal @repository.find_changeset_by_name(r1), changeset.next
440 end
441 end
441 end
442 end
442 end
443 end
443
444
444 def test_next_nil
445 def test_next_nil
445 @repository.fetch_changesets
446 @repository.fetch_changesets
446 @repository.reload
447 @repository.reload
447 %w|67e7792ce20ccae2e4bb73eed09bb397819c8834 67e7792ce20cca|.each do |r1|
448 %w|67e7792ce20ccae2e4bb73eed09bb397819c8834 67e7792ce20cca|.each do |r1|
448 changeset = @repository.find_changeset_by_name(r1)
449 changeset = @repository.find_changeset_by_name(r1)
449 assert_nil changeset.next
450 assert_nil changeset.next
450 end
451 end
451 end
452 end
452 else
453 else
453 puts "Git test repository NOT FOUND. Skipping unit tests !!!"
454 puts "Git test repository NOT FOUND. Skipping unit tests !!!"
454 def test_fake; assert true end
455 def test_fake; assert true end
455 end
456 end
456 end
457 end
General Comments 0
You need to be logged in to leave comments. Login now