I am attempting to write an update
hook for git that bounces if a submodule is being updated to a commit ID that does not exist in the submodule's upstream repository. To say it another way, I want to force users to push changes to the submodule repositories before they push changes to the submodule pointers.
One caveat:
I have been playing around with an idea but it feels like there must be a better way to do this. Here is what I was planning on doing in the update hook:
refs/heads/
. If not, exit early.git rev-list
to get a list of revisions being pushed.git show
and use a regular expression that looks to see if a submodule was updated (by searching for `+Subproject commit [0-9a-f]+)..gitmodules
files as seen by that particular commit (git show :.gitmodules
).cd
to the paths found in 3.4 and execute git rev-parse --quiet --verify
to see if that commit exists in that repository. If it does not, exit with a non-zero status.(Note: I believe the results of 3.2 can potentially be cached across revisions as long as the output to git rev-parse --quiet --verify
doesn't change from one revision to the next. I left this part out to simplify the solution.)
So yeah, this seems pretty complex, and I can't help but wonder if there are some internal git commands that might make my life a lot easier. Or maybe there is a different way to think about the problem?