23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/git_handler.rb', line 23
def export_branch(branch = 'master')
tmp_dir = "#{@options['target_directory']}/checkouts/#{branch}/.tmp_#{Time.now.strftime("%Y%m%d%H%M%S")}"
begin
repo = Git.clone(@options['repository'], tmp_dir, {:depth => 1})
repo.checkout("origin/#{branch}")
rescue Exception => e
FileUtils.rm_rf repo.dir.to_s unless repo.nil?
raise "Error while cloning #{@options['repository']}: #{e}"
end
@last_commit = repo.gcommit('HEAD').sha
commit_dir = "#{@options['target_directory']}/checkouts/#{branch}/#{@last_commit}"
Dir.chdir(repo.dir.to_s) { FileUtils.rm_r '.git' }
FileUtils.mv repo.dir.to_s, commit_dir
commit_dir
end
|