7

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 :

#!/bin/sh
echo "Updating submodules recursively"
pwd
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 www-data@11.22.33.44:.
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

Louis Ameline
  • 2,779
  • 1
  • 25
  • 25

1 Answers1

9

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
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thank you very much, it works like a charm. I spent a lot of time looking for that answer. – Louis Ameline Feb 04 '14 at 11:19
  • Why it is necessary to cd in the folder, if you provide `--work-tree`? – Clijsters Nov 07 '17 at 17:55
  • @Clijsters 3 and a half years later, I am not too sure. And I would now write it `git -C /var/www submodule update --init --recursive` But maybe at the time, submodules needed to be used from the root folder only. – VonC Nov 07 '17 at 19:13
  • Yeah git told me you're right with some kind of error message. Thanks. This answer helped me out. Was just confused about it, as other git statements work out of the universe – Clijsters Nov 07 '17 at 19:15
  • I had the same issue, but -C didn't help. Wired. – Lev Aug 28 '20 at 15:25
  • @Lev Strange. Could you ask a separate question for me or others to have a look? – VonC Aug 28 '20 at 15:38
  • @VonC https://stackoverflow.com/questions/63637260/git-submodule-update-in-post-receive-hook-ignores-c – Lev Aug 28 '20 at 16:01