How to capture git's output in drush make? We use drush to clone a number of git-repositories during build. Most of the time this "just works", but on (a rare) occasion, a cloning fails.

Unfortunately, all that we get from drush in such cases is:


  Unable to clone repository                                 [error]


The DRUSH_BACKEND piece of JSON is shown, but claims no error ("error":null):

DRUSH_BACKEND:{"type":"notice","message":"Command dispatch complete","timestamp":1411582254.5773,"memory":10891736,"error":null,"packet":"log"}


The actual error message generated by the git-executable is not shown. Is there a way to change that? Simply adding --debug to drush's command line does not do it...

This question may not even be drush-make specific -- the spawning of external programs and capturing their stdout/stderr may be a generic drush thing...

Thank you!
Ok, the short answer is: it is not possible. Not at the moment. Although the code in includes/exec.inc is prepared to output the captured stdout and stderr of the command, it will only do so, if DRUSH_DEBUG is set:

  exec($command . ' 2&gt;&amp;1', $output, $result);
  _drush_shell_exec_output_set($output);

  if (drush_get_context('DRUSH_DEBUG')) {
    foreach ($output as $line) {
      drush_print($line, 2);
    }
  }


The only way to set DRUSH_DEBUG is by giving the --debug flag on drush command-line (it can not be set from drushrc.php). Sadly, in a number of cases -- including git-invocations -- the top-level drush invokes a child drush to do the actual work. It is doing so without passing the --debug flag to it...

I filed a ticket with drush-maintainers and implemented a work-around. We replaced the real git executable with a shell-wrapper, which captures stderr of the real git (and some other info, like environment veriables) into a log-file, then feeds the captured stderr to its own descriptor 2 -- just in case the caller cares. Then, if the real git's exit-code is 0, the log is deleted, otherwise it is retained for investigation.