git submodule pull and commit automatically on webserver

Posted by Lukas Oppermann on Stack Overflow See other posts from Stack Overflow or by Lukas Oppermann
Published on 2012-10-02T10:43:56Z Indexed on 2012/10/03 3:37 UTC
Read the original article Hit count: 194

Filed under:
|
|

I have the following setup, I am working on a project project with the submodule submodule. Whenever I push changes to github it sends a post request to update.php on the server.

This php file executes a git command. Without submodules I can just do a git pull and everything is fine but with submodules it is much more difficult.

I have this at the moment, but it does not do what I want. I should git pull the repo and update and pull the latest version of each submodule.

<?php echo `git submodule foreach 'git checkout master; git pull; 
git submodule update --init --recursive; git commit -m "updating"' && git pull && 
git submodule foreach 'git add -A .' 
&& git commit -m "updating to latest version including submodules" 2>&1s`;

EDIT// Okay, I got it half way done.

<?php echo `git submodule foreach 'git checkout master; git pull; 
git submodule update --init --recursive; git commit -am "updating"; echo "updated"' && 
git pull &&  git commit -am "updating to latest version including submodules" && 
echo 'updated'`;

The echo prevents the script to stop because of non-zero returned. It works 100% fine when I run it from the console using php update.php.

When github initialized the file, or I run it from the browser it still does not work.

Any ideas?

© Stack Overflow or respective owner

Related posts about git

Related posts about github