def copy_to(destination, submodules = false)
unless File.exist?(destination.join(".git"))
begin
SharedHelpers.filesystem_access(destination.dirname) do |p|
FileUtils.mkdir_p(p)
end
SharedHelpers.filesystem_access(destination) do |p|
FileUtils.rm_rf(p)
end
git_retry %(clone --no-checkout --quiet "#{path}" "#{destination}")
File.chmod(((File.stat(destination).mode | 0777) & ~File.umask), destination)
rescue Errno::EEXIST => e
file_path = e.message[%r{.*?(/.*)}, 1]
raise GitError, "Bundler could not install a gem because it needs to " \
"create a directory, but a file exists - #{file_path}. Please delete " \
"this file and try again."
end
end
SharedHelpers.chdir(destination) do
git_retry %(fetch --force --quiet --tags "#{path}")
git "reset --hard #{@revision}"
git_retry "submodule update --init --recursive" if submodules
end
end