Skip to content

Commit ef1186e

Browse files
committed
Merge pull request #307 from steved/steved/local_within
pwd is an empty array if already instantiated
2 parents ff80cb6 + 5fa154f commit ef1186e

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ appear at the top.
77

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

1114
## 1.8.1
1215

lib/sshkit/backends/abstract.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,16 @@ def create_command_and_execute(args, options)
121121
command(args, options).tap { |cmd| execute_command(cmd) }
122122
end
123123

124+
def pwd_path
125+
if @pwd.nil? || @pwd.empty?
126+
nil
127+
else
128+
File.join(@pwd)
129+
end
130+
end
131+
124132
def command(args, options)
125-
SSHKit::Command.new(*[*args, options.merge({in: @pwd.nil? ? nil : File.join(@pwd), env: @env, host: @host, user: @user, group: @group})])
133+
SSHKit::Command.new(*[*args, options.merge({in: pwd_path, env: @env, host: @host, user: @user, group: @group})])
126134
end
127135

128136
end

test/unit/backends/test_abstract.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,20 @@ def test_capture_supports_disabling_strip
7777
assert_equal "Some stdout\n ", output
7878
end
7979

80+
def test_within_properly_clears
81+
backend = ExampleBackend.new do
82+
within 'a' do
83+
execute :cat, 'file', :strip => false
84+
end
85+
86+
execute :cat, 'file', :strip => false
87+
end
88+
89+
backend.run
90+
91+
assert_equal '/usr/bin/env cat file', backend.executed_command.to_command
92+
end
93+
8094
def test_background_logs_deprecation_warnings
8195
deprecation_out = ''
8296
SSHKit.config.deprecation_output = deprecation_out

0 commit comments

Comments
 (0)