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

Fix ssh task escaping #708

Merged
merged 2 commits into from
Jan 9, 2022
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
2 changes: 1 addition & 1 deletion spec/support/outputs/ssh.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ssh localhost -p 22 -tt 'cd .*/deploy && exec \$SHELL'
cd .*/deploy && exec \$SHELL
23 changes: 11 additions & 12 deletions spec/tasks/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,20 @@
end

describe 'ssh' do
it 'runs ssh when :deploy_to exists' do
allow(Kernel).to receive(:exec)

task.invoke

expect(Kernel).to have_received(:exec).with(output_file('ssh'))
it 'opens an SSH connection when :deploy_to exists' do
expect do
invoke_all
end.to change { Mina::Configuration.instance.fetch(:execution_mode) }.to(:exec)
.and output(output_file('ssh')).to_stdout
end

it "exits with an error if :deploy_to doesn't exist" do
deploy_to = Mina::Configuration.instance.remove(:deploy_to)
it "exits with an error message when :deploy_to isn't set" do
Mina::Configuration.instance.remove(:deploy_to)

expect { task.invoke }.to raise_error(SystemExit)
.and output(/deploy_to must be defined!/).to_stdout

Mina::Configuration.instance.set(:deploy_to, deploy_to)
expect do
invoke_all
end.to raise_error(SystemExit)
.and output(/deploy_to must be defined!/).to_stdout
end
end

Expand Down
7 changes: 5 additions & 2 deletions tasks/mina/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,11 @@
end
end

desc 'Opens an SSH session and positions to :deploy_to folder'
desc 'Open an SSH connection and position to :deploy_to folder'
task :ssh do
ensure!(:deploy_to)
Kernel.exec %(#{Mina::Backend::Remote.new(nil).ssh} 'cd #{fetch(:deploy_to)} && exec $SHELL')

set :execution_mode, :exec

command "cd #{fetch(:deploy_to)} && exec $SHELL"
end