Handle legacy repository archive requests with no ref given

The legacy endpoint requires no reference and defaults to the root
ref.

Closes #45154
This commit is contained in:
Stan Hu 2018-04-08 05:47:54 -07:00
parent dd552d06f6
commit 5c735af3b5
2 changed files with 13 additions and 2 deletions

View File

@ -16,8 +16,10 @@ class Projects::RepositoriesController < Projects::ApplicationController
def archive
append_sha = params[:append_sha]
shortname = "#{@project.path}-#{@ref.tr('/', '-')}"
append_sha = false if @filename == shortname
if @ref
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
rescue => ex
@ -27,6 +29,9 @@ class Projects::RepositoriesController < Projects::ApplicationController
def assign_archive_vars
@id = params[:id]
return unless @id
@ref, @filename = extract_ref(@id)
rescue InvalidPathError
render_404

View File

@ -34,6 +34,12 @@ describe Projects::RepositoriesController do
expect(response.header[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("git-archive:")
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
before do
allow(Gitlab::Workhorse).to receive(:send_git_archive).and_raise("Archive failed")