hello group,
I encountered an unexpected feature of capistrano. When I test a file or directory with 'if test [ -d .....]', in a within block, the directory of that test is based on the working directory instead of the directory in the within block.
Who can explain what happens?
The following Capfile illustrates this; the second task is the most readable, but does not work as I expect. The first, in which the file test is done outside the within block, is a working version of it. Has this anything to do with the ssh toolkit? Can I use the second task by adjusting the used syntax?
require 'capistrano/setup'
require 'capistrano/deploy'
namespace :rbg do
desc 'check git directory'
task :check_gitdir do
on roles :installatie, :test do
if test ( "[ -d " + fetch( :deploy_to) + "/.git ]" )
info " git-dir exists"
else
info " git-dir does not exist"
within deploy_to do
execute :git, 'init'
end
end
end
end
task :check_gitdir_doesn_work do
on roles :installatie, :test do
within deploy_to do
if test "[ -d .git ]"
info " git-dir exists"
else
info " git-dir does not exist"
execute :git, 'init'
end
end
end
end
end
Output of task 1 (correct) when applying this on a host with a .git directory within the deploy directory:
INFO git-dir exists
Output of task 2 in the same situation:
INFO git-dir does not exist
INFO [e64c94b6] Running /usr/bin/env git init as dep...@172.xx.xx.xx
INFO [e64c94b6] Finished in 0.238 seconds with exit status 0 (successful).
INFO [b45c3b5b] Running /usr/bin/env git remote add repo REPOSITORYNAME as .......
Thanks in advance for helping me understanding what is going on.
Ruud
--
You received this message because you are subscribed to the Google Groups "Capistrano" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capistrano+...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/capistrano/8d2bab9b-3355-43c3-be15-66a3e0606324%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
It's documented *somewhere*, I recall having written about why, the long and short version is "anything with a whitespace in it is not safe for us to modify, and prepend and append paths, commands, etc", that unfortunately also applies to test(), and of course there is no `test(:some, :symbol)` syntax that makes sense.
I'd suggest to use the `capture()` api to `capture(:pwd)`, and use Ruby's `File.join()` APIs (or, just concatenate the strings) to build the command to test for.
--
You received this message because you are subscribed to the Google Groups "Capistrano" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capistrano+...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/capistrano/6e349cd8-ddb0-40d4-836e-bf5c2d816c07%40googlegroups.com.
Thanks, it's something we've strugged with since v3, the new API is great, *if* your command is simple enough to concatenate. I think without going down the road of relational algebra for composing parts of commands, or writing a bash lexer/parser combo, i'll always struggle to work with anything with whitespaces in, and it really cheapens the user experience, unfortunately :( Any recommendations you can make of how we might fix the docs now that you know better how it works would be very welcome indeed.
I'd suggest to use the `capture()` api to `capture(:pwd)`, and use Ruby's `File.join()` APIs (or, just concatenate the strings) to build the command to test for.
`if test('[ ', '-d', '.git ]' )`
`if test(:test, '-d .git')`
--
You received this message because you are subscribed to the Google Groups "Capistrano" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capistrano+...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/capistrano/8bdb3ab1-01ff-4a25-8437-c4c2d5855cef%40googlegroups.com.