@@ -19,4 +19,8 class Change < ActiveRecord::Base | |||
|
19 | 19 | belongs_to :changeset |
|
20 | 20 | |
|
21 | 21 | validates_presence_of :changeset_id, :action, :path |
|
22 | ||
|
23 | def relative_path | |
|
24 | changeset.repository.relative_path(path) | |
|
25 | end | |
|
22 | 26 | end |
@@ -64,6 +64,11 class Repository < ActiveRecord::Base | |||
|
64 | 64 | :order => "committed_on DESC, #{Changeset.table_name}.id DESC").collect(&:changeset) |
|
65 | 65 | end |
|
66 | 66 | |
|
67 | # Returns a path relative to the url of the repository | |
|
68 | def relative_path(path) | |
|
69 | path | |
|
70 | end | |
|
71 | ||
|
67 | 72 | def latest_changeset |
|
68 | 73 | @latest_changeset ||= changesets.find(:first) |
|
69 | 74 | end |
@@ -35,6 +35,11 class Repository::Subversion < Repository | |||
|
35 | 35 | revisions ? changesets.find_all_by_revision(revisions.collect(&:identifier), :order => "committed_on DESC") : [] |
|
36 | 36 | end |
|
37 | 37 | |
|
38 | # Returns a path relative to the url of the repository | |
|
39 | def relative_path(path) | |
|
40 | path.gsub(Regexp.new("^\/?#{Regexp.escape(relative_url)}"), '') | |
|
41 | end | |
|
42 | ||
|
38 | 43 | def fetch_changesets |
|
39 | 44 | scm_info = scm.info |
|
40 | 45 | if scm_info |
@@ -71,4 +76,14 class Repository::Subversion < Repository | |||
|
71 | 76 | end |
|
72 | 77 | end |
|
73 | 78 | end |
|
79 | ||
|
80 | private | |
|
81 | ||
|
82 | # Returns the relative url of the repository | |
|
83 | # Eg: root_url = file:///var/svn/foo | |
|
84 | # url = file:///var/svn/foo/bar | |
|
85 | # => returns /bar | |
|
86 | def relative_url | |
|
87 | @relative_url ||= url.gsub(Regexp.new("^#{Regexp.escape(root_url)}"), '') | |
|
88 | end | |
|
74 | 89 | end |
@@ -49,7 +49,7 | |||
|
49 | 49 | <td><div class="square action_<%= change.action %>"></div> <%= change.path %> <%= "(#{change.revision})" unless change.revision.blank? %></td> |
|
50 | 50 | <td align="right"> |
|
51 | 51 | <% if change.action == "M" %> |
|
52 | <%= link_to l(:label_view_diff), :action => 'diff', :id => @project, :path => without_leading_slash(change.path), :rev => @changeset.revision %> | |
|
52 | <%= link_to l(:label_view_diff), :action => 'diff', :id => @project, :path => without_leading_slash(change.relative_path), :rev => @changeset.revision %> | |
|
53 | 53 | <% end %> |
|
54 | 54 | </td> |
|
55 | 55 | </tr> |
@@ -13,4 +13,11 changes_002: | |||
|
13 | 13 | path: /test/some/path/elsewhere/in/the/repo |
|
14 | 14 | from_path: |
|
15 | 15 | from_revision: |
|
16 | changes_003: | |
|
17 | id: 3 | |
|
18 | changeset_id: 101 | |
|
19 | action: M | |
|
20 | path: /test/some/path/in/the/repo | |
|
21 | from_path: | |
|
22 | from_revision: | |
|
16 | 23 | No newline at end of file |
@@ -97,6 +97,32 class RepositoriesSubversionControllerTest < Test::Unit::TestCase | |||
|
97 | 97 | assert_equal 'folder', assigns(:entry).name |
|
98 | 98 | end |
|
99 | 99 | |
|
100 | def test_revision | |
|
101 | get :revision, :id => 1, :rev => 2 | |
|
102 | assert_response :success | |
|
103 | assert_template 'revision' | |
|
104 | assert_tag :tag => 'tr', | |
|
105 | :child => { :tag => 'td', :content => %r{/test/some/path/in/the/repo} }, | |
|
106 | :child => { :tag => 'td', | |
|
107 | :child => { :tag => 'a', :attributes => { :href => '/repositories/diff/ecookbook/test/some/path/in/the/repo?rev=2' } } | |
|
108 | } | |
|
109 | end | |
|
110 | ||
|
111 | def test_revision_with_repository_pointing_to_a_subdirectory | |
|
112 | r = Project.find(1).repository | |
|
113 | # Changes repository url to a subdirectory | |
|
114 | r.update_attribute :url, (r.url + '/test/some') | |
|
115 | ||
|
116 | get :revision, :id => 1, :rev => 2 | |
|
117 | assert_response :success | |
|
118 | assert_template 'revision' | |
|
119 | assert_tag :tag => 'tr', | |
|
120 | :child => { :tag => 'td', :content => %r{/test/some/path/in/the/repo} }, | |
|
121 | :child => { :tag => 'td', | |
|
122 | :child => { :tag => 'a', :attributes => { :href => '/repositories/diff/ecookbook/path/in/the/repo?rev=2' } } | |
|
123 | } | |
|
124 | end | |
|
125 | ||
|
100 | 126 | def test_diff |
|
101 | 127 | get :diff, :id => 1, :rev => 3 |
|
102 | 128 | assert_response :success |
General Comments 0
You need to be logged in to leave comments.
Login now