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