Skip to content

Commit

Permalink
Merge pull request #307 from steved/steved/local_within
Browse files Browse the repository at this point in the history
pwd is an empty array if already instantiated
  • Loading branch information
leehambley committed Dec 18, 2015
2 parents ff80cb6 + 5fa154f commit ef1186e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
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

0 comments on commit ef1186e

Please sign in to comment.