F
F
F3NS2018-12-25 17:15:11
git
F3NS, 2018-12-25 17:15:11

How to commit in parent project with changes from submodule using pre-commit hook?

I am developing a pre-commit hook for git, simulating the situation when the developer went to the submodule on his local wheelbarrow - changed the file - returned to the parent project and did git add . and git commit after which this hook worked. The whole text of the hook does not matter, I will leave only the necessary part.
Screen 1 . 5c2239c2e1c84712226644.jpeg
Using git submodule foreach
1) accessing the submodule
2) indexing the changes
3) commit
Actually, when the hook is executed, I see that a new commit has been created in the submodule
Step 4, I try to index the changes in the parent project by simply git add deploy (this is the name of the submodule)
I see two messages at once
1) that the changes are indexed and they will be included in the commit
2) that new commits have appeared in the submodule and need to be updated (??????) and that there are no changes that will get into the commit
Changes to the server do not arrive as you can see from screenshot #1
In screenshot #2
I execute git status to see these again messages, but there is only one message left - everything is ready and indexed - commit
5c223a0a790d2371112504.jpegIn screenshot #3 , I commit again and then a commit appears in the parent project The
5c223a24dfa8d201984803.jpeg
question is why does this not work the first time? Rummaged through the entire stackover. Just started working with submodules. I hope for your help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
F3NS, 2018-12-26
@F3NS

I did find the reason why this is happening. The fact is that git add in pre-commit does not work in every version and there are many discussions on this matter.
https://stackoverflow.com/questions/51778574/git-a...
Its a frequent behavior it indexes the changes but they will only hit the next commit. That is, you immediately get two conflicting messages that the changes are indexed and at the same time that there are new changes, but they are not indexed. I just want to add that I spent 2 days looking for an answer.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question