Skip to content
This repository was archived by the owner on May 12, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions lib/gitlab_git/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better put these lines under else case.


case format
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix indentation according to https://github.com/styleguide/ruby

case
when song.name == "Misty"
  puts "Not again!"
when song.duration > 120
  puts "Too long!"
when Time.now.hour > 21
  puts "It's too late"
else
  song.play
end

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
Expand All @@ -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
Expand Down
28 changes: 28 additions & 0 deletions spec/repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down