Shell_exec not working with git commit

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jateeq
Forum Newbie
Posts: 14
Joined: Mon Mar 01, 2010 12:16 pm

Shell_exec not working with git commit

Post by jateeq »

Hello,

I am trying to execute a git commit command through php's shell_exec function, but it just doesn't do anything: nothing is output, the apache error log does not record an error, and if i paste the exact command in the cli then git does commit to the repository. I know this is not a privilege or permissions error since the repository belongs to the web server, and the file permissions are set to 777 (not that it matters). In addition, I am able to run the git checkout and git add commands, but only git commit fails (yet).

My code:
//stage files and then do the following
$command = "git commit -m 'I have modified a file'
shell_exec($command);
header('location: index.php');

If anyone has any ideas, type away!

PS: I believe this is an error pertinent to php, not git, hence my post in this section. I apologise if this ends up being more relevant to git.

Thank you,
Jawad.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Shell_exec not working with git commit

Post by VladSun »

Try

Code: Select all

$command = "git commit -m 'I have modified a file ' 2>&1";
echo shell_exec($command);
exit();
There are 10 types of people in this world, those who understand binary and those who don't
jateeq
Forum Newbie
Posts: 14
Joined: Mon Mar 01, 2010 12:16 pm

Re: Shell_exec not working with git commit

Post by jateeq »

What does the '2>&1' do? I tried echoing without it, and it was blank, but with it the shell_exec command tells me that the commit_editmsg file does not belong to the webserver (permissions always screw me up somehow). So that's why only the commit command was affected. Great, it works now!

Thanks,
Jawad.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Shell_exec not working with git commit

Post by VladSun »

There are 10 types of people in this world, those who understand binary and those who don't
Post Reply