Skip to content

Commit 493c569

Browse files
authored
Merge pull request #1066 from davidstosik/v2.1.1/path-space-fix
Support spaces in git repository path
2 parents 5de55a2 + 8d6d7ff commit 493c569

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

lib/kamal/commands/builder/clone.rb

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
module Kamal::Commands::Builder::Clone
2-
extend ActiveSupport::Concern
3-
4-
included do
5-
delegate :clone_directory, :build_directory, to: :"config.builder"
6-
end
7-
82
def clone
9-
git :clone, Kamal::Git.root, "--recurse-submodules", path: clone_directory
3+
git :clone, escaped_root, "--recurse-submodules", path: config.builder.clone_directory.shellescape
104
end
115

126
def clone_reset_steps
137
[
14-
git(:remote, "set-url", :origin, Kamal::Git.root, path: build_directory),
15-
git(:fetch, :origin, path: build_directory),
16-
git(:reset, "--hard", Kamal::Git.revision, path: build_directory),
17-
git(:clean, "-fdx", path: build_directory),
18-
git(:submodule, :update, "--init", path: build_directory)
8+
git(:remote, "set-url", :origin, escaped_root, path: escaped_build_directory),
9+
git(:fetch, :origin, path: escaped_build_directory),
10+
git(:reset, "--hard", Kamal::Git.revision, path: escaped_build_directory),
11+
git(:clean, "-fdx", path: escaped_build_directory),
12+
git(:submodule, :update, "--init", path: escaped_build_directory)
1913
]
2014
end
2115

2216
def clone_status
23-
git :status, "--porcelain", path: build_directory
17+
git :status, "--porcelain", path: escaped_build_directory
2418
end
2519

2620
def clone_revision
27-
git :"rev-parse", :HEAD, path: build_directory
21+
git :"rev-parse", :HEAD, path: escaped_build_directory
22+
end
23+
24+
def escaped_root
25+
Kamal::Git.root.shellescape
26+
end
27+
28+
def escaped_build_directory
29+
config.builder.build_directory.shellescape
2830
end
2931
end

test/commands/builder_test.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,26 @@ class CommandsBuilderTest < ActiveSupport::TestCase
149149
assert_equal "docker info --format '{{index .RegistryConfig.Mirrors 0}}'", command.first_mirror.join(" ")
150150
end
151151

152+
test "clone path with spaces" do
153+
command = new_builder_command
154+
Kamal::Git.stubs(:root).returns("/absolute/path with spaces")
155+
clone_command = command.clone.join(" ")
156+
clone_reset_commands = command.clone_reset_steps.map { |a| a.join(" ") }
157+
158+
assert_match(%r{path\\ with\\ space}, clone_command)
159+
assert_no_match(%r{path with spaces}, clone_command)
160+
161+
clone_reset_commands.each do |command|
162+
assert_match(%r{path\\ with\\ space}, command)
163+
assert_no_match(%r{path with spaces}, command)
164+
end
165+
end
166+
152167
private
153168
def new_builder_command(additional_config = {})
154169
Kamal::Commands::Builder.new(Kamal::Configuration.new(@config.deep_merge(additional_config), version: "123"))
155170
end
156171

157-
def build_directory
158-
"#{Dir.tmpdir}/kamal-clones/app/kamal/"
159-
end
160-
161172
def local_arch
162173
Kamal::Utils.docker_arch
163174
end

0 commit comments

Comments
 (0)