1

I'm trying to git pull from a PHP file, but it seems like the config isn't being used.

git config --global user.name and git config --global user.email are set and git pull works from the command line.

Now when I try to execute this script:

<?php

header('Content-type: text/plain');
system('git pull 2>&1');
echo "\nCompleted!";

I get the following output:

* Please tell me who you are.

Run

git config --global user.email "[email protected]" git config --global user.name "Your Name"

to set your account's default identity. Omit --global to set the identity only in this repository.

fatal: empty ident not allowed

Completed!

Is it maybe because the git config is user specfic and PHP is ran from another user?

4 Answers 4

2

Just use the -c flag on git itself:

-c <name>=<value>
Pass a configuration parameter to the command. The value given will override values from configuration files. The <name> is expected in the same format
as listed by git config (subkeys separated by dots).

So something like:

git -c user.name=apache pull

should get you there. Add whatever arguments you need. If you want to specify a particular file, then either add the relevant configuration options to the user executing the script, or hack around it by exporting a different HOME env variable first.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I'm using system('/usr/bin/env -i HOME=/home/myself git pull 2>&1'); now.
0

You expect your webserver to work even when you are not logged in, don't you? This means it is run by another user than you (unless you specified otherwise). Unless you run your script via the CLI, the script is run by apache, www-data or whatever user you configured.

Comments

0

I managed to get it working, but it's not an ideal solution. I need to find a way to set the git config for the apache user once, instead of every time. I'm on shared host, so I don't know if it's actually possible.

<?php

header('Content-type: text/plain');
system('git config user.name "Server"');
system('git config user.email "[email protected]"');
system('git pull 2>&1');
echo "\nCompleted!";

Comments

0

It's a bit of kludge, but you can also set the system git config:

git config --system user.name <user>
git config --system user.email <user>@<domain>

This has the rather unfortunate side effect of being the default config for all users of the server, so it really isn't very good.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.