-
Notifications
You must be signed in to change notification settings - Fork 482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support spaces in git repository path #1066
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wondered what this was, and realized it has become unnecessary when tests still passed without it. |
||
def local_arch | ||
Kamal::Utils.docker_arch | ||
end | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This delegation becomes superfluous when we need to escape the values returned by
clone_directory
andbuild_directory
, so I just removed it. Inlinedconfig.builder.clone_directory.shellescape
in the single location it's needed, and factorizedconfig.builder.build_directory.shellescape
in theescaped_build_directory
method.