-
-
Save demelziraptor/2717730 to your computer and use it in GitHub Desktop.
def archive | |
unless can?(current_user, :download_code, @project) | |
render_404 and return | |
end | |
ref = params[:ref] || @project.root_ref | |
commit = @project.commit(ref) | |
render_404 and return unless commit | |
# Build file path | |
file_name = @project.code + "-" + commit.id.to_s + ".zip" | |
storage_path = File.join(Rails.root, "tmp", "repositories", @project.code) | |
file_path = File.join(storage_path, file_name) | |
# Create file if not exists | |
unless File.exists?(file_path) | |
FileUtils.mkdir_p storage_path | |
cmd = "git --git-dir='#{@project.path_to_repo}' archive --format=zip -o #{file_path} #{ref}" | |
render_404 and return unless system(cmd) | |
end | |
# Send file to user | |
send_file file_path | |
end |
Hi,
I tryed this out but sadly it does not work with my current version (2.7.0).
Got the following error: Cannot spawn application '/opt/gitlabhq': The spawn server has exited unexpectedly.
I installed gitlab by following this tutorial: http://blog.phusion.nl/2012/04/21/tutorial-setting-up-gitlab-on-debian-6/
Which version of gitlab are you using? Or do you know any better workarounds for zip downloads in gitlab?
Greetings, Xiphe.
Ah, thanks for letting me know. I'm on 2.6.2 right now. I haven't seen any better workarounds yet, although I'm sure there should be some.
Will test on 2.7 when I upgrade in a few weeks.
Cool, i'd love to know when you got that to work :)
I've been looking for other solutions the last 3 days and have not found anything but yours.
Sadly i have absolutely no experience with ruby so it'm not able to debug it or make any suggestions :(
Although this is like 2 years old, but there is an even quicker hack (as of GitLab 4.0.1) by editing archive_repo() in app/roles/repository.rb:
Change:
file_name = self.path + "-" + commit.id.to_s + ".tar.gz"
To:
file_name = self.path + "-" + commit.id.to_s + ".zip"
And change:
file = self.repo.archive_to_file(ref, prefix, file_path)
To:
file = self.repo.archive_to_file(ref, prefix, file_path, "zip", "cat")
Replace archive function in app/controllers/repositories_controller.rb with this one.