Commit e9947951 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'sh-handle-legacy-archive-requests' into 'master'

Handle legacy repository archive requests with no ref given

Closes #45154

See merge request gitlab-org/gitlab-ce!18246
parents 86ca1a77 5c735af3
...@@ -16,8 +16,10 @@ class Projects::RepositoriesController < Projects::ApplicationController ...@@ -16,8 +16,10 @@ class Projects::RepositoriesController < Projects::ApplicationController
def archive def archive
append_sha = params[:append_sha] append_sha = params[:append_sha]
shortname = "#{@project.path}-#{@ref.tr('/', '-')}" if @ref
append_sha = false if @filename == shortname shortname = "#{@project.path}-#{@ref.tr('/', '-')}"
append_sha = false if @filename == shortname
end
send_git_archive @repository, ref: @ref, format: params[:format], append_sha: append_sha send_git_archive @repository, ref: @ref, format: params[:format], append_sha: append_sha
rescue => ex rescue => ex
...@@ -27,6 +29,9 @@ class Projects::RepositoriesController < Projects::ApplicationController ...@@ -27,6 +29,9 @@ class Projects::RepositoriesController < Projects::ApplicationController
def assign_archive_vars def assign_archive_vars
@id = params[:id] @id = params[:id]
return unless @id
@ref, @filename = extract_ref(@id) @ref, @filename = extract_ref(@id)
rescue InvalidPathError rescue InvalidPathError
render_404 render_404
......
...@@ -34,6 +34,12 @@ describe Projects::RepositoriesController do ...@@ -34,6 +34,12 @@ describe Projects::RepositoriesController do
expect(response.header[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("git-archive:") expect(response.header[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("git-archive:")
end end
it 'handles legacy queries with no ref' do
get :archive, namespace_id: project.namespace, project_id: project, format: "zip"
expect(response.header[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("git-archive:")
end
context "when the service raises an error" do context "when the service raises an error" do
before do before do
allow(Gitlab::Workhorse).to receive(:send_git_archive).and_raise("Archive failed") allow(Gitlab::Workhorse).to receive(:send_git_archive).and_raise("Archive failed")
......
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