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

pwd is an empty array if already instantiated #307

Merged
merged 2 commits into from
Dec 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ appear at the top.

* Add your entries below here, remember to credit yourself however you want
to be credited!
* make sure working directory for commands is properly cleared after `within` blocks
[PR #307](https://github.com/capistrano/sshkit/pull/307)
@steved

## 1.8.1

Expand Down
10 changes: 9 additions & 1 deletion lib/sshkit/backends/abstract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,16 @@ def create_command_and_execute(args, options)
command(args, options).tap { |cmd| execute_command(cmd) }
end

def pwd_path
if @pwd.nil? || @pwd.empty?
nil
else
File.join(@pwd)
end
end

def command(args, options)
SSHKit::Command.new(*[*args, options.merge({in: @pwd.nil? ? nil : File.join(@pwd), env: @env, host: @host, user: @user, group: @group})])
SSHKit::Command.new(*[*args, options.merge({in: pwd_path, env: @env, host: @host, user: @user, group: @group})])
end

end
Expand Down
14 changes: 14 additions & 0 deletions test/unit/backends/test_abstract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@ def test_capture_supports_disabling_strip
assert_equal "Some stdout\n ", output
end

def test_within_properly_clears
backend = ExampleBackend.new do
within 'a' do
execute :cat, 'file', :strip => false
end

execute :cat, 'file', :strip => false
end

backend.run

assert_equal '/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