diff --git a/app/controllers/projects/application_controller.rb b/app/controllers/projects/application_controller.rb index ba523b190bf..db33b60b229 100644 --- a/app/controllers/projects/application_controller.rb +++ b/app/controllers/projects/application_controller.rb @@ -18,7 +18,7 @@ class Projects::ApplicationController < ApplicationController # to # localhost/group/project # - if id =~ /\.git\Z/ + if params[:format] == 'git' redirect_to request.original_url.gsub(/\.git\/?\Z/, '') return end diff --git a/changelogs/unreleased/git_to_html_redirection.yml b/changelogs/unreleased/git_to_html_redirection.yml new file mode 100644 index 00000000000..b2959c02c07 --- /dev/null +++ b/changelogs/unreleased/git_to_html_redirection.yml @@ -0,0 +1,4 @@ +--- +title: Redirect http://someproject.git to http://someproject +merge_request: +author: blackst0ne diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index 9323f723bdb..e7aa8745b99 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -213,6 +213,17 @@ describe ProjectsController do expect(response.status).to eq 404 end end + + context "redirection from http://someproject.git" do + it 'redirects to project page (format.html)' do + project = create(:project, :public) + + get :show, namespace_id: project.namespace.path, id: project.path, format: :git + + expect(response).to have_http_status(302) + expect(response).to redirect_to(namespace_project_path) + end + end end describe "#update" do