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