Git Submodule Update From Post-receive Hook

- 1 answer

I'm trying to update automatically my submodule located in var/www/php/vendor/projectX at each commit to the var/www super-project. I added these lines in the .git/hooks/post-receive file :

echo "Updating submodules recursively"
git submodule update --init --recursive

But I get this when I commit to the super-project :

Counting objects: 8, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 346 bytes | 0 bytes/s, done.
Total 4 (delta 3), reused 0 (delta 0)

remote: Updating submodules recursively
remote: /var/www/.git
remote: No submodule mapping found in .gitmodules for path 'php/vendor/projectX'
To [email protected]:.
3dc2404..bc46dd6  dev -> dev

The appropriate section is present in the .gitmodules file however, and so are the files in .git/modules. Running git submodule update --init --recursive manually works fine. It's only when run from the hook that it does not work. Thank you



Try and :

  • cd to the root folder of that repo
  • specify the work-tree and git directory for that folder when doing the git command.

That would give in your post-receive hook script:

cd /var/www/
git --git-dir=/var/www/.git --work-tree=/var/www submodule update --init --recursive