0

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

I am developing a pre-commit hook for the git, modeling the situation when the developer went to his sub-module on his local car - changed the file - went back to the parent project and made git add. and git commit after which this hook worked. The whole text of the hook does not matter, leaving only the desired part.

Using git submodule foreach
1) appeal to the submodule
2) I index changes
3) make a commit Actually, when I work out a hook, I see that a new commit was created in the submodule In 4 steps I try to index 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 fall into the commit
2) that there are new commits in the submodule and you need to update (??????) and that there are no changes that will fall into the commit Changes to the server do not arrive as can be seen from the screen number 1

https://b.radikal.ru/b12/1812/1b/7d23ee4e948b.jpg

On the screen number 2 I am running git status to see these messages again, but there is only one message left - everything is ready and indexed - to commit

https://d.radikal.ru/d13/1812/ad/7c2201d4f68d.jpg

On screen 3, I perform the commit again and then the commit appears in the parent project

https://b.radikal.ru/b36/1812/2c/3e133ddf3a45.jpg

The question is why it does not work out the first time? Rummaged the whole stackover. Only started working with submodules. I hope for your help.

Sorry for links, stack tell about 10 reputation.

F3ns
  • 36
  • 4

1 Answers1

0

I still found the reason why this happens. The fact is that git add in pre-commit does not work in every version and there is a lot of discussion on this.

Git add in pre-commit hook not staging file for commit

His frequent behavior is that he indexes the changes, but they will only fall into the next commit. Ie you have two contradictory messages at once that the changes are indexed and at the same time that there are new changes, but they are not indexed. Just want to add that I spent 2 days searching for an answer.

F3ns
  • 36
  • 4