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 [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

1 Answer 1

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 
Sign up to request clarification or add additional context in comments.

7 Comments

Thank you very much, it works like a charm. I spent a lot of time looking for that answer.
Why it is necessary to cd in the folder, if you provide --work-tree?
@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.
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
I had the same issue, but -C didn't help. Wired.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.