summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-07-09 06:19:18 +0000
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-07-09 06:19:18 +0000
commit22995fc9324774ce5301589d05a4687793faddac (patch)
tree014cecf3effce4fa04ab3119bf9186846dbf51c1
parent4c3785afbf24b39a8574311b9ba36edbc6e26bc2 (diff)
parente87f2380779871a64742acdd9dd0358aac7eafce (diff)
downloadgitlab-ce-22995fc9324774ce5301589d05a4687793faddac.tar.gz
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
-rw-r--r--app/controllers/projects/blob_controller.rb10
-rw-r--r--app/controllers/projects/tree_controller.rb9
-rw-r--r--spec/controllers/blob_controller_spec.rb14
-rw-r--r--spec/controllers/tree_controller_spec.rb13
4 files changed, 42 insertions, 4 deletions
diff --git a/app/controllers/projects/blob_controller.rb b/app/controllers/projects/blob_controller.rb
index a1a8bed09f4..db3d173b98d 100644
--- a/app/controllers/projects/blob_controller.rb
+++ b/app/controllers/projects/blob_controller.rb
@@ -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
diff --git a/app/controllers/projects/tree_controller.rb b/app/controllers/projects/tree_controller.rb
index 30c94ec6da0..4d033b36848 100644
--- a/app/controllers/projects/tree_controller.rb
+++ b/app/controllers/projects/tree_controller.rb
@@ -1,7 +1,14 @@
# 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
diff --git a/spec/controllers/blob_controller_spec.rb b/spec/controllers/blob_controller_spec.rb
index cea6922e1c3..929f6d3b46d 100644
--- a/spec/controllers/blob_controller_spec.rb
+++ b/spec/controllers/blob_controller_spec.rb
@@ -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
diff --git a/spec/controllers/tree_controller_spec.rb b/spec/controllers/tree_controller_spec.rb
index 479118a3465..b169c2a678f 100644
--- a/spec/controllers/tree_controller_spec.rb
+++ b/spec/controllers/tree_controller_spec.rb
@@ -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