diff --git a/lib/gitlab_git/repository.rb b/lib/gitlab_git/repository.rb index a862620..e93b47c 100644 --- a/lib/gitlab_git/repository.rb +++ b/lib/gitlab_git/repository.rb @@ -99,13 +99,35 @@ def discover_default_branch # Already packed repo archives stored at # app_root/tmp/repositories/project_name/project_name-commit-id.tag.gz # - def archive_repo(ref, storage_path) + def archive_repo(ref, storage_path, format = "tar.gz") ref = ref || self.root_ref commit = Gitlab::Git::Commit.find(self, ref) return nil unless commit + + extension = nil + git_archive_format = nil + pipe_cmd = nil + + case format + when "tar.bz2", "tbz", "tbz2", "tb2", "bz2" + extension = ".tar.bz2" + pipe_cmd = "bzip" + when "tar" + extension = ".tar" + pipe_cmd = "cat" + when "zip" + extension = ".zip" + git_archive_format = "zip" + pipe_cmd = "cat" + else + # everything else should fall back to tar.gz + extension = ".tar.gz" + git_archive_format = nil + pipe_cmd = "gzip" + end # Build file path - file_name = self.name.gsub("\.git", "") + "-" + commit.id.to_s + ".tar.gz" + file_name = self.name.gsub("\.git", "") + "-" + commit.id.to_s + extension file_path = File.join(storage_path, self.name, file_name) # Put files into a directory before archiving @@ -114,7 +136,7 @@ def archive_repo(ref, storage_path) # Create file if not exists unless File.exists?(file_path) FileUtils.mkdir_p File.dirname(file_path) - file = self.grit.archive_to_file(ref, prefix, file_path) + file = self.grit.archive_to_file(ref, prefix, file_path, git_archive_format, pipe_cmd) end file_path diff --git a/spec/repository_spec.rb b/spec/repository_spec.rb index 5828177..405fe1d 100644 --- a/spec/repository_spec.rb +++ b/spec/repository_spec.rb @@ -63,6 +63,34 @@ after { FileUtils.rm_r(archive) } it { archive.should match(/tmp\/gitlabhq.git\/gitlabhq-bcf03b5/) } + it { archive.should end_with ".tar.gz" } + it { File.exists?(archive).should be_true } + end + + describe :archive_zip do + let(:archive) { repository.archive_repo('master', '/tmp', 'zip') } + after { FileUtils.rm_r(archive) } + + it { archive.should match(/tmp\/gitlabhq.git\/gitlabhq-bcf03b5/) } + it { archive.should end_with ".zip" } + it { File.exists?(archive).should be_true } + end + + describe :archive_bz2 do + let(:archive) { repository.archive_repo('master', '/tmp', 'tbz2') } + after { FileUtils.rm_r(archive) } + + it { archive.should match(/tmp\/gitlabhq.git\/gitlabhq-bcf03b5/) } + it { archive.should end_with ".tar.bz2" } + it { File.exists?(archive).should be_true } + end + + describe :archive_fallback do + let(:archive) { repository.archive_repo('master', '/tmp', 'madeup') } + after { FileUtils.rm_r(archive) } + + it { archive.should match(/tmp\/gitlabhq.git\/gitlabhq-bcf03b5/) } + it { archive.should end_with ".tar.gz" } it { File.exists?(archive).should be_true } end