Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2015-07-22 04:01:03 +0300
committerStan Hu <stanhu@gmail.com>2015-07-22 04:01:03 +0300
commitf593b621e3d4b3da31a2e48dd53a96d60dde6cd0 (patch)
treeb553985902225a726d011faea559fd83bdc4b56d /app
parent815cf7f84309f28af3561e1c9b49d1fa35719c7f (diff)
parent643557dabccbb3a503b0867ae44ec5701759d2a8 (diff)
Merge branch 'fix-404-empty-repo' into 'master'
Fix 404 error in files view after deleting the last file in a repository Here's the logic: 1. In `TreeController`, `require_non_empty_project` will prevent `show` from being called if the project is empty. That means all calls to `show` will be guaranteed to have at least 1 commit. 2. If the ref name is not valid, then return a 404. This ensures that at least the controller is looking at a valid branch/tag/SHA ID. 3. This leaves a number of cases: ``` 3a. Valid ref, valid directory 3b. Valid ref, valid filename 3c. Valid ref, invalid path 3d. Valid ref, no files ``` Case 3a: The tree will not be `empty?` and will pass through the whole function. Case 3b: The tree will be `empty?` but the `blob_at` will resolve properly and trigger a redirect to the file. Case 3c: In this case, a path is given. Return 404 if it cannot be resolved neither as a tree nor a blob. Case 3d: In this case, no path is given. If the tree is empty, this means it's an empty branch and just fall through. Example broken branch: https://gitlab.com/gitlab-org/gitlab-test/tree/empty-branch Closes #1362 See merge request !1010
Diffstat (limited to 'app')
-rw-r--r--app/controllers/projects/tree_controller.rb4
1 files changed, 3 insertions, 1 deletions
diff --git a/app/controllers/projects/tree_controller.rb b/app/controllers/projects/tree_controller.rb
index b659e15f242..92e4bc16d9d 100644
--- a/app/controllers/projects/tree_controller.rb
+++ b/app/controllers/projects/tree_controller.rb
@@ -7,13 +7,15 @@ class Projects::TreeController < Projects::ApplicationController
before_action :authorize_download_code!
def show
+ return not_found! unless @repository.commit(@ref)
+
if tree.entries.empty?
if @repository.blob_at(@commit.id, @path)
redirect_to(
namespace_project_blob_path(@project.namespace, @project,
File.join(@ref, @path))
) and return
- else
+ elsif @path.present?
return not_found!
end
end