Added in caching of when the clone/pull/push occurred into a git config --local option with name "subrepo.lastpushcommitid$subdir"
With the use of this cached information, the merges will work!
As long as the subdir doesn't have any backslaches, the name will work. They'll probably need to be escaped with another backslash, though I didn't look into it too much as I figured a different path would be used due to feedback.
So, it turns out in some flows I made that HEAD^2 doesn't always exist, so I threw HEAD there as a backup.
Feel free to change! But this works for me as everything looks ship-shape.
Changed name of cached commit-id to subrepo.lastcommitid$(subdir) with some processing on subdir to ensure it is not rejected as a config key.
Fixed a bug where the cached commit-id wasn't being set (apparently --add was needed?).
Turns out git config --local --add didn't overwrite existing items as I had intended.
In the event of a subrepo-push, an upstream update (from elsewhere), then a subrepo-pull, the history rewrite would disconnect HEAD^ from all ancestry.  This commit includes a test for that case, by checking (after the merge in the subrepo-pull) if HEAD^ is equal to HEAD^2^, and not rewriting the history in that case. I am certain an improvement can be done here though, as the resulting "git subrepo pull" commit is different than normal and is quite messy.
On subrepo-pull if cache of last subrepo clone/push/pull doesn't exist, it is created for the clone/pull cases.
Added the rebase on subrepo-push back.