Commit a00c534c4c7921e40f58f714291a2bb09ad02225

Authored by Izaak Alpert
1 parent ce21d868

Fix a bug where the tgz returned got encoded utf8

Conflicts:
	doc/api/repositories.md

Change-Id: I7ebc39b47ff860813d9622ba6776583536e6e384
doc/api/repositories.md
... ... @@ -368,4 +368,4 @@ GET /projects/:id/repository/archive
368 368  
369 369 Parameters:
370 370 + `id` (required) - The ID of a project
371   -+ `sha` (optional) - The commit or branch name
  371 ++ `sha` (optional) - The commit sha to download defaults to the tip of the default branch
372 372 \ No newline at end of file
... ...
lib/api/repositories.rb
... ... @@ -181,7 +181,7 @@ module API
181 181 #
182 182 # Parameters:
183 183 # id (required) - The ID of a project
184   - # sha (optional) - the commit sha to download defaults to head
  184 + # sha (optional) - the commit sha to download defaults to the tip of the default branch
185 185 # Example Request:
186 186 # GET /projects/:id/repository/archive
187 187 get ":id/repository/archive" do
... ... @@ -190,11 +190,15 @@ module API
190 190 ref = params[:sha]
191 191 storage_path = Rails.root.join("tmp", "repositories")
192 192  
193   - file_path = repo.archive_repo(ref || 'HEAD', storage_path)
194   - if file_path
195   - data = File.open(file_path).read
  193 + file_path = repo.archive_repo(ref, storage_path)
  194 + if file_path && File.exists?(file_path)
  195 + data = File.open(file_path, 'rb').read
  196 +
  197 + header "Content-Disposition:", " infile; filename=\"#{File.basename(file_path)}\""
196 198 content_type 'application/x-gzip'
197   - header "Content-Disposition:"," infile; filename=\"#{File.basename(file_path)}\""
  199 +
  200 + env['api.format'] = :binary
  201 +
198 202 present data
199 203 else
200 204 not_found!
... ...