I don't think the code change which provided the reference implementation for JGit can be readily reused or reworked to support reference repositories for submodules.
I think the core challenge is already indicated in your bash-style pseudocode. As far as I can tell, you assume the reference repository for each submodule must be at $refdir/$repo. My assumption is that is not general enough compared to the needs of the 50,000+ installations of git.
I think adding reference support to submodules includes some of the same challenges as are represented in
JENKINS-20941. That request asks for credential support.
In the case of both credentials and reference repositories, we need to map a repository URL to something, and use that "something" in a later git command. I think git credentials with submodules might use the existing credentials system to attempt to choose a credential for the repository. That won't work all the time, but might be good enough. Reference repositories need to map a submodule repository URL to a local directory which contains the reference repository.
Another approach would be to try to apply Jesse Glick's pattern of reference repository from the Mercurial plugin. I believe he creates a local clone of the repository on the Jenkins master server, then clones to slaves from the Jenkins master server. We might even want to extend it to clone a reference repository onto the slave node when a job runs.
All those alternatives have some complications which will make them challenging.