1 require File.dirname(__FILE__) + '/../test_helper'
4 class SvnCommitsTest < Scm::Test
7 with_svn_repository('svn') do |svn|
8 assert_equal 5, svn.commit_count
9 assert_equal 3, svn.commit_count(2)
10 assert_equal 0, svn.commit_count(1000)
12 assert_equal [1,2,3,4,5], svn.commit_tokens
13 assert_equal [3,4,5], svn.commit_tokens(2)
14 assert_equal [], svn.commit_tokens(1000)
16 assert_equal [1,2,3,4,5], svn.commits.collect { |c| c.token }
17 assert_equal [3,4,5], svn.commits(2).collect { |c| c.token }
18 assert_equal [], svn.commits(1000)
22 # Confirms that the sha1 matches those created by git exactly
24 with_svn_repository('svn') do |svn|
25 assert_equal '0000000000000000000000000000000000000000', svn.try_get_sha1('/trunk/file_not_found')
26 assert_equal 'f6adcae4447809b651c787c078d255b2b4e963c5', svn.try_get_sha1('/trunk/helloworld.c')
30 # Given a commit with diffs, fill in all of the SHA1 values.
31 def test_populate_sha1
32 with_svn_repository('svn') do |svn|
33 c = Scm::Commit.new(:token => 3)
34 c.diffs = [Scm::Diff.new(:path => "/trunk/helloworld.c", :action => "M")]
35 svn.populate_sha1s!(c)
36 assert_equal 'f6adcae4447809b651c787c078d255b2b4e963c5', c.diffs.first.sha1
37 assert_equal '4c734ad53b272c9b3d719f214372ac497ff6c068', c.diffs.first.parent_sha1
41 def test_strip_commit_branch
42 svn = SvnAdapter.new(:branch_name => "/trunk")
43 commit = Scm::Commit.new
45 # nil diffs before => nil diffs after
46 assert !svn.strip_commit_branch(commit).diffs
48 # [] diffs before => [] diffs after
50 assert_equal [], svn.strip_commit_branch(commit).diffs
53 Scm::Diff.new(:path => "/trunk"),
54 Scm::Diff.new(:path => "/trunk/helloworld.c"),
55 Scm::Diff.new(:path => "/branches/a")
57 assert_equal ['', '/helloworld.c'], svn.strip_commit_branch(commit).diffs.collect { |d| d.path }.sort
60 def test_strip_diff_branch
61 svn = SvnAdapter.new(:branch_name => "/trunk")
62 assert !svn.strip_diff_branch(Scm::Diff.new)
63 assert !svn.strip_diff_branch(Scm::Diff.new(:path => "/branches/b"))
64 assert_equal '', svn.strip_diff_branch(Scm::Diff.new(:path => "/trunk")).path
65 assert_equal '/helloworld.c', svn.strip_diff_branch(Scm::Diff.new(:path => "/trunk/helloworld.c")).path
68 def test_strip_path_branch
69 # Returns nil for any path outside of SvnAdapter::branch_name
70 assert !SvnAdapter.new.strip_path_branch(nil)
71 assert !SvnAdapter.new(:branch_name => "/trunk").strip_path_branch("/branches/foo")
72 assert !SvnAdapter.new(:branch_name => "/trunk").strip_path_branch("/t")
74 # If branch_name is empty or root, returns path unchanged
75 assert_equal '', SvnAdapter.new.strip_path_branch('')
76 assert_equal '/trunk', SvnAdapter.new.strip_path_branch('/trunk')
78 # If path is equal to or is a subdirectory of branch_name, returns subdirectory portion only.
79 assert_equal '', SvnAdapter.new(:branch_name => "/trunk").strip_path_branch('/trunk')
80 assert_equal '/foo', SvnAdapter.new(:branch_name => "/trunk").strip_path_branch('/trunk/foo')
83 def test_strip_path_branch_with_special_chars
84 assert_equal '/foo', SvnAdapter.new(:branch_name => '/trunk/hamcrest-c++').strip_path_branch('/trunk/hamcrest-c++/foo')
89 with_svn_repository('deep_svn') do |svn|
91 # The full repository contains 4 revisions...
92 assert_equal 4, svn.commit_count
94 # ...however, the current trunk contains only revisions 3 and 4.
95 # That's because the branch was moved to replace the trunk at revision 3.
97 # Even though there was a different trunk directory present in
98 # revisions 1 and 2, it is not visible to Ohloh.
100 trunk = SvnAdapter.new(:url => File.join(svn.url,'trunk'), :branch_name => '/trunk').normalize
101 assert_equal 2, trunk.commit_count
102 assert_equal [3,4], trunk.commit_tokens
106 trunk.each_commit { |c| deep_commits << c }
108 # When the branch is moved to replace the trunk in revision 3,
109 # the Subversion log shows
112 # A /trunk (from /branches/b:2)
114 # However, there are files in those directories. Make sure the commits
115 # that we generate include all of those files not shown by the log.
117 # Also, our commits do not include diffs for the actual directories;
118 # only the files within those directories.
120 # Also, since we are only tracking the /trunk and not /branches/b, then
121 # there should not be anything referring to activity in /branches/b.
123 assert_equal 3, deep_commits.first.token # Make sure this is the right revision
124 assert_equal 2, deep_commits.first.diffs.size # Two files seen
126 assert_equal 'A', deep_commits.first.diffs[0].action
127 assert_equal '/subdir/bar.rb', deep_commits.first.diffs[0].path
128 assert_equal 'A', deep_commits.first.diffs[1].action
129 assert_equal '/subdir/foo.rb', deep_commits.first.diffs[1].path
131 # In Revision 4, a directory is renamed. This shows in the Subversion log as
133 # A /trunk/newdir (from /trunk/subdir:3)
136 # Again, there are files in this directory, so make sure our commit includes
137 # both delete and add events for all of the files in this directory, but does
138 # not actually refer to the directories themselves.
140 assert_equal 4, deep_commits.last.token # Make sure we're checking the right revision
142 # There should be 2 files removed and two files added
143 assert_equal 4, deep_commits.last.diffs.size
145 assert_equal 'A', deep_commits.last.diffs[0].action
146 assert_equal '/newdir/bar.rb', deep_commits.last.diffs[0].path
147 assert_equal 'A', deep_commits.last.diffs[1].action
148 assert_equal '/newdir/foo.rb', deep_commits.last.diffs[1].path
150 assert_equal 'D', deep_commits.last.diffs[2].action
151 assert_equal '/subdir/bar.rb', deep_commits.last.diffs[2].path
152 assert_equal 'D', deep_commits.last.diffs[3].action
153 assert_equal '/subdir/foo.rb', deep_commits.last.diffs[3].path
157 # A mini-integration test.
158 # Check that SHA1 values are populated, directories are recursed, and outside branches are ignored.
161 with_svn_repository('svn') do |svn|
162 svn.each_commit do |e|
165 assert e.committer_name
166 assert e.committer_date
170 assert d.action.length == 1
171 assert d.path.length > 0
176 assert_equal [1, 2, 3, 4, 5], commits.collect { |c| c.token }
177 assert_equal ['robin','robin','robin','jason','jason'], commits.collect { |c| c.committer_name }
179 assert commits[0].committer_date - Time.utc(2006,6,11,18,28,0) < 1 # commits include milliseconds
180 assert commits[1].committer_date - Time.utc(2006,6,11,18,32,13) < 1
181 assert commits[2].committer_date - Time.utc(2006,6,11,18,34,17) < 1
182 assert commits[3].committer_date - Time.utc(2006,7,14,22,17,8) < 1
183 assert commits[4].committer_date - Time.utc(2006,7,14,23,7,15) < 1
185 assert_equal "Initial Checkin\n", commits[0].message
186 assert_equal "added makefile", commits[1].message
187 assert_equal "added some documentation and licensing info", commits[2].message
188 assert_equal "added bs COPYING to catch global licenses", commits[3].message
189 assert_equal "moving COPYING", commits[4].message
191 assert_equal 1, commits[0].diffs.size
192 assert_equal 'A', commits[0].diffs[0].action
193 assert_equal '/trunk/helloworld.c', commits[0].diffs[0].path
194 assert_equal '4c734ad53b272c9b3d719f214372ac497ff6c068', commits[0].diffs[0].sha1
195 assert_equal '0000000000000000000000000000000000000000', commits[0].diffs[0].parent_sha1
197 assert_equal 1, commits[1].diffs.size
198 assert_equal 'A', commits[1].diffs[0].action
199 assert_equal '/trunk/makefile', commits[1].diffs[0].path
200 assert_equal 'af2dfd5070b01a19b672861e595de98c101c49cc', commits[1].diffs[0].sha1
201 assert_equal '0000000000000000000000000000000000000000', commits[1].diffs[0].parent_sha1
203 assert_equal 2, commits[2].diffs.size
204 assert_equal 'A', commits[2].diffs[0].action
205 assert_equal '/trunk/README', commits[2].diffs[0].path
206 assert_equal 'f0547ce063095e66be74618bc410989df226d2d2', commits[2].diffs[0].sha1
207 assert_equal '0000000000000000000000000000000000000000', commits[2].diffs[0].parent_sha1
208 assert_equal 'M', commits[2].diffs[1].action
209 assert_equal '/trunk/helloworld.c', commits[2].diffs[1].path
210 assert_equal 'f6adcae4447809b651c787c078d255b2b4e963c5', commits[2].diffs[1].sha1
211 assert_equal '4c734ad53b272c9b3d719f214372ac497ff6c068', commits[2].diffs[1].parent_sha1
213 assert_equal 1, commits[3].diffs.size
214 assert_equal 'A', commits[3].diffs[0].action
215 assert_equal '/COPYING', commits[3].diffs[0].path
216 assert_equal '6ff87c4664981e4397625791c8ea3bbb5f2279a3', commits[3].diffs[0].sha1
217 assert_equal '0000000000000000000000000000000000000000', commits[3].diffs[0].parent_sha1
219 assert_equal 2, commits[4].diffs.size
220 assert_equal 'D', commits[4].diffs[0].action
221 assert_equal '/COPYING', commits[4].diffs[0].path
222 assert_equal '0000000000000000000000000000000000000000', commits[4].diffs[0].sha1
223 assert_equal '6ff87c4664981e4397625791c8ea3bbb5f2279a3', commits[4].diffs[0].parent_sha1
224 assert_equal 'A', commits[4].diffs[1].action
225 assert_equal '/trunk/COPYING', commits[4].diffs[1].path
226 assert_equal '6ff87c4664981e4397625791c8ea3bbb5f2279a3', commits[4].diffs[1].sha1
227 assert_equal '0000000000000000000000000000000000000000', commits[4].diffs[1].parent_sha1