We use a git module with several submodules. In order to make it more convenient for daily use, I wanted to have a post-commit hook which automatically adds the submodule to the git index in the main/super/root git repo/clone/module such as git add mychangedsubmodulename
so as to prepare a commit ready to update the submodule's commit reference in the main repo and probably more ideas to come.
The .git folder is located inside the main module root folder and seems to contain as well the submodule related stuff as a result of having cloned the main repo with --recursive
option. My version of git is git version 2.6.4 (Apple Git-63)
.
I could easily create a post-commit hook in the main repo but it does not fire from commits within a submodule, which I consider correct and appropriate so far but also might be a clue for a possible workaround.
I have tried to define several post-commit hook files in different locations also following the question 10848191 without any success.
How can I achieve to automatically modify the main module on commits in a submodule?
Update: After the submodule post-commit hook now works sometimes, I managed to cd into the main repository and successfully invoke git by cleaning the environment variables.
# clear git environment or git would confuse main and sub repos when crossing boundary by only changing pwd
while read variable; do
unset $variable
done < <(env | grep "^GIT_" | sed 's/=.*//g')
However, the original question was as how to fire the submodule hook. This seems to be working only sometimes, still.