1

We have a PHP script which consists of nothing but the following code...

/usr/bin/git pull

...we originally were using just git pull.

Whenever GitHub posts data to this script the git pull fails. We've tried using http://us2.php.net/manual/en/function.shell-exec.php and storing the response in a variable and writing the content of that variable into a text file so we could make sure commands were being executed - and they were! We could execute for example git log and the text file would have all content of the git log response. But executing git pull just doesn't work?

Our server engineers suggested using the full path to the git install (using which git to find the path) and that is what you see above, but that too didn't work.

We're confused as to why we can execute git commands such as git log when GitHub's post-hook calls our script but yet git pull doesn't work?

Does any one have any ideas on why this wouldn't work?

Thanks.

Integralist
  • 2,161
  • 1
  • 32
  • 50
  • Can you post the entire script? – Waynn Lue Mar 16 '12 at 10:47
  • 2
    @starlocke "the solution must be to hire new server engineers, right?" yes that would be nice :-) – Integralist Mar 16 '12 at 13:52
  • @WaynnLue the entire script? The php script is literally just `/usr/bin/git pull` that was the entire script (because the command is wrapped in backticks PHP treats the line as a shell command rather than PHP code). So we're using PHP to trigger a shell command and the PHP script is called by a GitHub trigger (which occurs when we push changes to GitHub). We have found that we can execute `git log` & `git status` but not `git pull` or similar commands like `git fetch`. I'm thinking there must be a PHP permission issue somewhere but why allow `git log` or `git status` and not `git pull`? – Integralist Mar 16 '12 at 13:57
  • What I don't understand is why... (a) this is a post-hook issue [which hook, exactly?] (b) this a php issue instead of a bash script issue [hook scripts are normally typically bash scripts] (c) why your php script is so incomplete [where is the " – starlocke Mar 16 '12 at 16:08
  • @starlocke A) ok the title is incorrect, but I would have hoped the explanation in the actual body of the text would have clarified for readers B) this is effectively a server issue where a PHP script can execute certain git commands and not others - in this case not executing `git pull` C) if you want me to add the `` open/close tags I can, but I honestly didn't think that was going to be a big deal for people. If you say "I have a PHP script, here it is" you don't normally expect the ``. Similar in JavaScript ppl pasting code dont include the ` – Integralist Mar 17 '12 at 19:52
  • 1
    In my case, the apache user which handles the php GET/POST didnt have permissions to create/modify files based on the git pull. The solution I've seen from others is to create a flag file based on that GET/POST with php, then use a separate shell script/cron to check for that flag and then kick off the pull. – Paul Irish Mar 24 '12 at 19:19

1 Answers1

0

make sure the code is being executed as a user with sufficient privileges. You can confirm this by running whoami in the script that tries to pull with git

Lloyd Moore
  • 3,117
  • 1
  • 32
  • 32