Commit 22995fc9 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'redirect_betwee_tree_and_blob' into 'master'

Redirect between tree and blob

This checks if on requested non-existing tree path blob exists, redirects to blob path if the file exists, otherwise return not found.

See #1369

See merge request !953
parents 4c3785af e87f2380
......@@ -30,8 +30,12 @@ class Projects::BlobController < Projects::ApplicationController
def blob
@blob ||= @repository.blob_at(@commit.id, @path)
return not_found! unless @blob
@blob
if @blob
@blob
elsif tree.entries.any?
redirect_to project_tree_path(@project, File.join(@ref, @path)) and return
else
return not_found!
end
end
end
# Controller for viewing a repository's file structure
class Projects::TreeController < Projects::BaseTreeController
def show
return not_found! if tree.entries.empty?
if tree.entries.empty?
if @repository.blob_at(@commit.id, @path)
redirect_to project_blob_path(@project, File.join(@ref, @path)) and return
else
return not_found!
end
end
respond_to do |format|
format.html
......
......@@ -34,4 +34,18 @@ describe Projects::BlobController do
it { should respond_with(:not_found) }
end
end
describe 'GET show with tree path' do
render_views
before do
get :show, project_id: project.to_param, id: id
controller.instance_variable_set(:@blob, nil)
end
context 'redirect to tree' do
let(:id) { 'master/doc' }
it { should redirect_to("/#{project.path_with_namespace}/tree/master/doc") }
end
end
end
......@@ -40,4 +40,17 @@ describe Projects::TreeController do
it { should respond_with(:not_found) }
end
end
describe 'GET show with blob path' do
render_views
before do
get :show, project_id: project.to_param, id: id
end
context 'redirect to blob' do
let(:id) { 'master/README.md' }
it { should redirect_to("/#{project.path_with_namespace}/blob/master/README.md") }
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment