:order => "committed_on DESC, #{Changeset.table_name}.id DESC").collect(&:changeset)
end
+ # Returns a path relative to the url of the repository
+ def relative_path(path)
+ path
+ end
+
def latest_changeset
@latest_changeset ||= changesets.find(:first)
end
revisions ? changesets.find_all_by_revision(revisions.collect(&:identifier), :order => "committed_on DESC") : []
end
+ # Returns a path relative to the url of the repository
+ def relative_path(path)
+ path.gsub(Regexp.new("^\/?#{Regexp.escape(relative_url)}"), '')
+ end
+
def fetch_changesets
scm_info = scm.info
if scm_info
end
end
end
+
+ private
+
+ # Returns the relative url of the repository
+ # Eg: root_url = file:///var/svn/foo
+ # url = file:///var/svn/foo/bar
+ # => returns /bar
+ def relative_url
+ @relative_url ||= url.gsub(Regexp.new("^#{Regexp.escape(root_url)}"), '')
+ end
end
<td><div class="square action_<%= change.action %>"></div> <%= change.path %> <%= "(#{change.revision})" unless change.revision.blank? %></td>
<td align="right">
<% if change.action == "M" %>
-<%= link_to l(:label_view_diff), :action => 'diff', :id => @project, :path => without_leading_slash(change.path), :rev => @changeset.revision %>
+<%= link_to l(:label_view_diff), :action => 'diff', :id => @project, :path => without_leading_slash(change.relative_path), :rev => @changeset.revision %>
<% end %>
</td>
</tr>
assert_equal 'folder', assigns(:entry).name
end
+ def test_revision
+ get :revision, :id => 1, :rev => 2
+ assert_response :success
+ assert_template 'revision'
+ assert_tag :tag => 'tr',
+ :child => { :tag => 'td', :content => %r{/test/some/path/in/the/repo} },
+ :child => { :tag => 'td',
+ :child => { :tag => 'a', :attributes => { :href => '/repositories/diff/ecookbook/test/some/path/in/the/repo?rev=2' } }
+ }
+ end
+
+ def test_revision_with_repository_pointing_to_a_subdirectory
+ r = Project.find(1).repository
+ # Changes repository url to a subdirectory
+ r.update_attribute :url, (r.url + '/test/some')
+
+ get :revision, :id => 1, :rev => 2
+ assert_response :success
+ assert_template 'revision'
+ assert_tag :tag => 'tr',
+ :child => { :tag => 'td', :content => %r{/test/some/path/in/the/repo} },
+ :child => { :tag => 'td',
+ :child => { :tag => 'a', :attributes => { :href => '/repositories/diff/ecookbook/path/in/the/repo?rev=2' } }
+ }
+ end
+
def test_diff
get :diff, :id => 1, :rev => 3
assert_response :success