diff --git a/lib/kamal/commands/builder/clone.rb b/lib/kamal/commands/builder/clone.rb index 17d9c931..a186c7b2 100644 --- a/lib/kamal/commands/builder/clone.rb +++ b/lib/kamal/commands/builder/clone.rb @@ -1,29 +1,31 @@ module Kamal::Commands::Builder::Clone - extend ActiveSupport::Concern - - included do - delegate :clone_directory, :build_directory, to: :"config.builder" - end - def clone - git :clone, Kamal::Git.root, "--recurse-submodules", path: clone_directory + git :clone, escaped_root, "--recurse-submodules", path: config.builder.clone_directory.shellescape end def clone_reset_steps [ - git(:remote, "set-url", :origin, Kamal::Git.root, path: build_directory), - git(:fetch, :origin, path: build_directory), - git(:reset, "--hard", Kamal::Git.revision, path: build_directory), - git(:clean, "-fdx", path: build_directory), - git(:submodule, :update, "--init", path: build_directory) + git(:remote, "set-url", :origin, escaped_root, path: escaped_build_directory), + git(:fetch, :origin, path: escaped_build_directory), + git(:reset, "--hard", Kamal::Git.revision, path: escaped_build_directory), + git(:clean, "-fdx", path: escaped_build_directory), + git(:submodule, :update, "--init", path: escaped_build_directory) ] end def clone_status - git :status, "--porcelain", path: build_directory + git :status, "--porcelain", path: escaped_build_directory end def clone_revision - git :"rev-parse", :HEAD, path: build_directory + git :"rev-parse", :HEAD, path: escaped_build_directory + end + + def escaped_root + Kamal::Git.root.shellescape + end + + def escaped_build_directory + config.builder.build_directory.shellescape end end diff --git a/test/commands/builder_test.rb b/test/commands/builder_test.rb index e5daddfd..1fc224da 100644 --- a/test/commands/builder_test.rb +++ b/test/commands/builder_test.rb @@ -149,15 +149,26 @@ class CommandsBuilderTest < ActiveSupport::TestCase assert_equal "docker info --format '{{index .RegistryConfig.Mirrors 0}}'", command.first_mirror.join(" ") end + test "clone path with spaces" do + command = new_builder_command + Kamal::Git.stubs(:root).returns("/absolute/path with spaces") + clone_command = command.clone.join(" ") + clone_reset_commands = command.clone_reset_steps.map { |a| a.join(" ") } + + assert_match(%r{path\\ with\\ space}, clone_command) + assert_no_match(%r{path with spaces}, clone_command) + + clone_reset_commands.each do |command| + assert_match(%r{path\\ with\\ space}, command) + assert_no_match(%r{path with spaces}, command) + end + end + private def new_builder_command(additional_config = {}) Kamal::Commands::Builder.new(Kamal::Configuration.new(@config.deep_merge(additional_config), version: "123")) end - def build_directory - "#{Dir.tmpdir}/kamal-clones/app/kamal/" - end - def local_arch Kamal::Utils.docker_arch end