1

I have the following code

<?php

$output = `git status`;
var_dump($output);
die;

which gives me the right output, so why is it that when I do this, I get nothing?

<?php

$output = `git pull origin master`;
var_dump($output);
die;

For some reason that code is not getting executed, as the repository isn't updated after I make the call..

What is going on?

Enrique Moreno Tent
  • 24,127
  • 34
  • 104
  • 189

2 Answers2

3

The problem I was having is that the output was directed to stderr, not stdout. That is why I got no output. I fixed it with this:

<?php

$output = `git pull origin master 2>&1`;
var_dump($output);
die;
Enrique Moreno Tent
  • 24,127
  • 34
  • 104
  • 189
2

I believe I've come across this issue. When you are executing a Git command with PHP, it is worth resetting your working directory thus:

$output = `cd /path/to/project && git pull origin master`;

Also, bear in mind that the PATH you have on the console may not be used by PHP, so it may also be worth calling git using its fully-qualified path.

halfer
  • 19,824
  • 17
  • 99
  • 186