Created
May 17, 2012 09:28
-
-
Save demelziraptor/2717730 to your computer and use it in GitHub Desktop.
Dirty hack to get gitlab archive download to use zip rather than tar.gz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
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")
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.