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