From 63dc80212ee8b2c0b35430eadb315d495396199a Mon Sep 17 00:00:00 2001 From: Madogiwa <17684091+Madogiwa0124@users.noreply.github.com> Date: Sat, 20 Jul 2019 23:28:35 +0900 Subject: [PATCH] allow home by env as $HOME in paths --- CHANGELOG.md | 1 + lib/sshkit/command.rb | 2 +- test/unit/backends/test_abstract.rb | 12 ++++++++++++ test/unit/test_command.rb | 5 +++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c1a64a2d..36409406 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/lib/sshkit/command.rb b/lib/sshkit/command.rb index 2dac6d1c..444633bc 100644 --- a/lib/sshkit/command.rb +++ b/lib/sshkit/command.rb @@ -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 diff --git a/test/unit/backends/test_abstract.rb b/test/unit/backends/test_abstract.rb index 9d8511f5..473be569 100644 --- a/test/unit/backends/test_abstract.rb +++ b/test/unit/backends/test_abstract.rb @@ -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 diff --git a/test/unit/test_command.rb b/test/unit/test_command.rb index 30964a16..af278686 100644 --- a/test/unit/test_command.rb +++ b/test/unit/test_command.rb @@ -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