Page 1 of 1

Shell_exec not working with git commit

Posted: Fri Mar 05, 2010 3:00 pm
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.

Re: Shell_exec not working with git commit

Posted: Fri Mar 05, 2010 3:30 pm
by VladSun
Try

Code: Select all

$command = "git commit -m 'I have modified a file ' 2>&1";
echo shell_exec($command);
exit();

Re: Shell_exec not working with git commit

Posted: Fri Mar 05, 2010 4:14 pm
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.

Re: Shell_exec not working with git commit

Posted: Fri Mar 05, 2010 4:27 pm
by VladSun