Fix 404 error in files view after deleting the last file in a repository
Here's the logic:
- In
TreeController
,require_non_empty_project
will preventshow
from being called if the project is empty. That means all calls toshow
will be guaranteed to have at least 1 commit. - 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.
- 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 (closed)