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)
Merge request reports
Activity
mentioned in issue #1362 (closed)
Added 19 commits:
- 9328562d...57f9a1cc - 18 commits from branch
gitlab-org:master
- 31f31a43 - Fix 404 error in files view after deleting the last file in a repository
- 9328562d...57f9a1cc - 18 commits from branch
mentioned in issue #1826 (closed)
Reassigned to @rspeicher
14 15 'master' => '5937ac0' 15 16 } 16 17 17 FORKED_BRANCH_SHA = BRANCH_SHA.merge({ 18 'add-submodule-version-bump' => '3f547c08' 19 }) 18 # Currently only need a subset of the branches 19 FORKED_BRANCH_SHA = { 20 'add-submodule-version-bump' => '3f547c08', 21 'master' => '5937ac0' The
merge
was bringing in the newempty-branch
, which is not present in https://gitlab.com/gitlab-org/gitlab-test-fork. I could push the branch there too and revert this change.
Added 1 commit:
- 643557da - Fix 404 error in files view after deleting the last file in a repository
@stanhu Sorry, I meant if it's only used in the one test to move it directly inside the
it
block for that test, so it's part of the setup phase.What are your thoughts on Better Specs? I tend to think minimizing the amount of code in the
it
block is more readable.In the last few months I've kind of come to agree with most of Joe Ferris's Let's Not post.
Using the tree_controller_spec.rb here as an example, we've got tests like this:
context "valid branch, valid path" do let(:id) { 'master/encoding/' } it { is_expected.to respond_with(:success) } end
And if you look at just that test, we're completely obscuring what this test is doing. It's unclear what setting
:id
does, or that it's required to make the test pass.To me, the test would be much clearer with something like this:
def go(id) get :show, params params params, id: id end it 'succeeds with a valid branch and valid path' do go 'master/encoding' expect(response).to be_success end it 'succeeds with a valid empty branch' do go 'empty-branch' expect(response).to be_success end
Of course, I'm guilty of abusing
let
s andsubject
pretty heavily and I've been actively trying to re-evaluate my usage of them lately. And there are times where I still feel like they're the cleanest way to do a lot of shared setup as we often have to do with things like issues belonging to milestones belonging to projects belonging to users.It's yet another thing we don't really have a standard for but should discuss further - /cc @DouweM
@stanhu Also you can leave your last commit as-is. Think this is good to merge now?
mentioned in commit f593b621