I
I
Ivan Vekov2018-05-03 16:31:20
PHP
Ivan Vekov, 2018-05-03 16:31:20

Why doesn't git commit work in shell_exec()?

You need to run the git command from a php script. Other commands work fine, namely commit does nothing and doesn't output anything.
That is, if I do:

$git_branches = shell_exec('git add ../'.$_GET["FILE"]);

That's all great.
If I do:
$git_branches = shell_exec("git commit -m '".$_GET["COMMIT_TITLE"]."'");

I get emptiness.
To get at least some information, he had the correct location, etc., I tried this option:
$git_branches = shell_exec("cd ".$_SERVER["DOCUMENT_ROOT"]." && ls -la && git commit -m '".$_GET["COMMIT_TITLE"]."'");
pre($git_branches);

Displays a list of files and directories from the project root, everything is as it should be. Therefore, it tries to make a commit from there, again, as I need. But the commit command itself doesn't work.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Ivan Vekov, 2018-05-04
@vekov

For debugging, you should use the following scheme:
That is, we change shell_exec to exec, and add "2>&1"; Then we can see the errors.
The commit command itself did not work, because the user was incorrectly specified in the config. And because the user did not have enough rights. Made him the owner of the .git folder. Problem solved

L
Lander, 2018-05-03
@usdglander

$git_branches = shell_exec('git commit -m "'.$_GET["COMMIT_TITLE"].'"');

So try. Perhaps git is sensitive to the type of quotes. But it is not exactly.

A
Andrey, 2018-08-10
@flx12

$str = 'git -c user.email="email" -c user.name="login" commit -m "message"';
exec($str,$stdin,$stderr);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question