##// END OF EJS Templates
scm: git: backout r8839 (#8857)...
Toshi MARUYAMA -
r9022:f0987e4b8f01
parent child
Show More
@@ -1,232 +1,221
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 3 # Copyright (C) 2007 Patrick Aljord patcito@ŋmail.com
4 4 #
5 5 # This program is free software; you can redistribute it and/or
6 6 # modify it under the terms of the GNU General Public License
7 7 # as published by the Free Software Foundation; either version 2
8 8 # of the License, or (at your option) any later version.
9 9 #
10 10 # This program is distributed in the hope that it will be useful,
11 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 # GNU General Public License for more details.
14 14 #
15 15 # You should have received a copy of the GNU General Public License
16 16 # along with this program; if not, write to the Free Software
17 17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 18
19 19 require 'redmine/scm/adapters/git_adapter'
20 20
21 21 class Repository::Git < Repository
22 22 attr_protected :root_url
23 23 validates_presence_of :url
24 24
25 25 def self.human_attribute_name(attribute_key_name, *args)
26 26 attr_name = attribute_key_name.to_s
27 27 if attr_name == "url"
28 28 attr_name = "path_to_repository"
29 29 end
30 30 super(attr_name, *args)
31 31 end
32 32
33 33 def self.scm_adapter_class
34 34 Redmine::Scm::Adapters::GitAdapter
35 35 end
36 36
37 37 def self.scm_name
38 38 'Git'
39 39 end
40 40
41 41 def report_last_commit
42 42 extra_report_last_commit
43 43 end
44 44
45 45 def extra_report_last_commit
46 46 return false if extra_info.nil?
47 47 v = extra_info["extra_report_last_commit"]
48 48 return false if v.nil?
49 49 v.to_s != '0'
50 50 end
51 51
52 52 def supports_directory_revisions?
53 53 true
54 54 end
55 55
56 56 def supports_revision_graph?
57 57 true
58 58 end
59 59
60 60 def repo_log_encoding
61 61 'UTF-8'
62 62 end
63 63
64 64 # Returns the identifier for the given git changeset
65 65 def self.changeset_identifier(changeset)
66 66 changeset.scmid
67 67 end
68 68
69 69 # Returns the readable identifier for the given git changeset
70 70 def self.format_changeset_identifier(changeset)
71 71 changeset.revision[0, 8]
72 72 end
73 73
74 74 def branches
75 75 scm.branches
76 76 end
77 77
78 78 def tags
79 79 scm.tags
80 80 end
81 81
82 82 def default_branch
83 83 scm.default_branch
84 84 rescue Exception => e
85 85 logger.error "git: error during get default branch: #{e.message}"
86 86 nil
87 87 end
88 88
89 89 def find_changeset_by_name(name)
90 90 return nil if name.nil? || name.empty?
91 91 e = changesets.find(:first, :conditions => ['revision = ?', name.to_s])
92 92 return e if e
93 93 changesets.find(:first, :conditions => ['scmid LIKE ?', "#{name}%"])
94 94 end
95 95
96 96 def entries(path=nil, identifier=nil)
97 97 scm.entries(path,
98 98 identifier,
99 99 options = {:report_last_commit => extra_report_last_commit})
100 100 end
101 101
102 102 # With SCMs that have a sequential commit numbering,
103 103 # such as Subversion and Mercurial,
104 104 # Redmine is able to be clever and only fetch changesets
105 105 # going forward from the most recent one it knows about.
106 106 #
107 107 # However, Git does not have a sequential commit numbering.
108 108 #
109 109 # In order to fetch only new adding revisions,
110 # Redmine needs to save "heads".
110 # Redmine needs to parse revisions per branch.
111 # Branch "last_scmid" is for this requirement.
111 112 #
112 113 # In Git and Mercurial, revisions are not in date order.
113 114 # Redmine Mercurial fixed issues.
114 115 # * Redmine Takes Too Long On Large Mercurial Repository
115 116 # http://www.redmine.org/issues/3449
116 117 # * Sorting for changesets might go wrong on Mercurial repos
117 118 # http://www.redmine.org/issues/3567
118 119 #
119 120 # Database revision column is text, so Redmine can not sort by revision.
120 121 # Mercurial has revision number, and revision number guarantees revision order.
121 122 # Redmine Mercurial model stored revisions ordered by database id to database.
122 123 # So, Redmine Mercurial model can use correct ordering revisions.
123 124 #
124 125 # Redmine Mercurial adapter uses "hg log -r 0:tip --limit 10"
125 126 # to get limited revisions from old to new.
126 127 # But, Git 1.7.3.4 does not support --reverse with -n or --skip.
127 128 #
128 129 # The repository can still be fully reloaded by calling #clear_changesets
129 130 # before fetching changesets (eg. for offline resync)
130 131 def fetch_changesets
131 132 scm_brs = branches
132 133 return if scm_brs.nil? || scm_brs.empty?
133
134 134 h1 = extra_info || {}
135 135 h = h1.dup
136 repo_heads = scm_brs.map{ |br| br.scmid }
137 h["heads"] ||= []
138 prev_db_heads = h["heads"].dup
139 if prev_db_heads.empty?
140 prev_db_heads += heads_from_branches_hash
141 end
142 return if prev_db_heads.sort == repo_heads.sort
143
136 h["branches"] ||= {}
144 137 h["db_consistent"] ||= {}
145 138 if changesets.count == 0
146 139 h["db_consistent"]["ordering"] = 1
147 140 merge_extra_info(h)
148 141 self.save
149 142 elsif ! h["db_consistent"].has_key?("ordering")
150 143 h["db_consistent"]["ordering"] = 0
151 144 merge_extra_info(h)
152 145 self.save
153 146 end
154
155 save_revisions(prev_db_heads, repo_heads)
156 end
157
158 def save_revisions(prev_db_heads, repo_heads)
159 h = {}
160 opts = {}
161 opts[:reverse] = true
162 opts[:excludes] = prev_db_heads
163 opts[:includes] = repo_heads
164 begin
165 scm.revisions('', nil, nil, opts) do |rev|
166 db_rev = find_changeset_by_name(rev.scmid)
167 transaction do
168 if db_rev.nil?
169 db_saved_rev = save_revision(rev)
170 parents = {}
171 parents[db_saved_rev] = rev.parents unless rev.parents.nil?
172 parents.each do |ch, chparents|
173 ch.parents = chparents.collect{|rp| find_changeset_by_name(rp)}.compact
147 save_revisions(h, scm_brs)
148 end
149
150 def save_revisions(h, scm_brs)
151 scm_brs.each do |br1|
152 br = br1.to_s
153 from_scmid = nil
154 from_scmid = h["branches"][br]["last_scmid"] if h["branches"][br]
155 h["branches"][br] ||= {}
156 begin
157 scm.revisions('', from_scmid, br, {:reverse => true}) do |rev|
158 db_rev = find_changeset_by_name(rev.revision)
159 transaction do
160 if db_rev.nil?
161 db_saved_rev = save_revision(rev)
162 parents = {}
163 parents[db_saved_rev] = rev.parents unless rev.parents.nil?
164 parents.each do |ch, chparents|
165 ch.parents = chparents.collect{|rp| find_changeset_by_name(rp)}.compact
166 end
174 167 end
168 h["branches"][br]["last_scmid"] = rev.scmid
169 merge_extra_info(h)
170 self.save
175 171 end
176 h["heads"] = prev_db_heads.dup
177 h["heads"] << rev.scmid
178 merge_extra_info(h)
179 self.save
180 172 end
173 rescue Redmine::Scm::Adapters::CommandFailed => e
174 logger.error("save revisions error: #{e.message}")
181 175 end
182 h["heads"] = repo_heads.dup
183 merge_extra_info(h)
184 self.save
185 rescue Redmine::Scm::Adapters::CommandFailed => e
186 logger.error("save revisions error: #{e.message}")
187 176 end
188 177 end
189 178 private :save_revisions
190 179
191 180 def save_revision(rev)
192 181 changeset = Changeset.new(
193 182 :repository => self,
194 183 :revision => rev.identifier,
195 184 :scmid => rev.scmid,
196 185 :committer => rev.author,
197 186 :committed_on => rev.time,
198 187 :comments => rev.message
199 188 )
200 189 if changeset.save
201 190 rev.paths.each do |file|
202 191 Change.create(
203 192 :changeset => changeset,
204 193 :action => file[:action],
205 194 :path => file[:path])
206 195 end
207 196 end
208 197 changeset
209 198 end
210 199 private :save_revision
211 200
212 201 def heads_from_branches_hash
213 202 h1 = extra_info || {}
214 203 h = h1.dup
215 204 h["branches"] ||= {}
216 205 h['branches'].map{|br, hs| hs['last_scmid']}
217 206 end
218 207
219 208 def latest_changesets(path,rev,limit=10)
220 209 revisions = scm.revisions(path, nil, rev, :limit => limit, :all => false)
221 210 return [] if revisions.nil? || revisions.empty?
222 211
223 212 changesets.find(
224 213 :all,
225 214 :conditions => [
226 215 "scmid IN (?)",
227 216 revisions.map!{|c| c.scmid}
228 217 ],
229 218 :order => 'committed_on DESC'
230 219 )
231 220 end
232 221 end
@@ -1,555 +1,547
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 class RepositoryGitTest < ActiveSupport::TestCase
21 21 fixtures :projects, :repositories, :enabled_modules, :users, :roles
22 22
23 23 include Redmine::I18n
24 24
25 25 REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
26 26 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
27 27
28 28 NUM_REV = 28
29 29 NUM_HEAD = 6
30 30
31 31 FELIX_HEX = "Felix Sch\xC3\xA4fer"
32 32 CHAR_1_HEX = "\xc3\x9c"
33 33
34 34 ## Ruby uses ANSI api to fork a process on Windows.
35 35 ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem
36 36 ## and these are incompatible with ASCII.
37 37 # WINDOWS_PASS = Redmine::Platform.mswin?
38 38 WINDOWS_PASS = false
39 39
40 40 ## Git, Mercurial and CVS path encodings are binary.
41 41 ## Subversion supports URL encoding for path.
42 42 ## Redmine Mercurial adapter and extension use URL encoding.
43 43 ## Git accepts only binary path in command line parameter.
44 44 ## So, there is no way to use binary command line parameter in JRuby.
45 45 JRUBY_SKIP = (RUBY_PLATFORM == 'java')
46 46 JRUBY_SKIP_STR = "TODO: This test fails in JRuby"
47 47
48 48 def setup
49 49 @project = Project.find(3)
50 50 @repository = Repository::Git.create(
51 51 :project => @project,
52 52 :url => REPOSITORY_PATH,
53 53 :path_encoding => 'ISO-8859-1'
54 54 )
55 55 assert @repository
56 56 @char_1 = CHAR_1_HEX.dup
57 57 if @char_1.respond_to?(:force_encoding)
58 58 @char_1.force_encoding('UTF-8')
59 59 end
60 60 end
61 61
62 62 def test_blank_path_to_repository_error_message
63 63 set_language_if_valid 'en'
64 64 repo = Repository::Git.new(
65 65 :project => @project,
66 66 :identifier => 'test'
67 67 )
68 68 assert !repo.save
69 69 assert_include "Path to repository can't be blank",
70 70 repo.errors.full_messages
71 71 end
72 72
73 73 def test_blank_path_to_repository_error_message_fr
74 74 set_language_if_valid 'fr'
75 75 str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)"
76 76 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
77 77 repo = Repository::Git.new(
78 78 :project => @project,
79 79 :url => "",
80 80 :identifier => 'test',
81 81 :path_encoding => ''
82 82 )
83 83 assert !repo.save
84 84 assert_include str, repo.errors.full_messages
85 85 end
86 86
87 87 if File.directory?(REPOSITORY_PATH)
88 88 def test_scm_available
89 89 klass = Repository::Git
90 90 assert_equal "Git", klass.scm_name
91 91 assert klass.scm_adapter_class
92 92 assert_not_equal "", klass.scm_command
93 93 assert_equal true, klass.scm_available
94 94 end
95 95
96 96 def test_fetch_changesets_from_scratch
97 97 assert_nil @repository.extra_info
98 98
99 99 assert_equal 0, @repository.changesets.count
100 100 @repository.fetch_changesets
101 101 @project.reload
102 102
103 103 assert_equal NUM_REV, @repository.changesets.count
104 104 assert_equal 39, @repository.changes.count
105 105
106 106 commit = @repository.changesets.find_by_revision("7234cb2750b63f47bff735edc50a1c0a433c2518")
107 107 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.scmid
108 108 assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments
109 109 assert_equal "jsmith <jsmith@foo.bar>", commit.committer
110 110 assert_equal User.find_by_login('jsmith'), commit.user
111 111 # TODO: add a commit with commit time <> author time to the test repository
112 112 assert_equal "2007-12-14 09:22:52".to_time, commit.committed_on
113 113 assert_equal "2007-12-14".to_date, commit.commit_date
114 114 assert_equal 3, commit.changes.count
115 115 change = commit.changes.sort_by(&:path).first
116 116 assert_equal "README", change.path
117 117 assert_equal "A", change.action
118 118
119 assert_equal NUM_HEAD, @repository.extra_info["heads"].size
119 assert_equal NUM_HEAD, @repository.extra_info["branches"].size
120 120 end
121 121
122 122 def test_fetch_changesets_incremental
123 123 assert_equal 0, @repository.changesets.count
124 124 @repository.fetch_changesets
125 125 @project.reload
126 126 assert_equal NUM_REV, @repository.changesets.count
127 extra_info_heads = @repository.extra_info["heads"].dup
128 assert_equal NUM_HEAD, extra_info_heads.size
129 extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" }
130 assert_equal 4, extra_info_heads.size
131
127 extra_info_db = @repository.extra_info["branches"]
128 assert_equal "1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127",
129 extra_info_db["latin-1-path-encoding"]["last_scmid"]
130 assert_equal "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
131 extra_info_db["master"]["last_scmid"]
132 132 del_revs = [
133 133 "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
134 134 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
135 135 "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
136 136 "deff712f05a90d96edbd70facc47d944be5897e3",
137 137 "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
138 138 "7e61ac704deecde634b51e59daa8110435dcb3da",
139 139 ]
140 140 @repository.changesets.each do |rev|
141 141 rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
142 142 end
143 143 @project.reload
144 144 cs1 = @repository.changesets
145 assert_equal NUM_REV - 6, cs1.count
146 extra_info_heads << "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8"
147 h = {}
148 h["heads"] = extra_info_heads
145 assert_equal 22, cs1.count
146 h = @repository.extra_info.dup
147 h["branches"]["master"]["last_scmid"] =
148 "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8"
149 149 @repository.merge_extra_info(h)
150 150 @repository.save
151 151 @project.reload
152 assert @repository.extra_info["heads"].index("4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8")
152 extra_info_db_1 = @repository.extra_info["branches"]
153 assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8",
154 extra_info_db_1["master"]["last_scmid"]
155
153 156 @repository.fetch_changesets
154 157 @project.reload
155 158 assert_equal NUM_REV, @repository.changesets.count
156 assert_equal NUM_HEAD, @repository.extra_info["heads"].size
157 assert @repository.extra_info["heads"].index("83ca5fd546063a3c7dc2e568ba3355661a9e2b2c")
158 159 end
159 160
160 161 def test_fetch_changesets_history_editing
161 162 assert_equal 0, @repository.changesets.count
162 163 @repository.fetch_changesets
163 164 @project.reload
164 165 assert_equal NUM_REV, @repository.changesets.count
165 extra_info_heads = @repository.extra_info["heads"].dup
166 assert_equal NUM_HEAD, extra_info_heads.size
167 extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" }
168 assert_equal 4, extra_info_heads.size
169
166 assert_equal NUM_HEAD, @repository.extra_info["branches"].size
167 assert_equal "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
168 @repository.extra_info["branches"]["master"]["last_scmid"]
170 169 del_revs = [
171 170 "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
172 171 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
173 172 "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
174 173 "deff712f05a90d96edbd70facc47d944be5897e3",
175 174 "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
176 175 "7e61ac704deecde634b51e59daa8110435dcb3da",
177 176 ]
178 177 @repository.changesets.each do |rev|
179 178 rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
180 179 end
181 180 @project.reload
182 181 assert_equal NUM_REV - 6, @repository.changesets.count
183 182
184 183 c = Changeset.new(:repository => @repository,
185 184 :committed_on => Time.now,
186 185 :revision => "abcd1234efgh",
187 186 :scmid => "abcd1234efgh",
188 187 :comments => 'test')
189 188 assert c.save
190 189 @project.reload
191 190 assert_equal NUM_REV - 5, @repository.changesets.count
192 191
193 extra_info_heads << "abcd1234efgh"
194 h = {}
195 h["heads"] = extra_info_heads
192 h = @repository.extra_info.dup
193 h["branches"]["master"]["last_scmid"] = "abcd1234efgh"
196 194 @repository.merge_extra_info(h)
197 195 @repository.save
198 196 @project.reload
199 h1 = @repository.extra_info["heads"].dup
200 assert h1.index("abcd1234efgh")
201 assert_equal 5, h1.size
197 assert_equal "abcd1234efgh",
198 @repository.extra_info["branches"]["master"]["last_scmid"]
202 199
203 200 @repository.fetch_changesets
204 201 @project.reload
205 202 assert_equal NUM_REV - 5, @repository.changesets.count
206 h2 = @repository.extra_info["heads"].dup
207 assert_equal h1, h2
208 203 end
209 204
210 205 def test_parents
211 206 assert_equal 0, @repository.changesets.count
212 207 @repository.fetch_changesets
213 208 @project.reload
214 209 assert_equal NUM_REV, @repository.changesets.count
215 210 r1 = @repository.find_changeset_by_name("7234cb2750b63")
216 211 assert_equal [], r1.parents
217 212 r2 = @repository.find_changeset_by_name("899a15dba03a3")
218 213 assert_equal 1, r2.parents.length
219 214 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518",
220 215 r2.parents[0].identifier
221 216 r3 = @repository.find_changeset_by_name("32ae898b720c2")
222 217 assert_equal 2, r3.parents.length
223 218 r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort
224 219 assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", r4[0]
225 220 assert_equal "7e61ac704deecde634b51e59daa8110435dcb3da", r4[1]
226 221 end
227 222
228 223 def test_db_consistent_ordering_init
229 224 assert_nil @repository.extra_info
230 225 assert_equal 0, @repository.changesets.count
231 226 @repository.fetch_changesets
232 227 @project.reload
233 228 assert_equal 1, @repository.extra_info["db_consistent"]["ordering"]
234 229 end
235 230
236 231 def test_db_consistent_ordering_before_1_2
237 232 assert_nil @repository.extra_info
238 233 assert_equal 0, @repository.changesets.count
239 234 @repository.fetch_changesets
240 235 @project.reload
241 236 assert_equal NUM_REV, @repository.changesets.count
242 237 assert_not_nil @repository.extra_info
243 238 h = {}
244 239 h["heads"] = []
245 240 h["branches"] = {}
246 241 h["db_consistent"] = {}
247 242 @repository.merge_extra_info(h)
248 243 @repository.save
249 244 assert_equal NUM_REV, @repository.changesets.count
250 245 @repository.fetch_changesets
251 246 @project.reload
252 247 assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
253 248
254 extra_info_heads = @repository.extra_info["heads"].dup
255 extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" }
256 249 del_revs = [
257 250 "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
258 251 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
259 252 "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
260 253 "deff712f05a90d96edbd70facc47d944be5897e3",
261 254 "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
262 255 "7e61ac704deecde634b51e59daa8110435dcb3da",
263 256 ]
264 257 @repository.changesets.each do |rev|
265 258 rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
266 259 end
267 260 @project.reload
268 261 cs1 = @repository.changesets
269 262 assert_equal NUM_REV - 6, cs1.count
270 263 assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
271
272 extra_info_heads << "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8"
273 h = {}
274 h["heads"] = extra_info_heads
264 h = @repository.extra_info.dup
265 h["branches"]["master"]["last_scmid"] =
266 "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8"
275 267 @repository.merge_extra_info(h)
276 268 @repository.save
277 269 @project.reload
278 assert @repository.extra_info["heads"].index("4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8")
270 extra_info_db_1 = @repository.extra_info["branches"]
271 assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8",
272 extra_info_db_1["master"]["last_scmid"]
273
279 274 @repository.fetch_changesets
280 @project.reload
281 275 assert_equal NUM_REV, @repository.changesets.count
282 assert_equal NUM_HEAD, @repository.extra_info["heads"].size
283
284 276 assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
285 277 end
286 278
287 279 def test_heads_from_branches_hash
288 280 assert_nil @repository.extra_info
289 281 assert_equal 0, @repository.changesets.count
290 282 assert_equal [], @repository.heads_from_branches_hash
291 283 h = {}
292 284 h["branches"] = {}
293 285 h["branches"]["test1"] = {}
294 286 h["branches"]["test1"]["last_scmid"] = "1234abcd"
295 287 h["branches"]["test2"] = {}
296 288 h["branches"]["test2"]["last_scmid"] = "abcd1234"
297 289 @repository.merge_extra_info(h)
298 290 @repository.save
299 291 @project.reload
300 292 assert_equal ["1234abcd", "abcd1234"], @repository.heads_from_branches_hash.sort
301 293 end
302 294
303 295 def test_latest_changesets
304 296 assert_equal 0, @repository.changesets.count
305 297 @repository.fetch_changesets
306 298 @project.reload
307 299 assert_equal NUM_REV, @repository.changesets.count
308 300 # with limit
309 301 changesets = @repository.latest_changesets('', 'master', 2)
310 302 assert_equal 2, changesets.size
311 303
312 304 # with path
313 305 changesets = @repository.latest_changesets('images', 'master')
314 306 assert_equal [
315 307 'deff712f05a90d96edbd70facc47d944be5897e3',
316 308 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
317 309 '7234cb2750b63f47bff735edc50a1c0a433c2518',
318 310 ], changesets.collect(&:revision)
319 311
320 312 changesets = @repository.latest_changesets('README', nil)
321 313 assert_equal [
322 314 '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf',
323 315 '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8',
324 316 '713f4944648826f558cf548222f813dabe7cbb04',
325 317 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
326 318 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
327 319 '7234cb2750b63f47bff735edc50a1c0a433c2518',
328 320 ], changesets.collect(&:revision)
329 321
330 322 # with path, revision and limit
331 323 changesets = @repository.latest_changesets('images', '899a15dba')
332 324 assert_equal [
333 325 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
334 326 '7234cb2750b63f47bff735edc50a1c0a433c2518',
335 327 ], changesets.collect(&:revision)
336 328
337 329 changesets = @repository.latest_changesets('images', '899a15dba', 1)
338 330 assert_equal [
339 331 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
340 332 ], changesets.collect(&:revision)
341 333
342 334 changesets = @repository.latest_changesets('README', '899a15dba')
343 335 assert_equal [
344 336 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
345 337 '7234cb2750b63f47bff735edc50a1c0a433c2518',
346 338 ], changesets.collect(&:revision)
347 339
348 340 changesets = @repository.latest_changesets('README', '899a15dba', 1)
349 341 assert_equal [
350 342 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
351 343 ], changesets.collect(&:revision)
352 344
353 345 # with path, tag and limit
354 346 changesets = @repository.latest_changesets('images', 'tag01.annotated')
355 347 assert_equal [
356 348 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
357 349 '7234cb2750b63f47bff735edc50a1c0a433c2518',
358 350 ], changesets.collect(&:revision)
359 351
360 352 changesets = @repository.latest_changesets('images', 'tag01.annotated', 1)
361 353 assert_equal [
362 354 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
363 355 ], changesets.collect(&:revision)
364 356
365 357 changesets = @repository.latest_changesets('README', 'tag01.annotated')
366 358 assert_equal [
367 359 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
368 360 '7234cb2750b63f47bff735edc50a1c0a433c2518',
369 361 ], changesets.collect(&:revision)
370 362
371 363 changesets = @repository.latest_changesets('README', 'tag01.annotated', 1)
372 364 assert_equal [
373 365 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
374 366 ], changesets.collect(&:revision)
375 367
376 368 # with path, branch and limit
377 369 changesets = @repository.latest_changesets('images', 'test_branch')
378 370 assert_equal [
379 371 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
380 372 '7234cb2750b63f47bff735edc50a1c0a433c2518',
381 373 ], changesets.collect(&:revision)
382 374
383 375 changesets = @repository.latest_changesets('images', 'test_branch', 1)
384 376 assert_equal [
385 377 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
386 378 ], changesets.collect(&:revision)
387 379
388 380 changesets = @repository.latest_changesets('README', 'test_branch')
389 381 assert_equal [
390 382 '713f4944648826f558cf548222f813dabe7cbb04',
391 383 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
392 384 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
393 385 '7234cb2750b63f47bff735edc50a1c0a433c2518',
394 386 ], changesets.collect(&:revision)
395 387
396 388 changesets = @repository.latest_changesets('README', 'test_branch', 2)
397 389 assert_equal [
398 390 '713f4944648826f558cf548222f813dabe7cbb04',
399 391 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
400 392 ], changesets.collect(&:revision)
401 393
402 394 if JRUBY_SKIP
403 395 puts JRUBY_SKIP_STR
404 396 else
405 397 # latin-1 encoding path
406 398 changesets = @repository.latest_changesets(
407 399 "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89')
408 400 assert_equal [
409 401 '64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
410 402 '4fc55c43bf3d3dc2efb66145365ddc17639ce81e',
411 403 ], changesets.collect(&:revision)
412 404
413 405 changesets = @repository.latest_changesets(
414 406 "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89', 1)
415 407 assert_equal [
416 408 '64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
417 409 ], changesets.collect(&:revision)
418 410 end
419 411 end
420 412
421 413 def test_latest_changesets_latin_1_dir
422 414 if WINDOWS_PASS
423 415 #
424 416 elsif JRUBY_SKIP
425 417 puts JRUBY_SKIP_STR
426 418 else
427 419 assert_equal 0, @repository.changesets.count
428 420 @repository.fetch_changesets
429 421 @project.reload
430 422 assert_equal NUM_REV, @repository.changesets.count
431 423 changesets = @repository.latest_changesets(
432 424 "latin-1-dir/test-#{@char_1}-subdir", '1ca7f5ed')
433 425 assert_equal [
434 426 '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127',
435 427 ], changesets.collect(&:revision)
436 428 end
437 429 end
438 430
439 431 def test_find_changeset_by_name
440 432 assert_equal 0, @repository.changesets.count
441 433 @repository.fetch_changesets
442 434 @project.reload
443 435 assert_equal NUM_REV, @repository.changesets.count
444 436 ['7234cb2750b63f47bff735edc50a1c0a433c2518', '7234cb2750b'].each do |r|
445 437 assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518',
446 438 @repository.find_changeset_by_name(r).revision
447 439 end
448 440 end
449 441
450 442 def test_find_changeset_by_empty_name
451 443 assert_equal 0, @repository.changesets.count
452 444 @repository.fetch_changesets
453 445 @project.reload
454 446 assert_equal NUM_REV, @repository.changesets.count
455 447 ['', ' ', nil].each do |r|
456 448 assert_nil @repository.find_changeset_by_name(r)
457 449 end
458 450 end
459 451
460 452 def test_identifier
461 453 assert_equal 0, @repository.changesets.count
462 454 @repository.fetch_changesets
463 455 @project.reload
464 456 assert_equal NUM_REV, @repository.changesets.count
465 457 c = @repository.changesets.find_by_revision(
466 458 '7234cb2750b63f47bff735edc50a1c0a433c2518')
467 459 assert_equal c.scmid, c.identifier
468 460 end
469 461
470 462 def test_format_identifier
471 463 assert_equal 0, @repository.changesets.count
472 464 @repository.fetch_changesets
473 465 @project.reload
474 466 assert_equal NUM_REV, @repository.changesets.count
475 467 c = @repository.changesets.find_by_revision(
476 468 '7234cb2750b63f47bff735edc50a1c0a433c2518')
477 469 assert_equal '7234cb27', c.format_identifier
478 470 end
479 471
480 472 def test_activities
481 473 c = Changeset.new(:repository => @repository,
482 474 :committed_on => Time.now,
483 475 :revision => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
484 476 :scmid => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
485 477 :comments => 'test')
486 478 assert c.event_title.include?('abc7234c:')
487 479 assert_equal 'abc7234cb2750b63f47bff735edc50a1c0a433c2', c.event_url[:rev]
488 480 end
489 481
490 482 def test_log_utf8
491 483 assert_equal 0, @repository.changesets.count
492 484 @repository.fetch_changesets
493 485 @project.reload
494 486 assert_equal NUM_REV, @repository.changesets.count
495 487 str_felix_hex = FELIX_HEX.dup
496 488 if str_felix_hex.respond_to?(:force_encoding)
497 489 str_felix_hex.force_encoding('UTF-8')
498 490 end
499 491 c = @repository.changesets.find_by_revision(
500 492 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b')
501 493 assert_equal "#{str_felix_hex} <felix@fachschaften.org>", c.committer
502 494 end
503 495
504 496 def test_previous
505 497 assert_equal 0, @repository.changesets.count
506 498 @repository.fetch_changesets
507 499 @project.reload
508 500 assert_equal NUM_REV, @repository.changesets.count
509 501 %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1|
510 502 changeset = @repository.find_changeset_by_name(r1)
511 503 %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2|
512 504 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
513 505 end
514 506 end
515 507 end
516 508
517 509 def test_previous_nil
518 510 assert_equal 0, @repository.changesets.count
519 511 @repository.fetch_changesets
520 512 @project.reload
521 513 assert_equal NUM_REV, @repository.changesets.count
522 %w|7234cb2750b63f47bff735edc50a1c0a433c2518 7234cb275|.each do |r1|
514 %w|95488a44bc25f7d1f97d775a31359539ff333a63 95488a44b|.each do |r1|
523 515 changeset = @repository.find_changeset_by_name(r1)
524 516 assert_nil changeset.previous
525 517 end
526 518 end
527 519
528 520 def test_next
529 521 assert_equal 0, @repository.changesets.count
530 522 @repository.fetch_changesets
531 523 @project.reload
532 524 assert_equal NUM_REV, @repository.changesets.count
533 525 %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2|
534 526 changeset = @repository.find_changeset_by_name(r2)
535 527 %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1|
536 528 assert_equal @repository.find_changeset_by_name(r1), changeset.next
537 529 end
538 530 end
539 531 end
540 532
541 533 def test_next_nil
542 534 assert_equal 0, @repository.changesets.count
543 535 @repository.fetch_changesets
544 536 @project.reload
545 537 assert_equal NUM_REV, @repository.changesets.count
546 %w|2a682156a3b6e77a8bf9cd4590e8db757f3c6c78 2a682156a3b6e77a|.each do |r1|
538 %w|67e7792ce20ccae2e4bb73eed09bb397819c8834 67e7792ce20cca|.each do |r1|
547 539 changeset = @repository.find_changeset_by_name(r1)
548 540 assert_nil changeset.next
549 541 end
550 542 end
551 543 else
552 544 puts "Git test repository NOT FOUND. Skipping unit tests !!!"
553 545 def test_fake; assert true end
554 546 end
555 547 end
General Comments 0
You need to be logged in to leave comments. Login now