Class: Capistrano::Deploy::Strategy::CopySmart

Inherits:
Copy
  • Object
show all
Defined in:
lib/capistrano/recipes/deploy/strategy/copy_smart.rb

Instance Method Summary collapse

Instance Method Details

#deploy! ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/capistrano/recipes/deploy/strategy/copy_smart.rb', line 8

def deploy!
  FileUtils.mkdir_p(destination)

  logger.trace "parsing the content of .gitignore"
  files_to_copy = `git ls-files`.split("\n")

  logger.trace "taking into account the untracked and deleted (but not staged) files"
  `git status --short --porcelain`.split("\n").each do |line|
    last_index = line.size
    files_to_copy << line[3..last_index]       if line[0..2] == "?? "  # file new
    files_to_copy.delete(line[3..last_index])  if line[0..2] == " D "  # file deleted
  end

  unless copy_exclude.empty?
    logger.trace "parsing exclusions defined by hand"
    files_without_excluded = []
    files_to_copy.each do |file|
      next if  copy_exclude.any? {|pattern| File.fnmatch(pattern, file) }
      files_without_excluded << file
    end
    files_to_copy = files_without_excluded
  end

  logger.trace "will copy #{files_to_copy.size} files from your working directory"

  files_to_copy.each do |file|
    file_dest_full_path = File.join(destination, file)
    FileUtils.mkdir_p(File.dirname(file_dest_full_path))  unless File.exists?(File.dirname(file_dest_full_path))
    FileUtils.cp(file, file_dest_full_path, { :preserve => true })
  end

  logger.trace "compressing #{destination} to #{filename}"
  Dir.chdir(copy_dir) { system(compress(File.basename(destination), File.basename(filename)).join(" ")) }

  distribute!
ensure
  FileUtils.rm filename  rescue nil
  FileUtils.rm_rf destination  rescue nil
end