| Q | A
| ----------------- | ---
| Issue Type | Feature Request
| Deployer Version | Any
| Local Machine OS | Any
| Remote Machine OS | Any
Remote run() commands use the working_path option to ensure that commands are always executed from within the same directory (unless the recipes says otherwise).
Anything run locally with runLocally() always "inherits" the cwd of Deployer's PHP process, which depends on which folder the user is in when running the recipe. This can lead to different results when dep is being used inside of a different directory.
As a user, I would expect that all local commands would be running relative to deploy.php but this does not seem to be the case.
Consider the following recipe:
<?php declare(strict_types = 1);
namespace Deployer;
require 'recipe/common.php';
// Hosts
host('example.com');
task('test', function() {
output()->write(runLocally('pwd'));
});
Running /path/to/dep test will produce different output depending on which directory I'm currently cded into. This could cause issues for commands like rm -rf some/relative/path.
My first proposal is to introduce a new default option named cwd which is passed to the new Process() constructor inside of ProcessRunner::run(). This value would default to the directory containing the deploy.php file. As a result, all local commands would run inside of / relative to that file.
This would introduce a similar level of consistency that run() commands enjoy.
If a user wants their cwd to be something different they can simply set() the option to something else.
The downside is that this would technically break backwards-compatibility for anyone relying on Deployer to run local commands relative to where dep deploy is invoked.
Instead of forcing everyone into this new functionality, we could default the cwd option to null but still pass in get('cwd') into the new Process() constructor. The null value will retain the current functionality but allow users to opt into the functionality described above using this in their recipe:
set('cwd', __DIR__);
The downside here is that everyone wanting this consistency needs to add some extra boilerplate and that a consistent cwd is not available by default as most users would expect.
I hope my proposal makes sense. Please let me know if I can better explain anything!
This is definitely should be fixed. I'll do it in next v7 release.
Done in master! Now cwd deault to deploy.php file dir! And also runLocally has 'cwd' option.
Most helpful comment
This is definitely should be fixed. I'll do it in next v7 release.