Commit 45512b2c authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Fix double render in project's git URL redirect

When you visit the git URL of a project using a browser, we redirect to
the project's URL without the git suffix.

When a project is moved, visiting the old URL results in a 500 because
we're redirecting twice in a single before_action.

Changelog: fixed
MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/62053
parent 3a95b615
......@@ -510,7 +510,7 @@ class ProjectsController < Projects::ApplicationController
# `project` calls `find_routable!`, so this will trigger the usual not-found
# behaviour when the user isn't authorized to see the project
return unless project
return if project.nil? || performed?
redirect_to(request.original_url.sub(%r{\.git/?\Z}, ''))
end
......
......@@ -375,6 +375,23 @@ RSpec.describe ProjectsController do
end
end
context 'when project is moved and git format is requested' do
let(:old_path) { project.path + 'old' }
before do
project.redirect_routes.create!(path: "#{project.namespace.full_path}/#{old_path}")
project.add_developer(user)
sign_in(user)
end
it 'redirects to new project path' do
get :show, params: { namespace_id: project.namespace, id: old_path }, format: :git
expect(response).to redirect_to(project_path(project, format: :git))
end
end
context 'when the project is forked and has a repository', :request_store do
let(:public_project) { create(:project, :public, :repository) }
let(:other_user) { create(:user) }
......
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