Skip to content
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

allow home by env as $HOME in paths #469

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,7 @@ appear at the top.

* Your contribution here!
* [#468](https://github.com/capistrano/sshkit/pull/468): Make `upload!` take a `:verbosity` option like `exec` does - [@grosser](https://github.com/grosser)
* [#469](https://github.com/capistrano/sshkit/pull/469): Fix a regression in 1.19.0 that prevented `$HOME` from being used in Capistrano paths, e.g. `:deploy_to`, etc. - [@Madogiwa0124](https://github.com/Madogiwa0124)

## [1.19.1][] (2019-07-02)

Expand Down
2 changes: 1 addition & 1 deletion lib/sshkit/command.rb
Expand Up @@ -221,7 +221,7 @@ def to_s

# allow using home directory but escape everything else like spaces etc
def self.shellescape_except_tilde(file)
file.shellescape.gsub("\\~", "~")
file.shellescape.gsub("\\~", "~").gsub("\\$HOME", "$HOME")
end

private
Expand Down
12 changes: 12 additions & 0 deletions test/unit/backends/test_abstract.rb
Expand Up @@ -111,6 +111,18 @@ def test_within_home
assert_equal 'cd ~/foo && /usr/bin/env cat file', backend.executed_command.to_command
end

def test_within_home_by_env
backend = ExampleBackend.new do
within '$HOME/foo' do
execute :cat, 'file', :strip => false
end
end

backend.run

assert_equal 'cd $HOME/foo && /usr/bin/env cat file', backend.executed_command.to_command
end

def test_background_logs_deprecation_warnings
deprecation_out = ''
SSHKit.config.deprecation_output = deprecation_out
Expand Down
5 changes: 5 additions & 0 deletions test/unit/test_command.rb
Expand Up @@ -89,6 +89,11 @@ def test_working_in_home_directory
assert_equal "cd ~/sites && /usr/bin/env ls -l", c.to_command
end

def test_working_in_home_directory_by_env
c = Command.new(:ls, '-l', in: "$HOME/sites")
assert_equal "cd $HOME/sites && /usr/bin/env ls -l", c.to_command
end

def test_working_in_a_given_weird_directory
c = Command.new(:ls, '-l', in: "/opt/sites and stuff")
assert_equal "cd /opt/sites\\ and\\ stuff && /usr/bin/env ls -l", c.to_command
Expand Down