shell_exec
is going to return NULL
if the command fails. This is almost certainly happening... the question is why. You aren't going to be able to find out using shell_exec
.
I'd recommend instead using exec, so you can at least figure out the status of the call and what's going wrong.
http://www.php.net/manual/en/function.exec.php
This will allow you to setup some vars that will be populated with the return values of the system's internal os call.
$shell_output = array();
$status = NULL;
if($_GET['action']=='add'){
$output = shell_exec('git add *',$shell_output,$status);
print_r($shell_output)
print_r($status);
}
if($_GET['action']=='commit'){
$output = shell_exec('git commit -m "'.$_POST["txt"].'" ',$shell_output,$status);
print_r($shell_output)
print_r($status);
}
My guess is you have a problem with permissions. A commit
in git requires write permission to that directory's '.git' folder.
Also, make sure you are operating in the proper directory! The apache user that is running the PHP instance may or may not be already cd
ed to the right folder where the repo is. You may need to add a cd path_to_repo && git commit
to your command to first move to the right directory. I'd first debug this with absolute paths.
Just a word of advice as well... if you are trying to set up a PHP based git client, you are going to have to handle a ton of fail cases, one of which is readily apparent in this code... attempting a commit when no new files have been modified. I'd encourage you to look at community solutions if you need to be concerned with these cases:
Is there a good php git client with http support?