Automate the libgit2 compatibility check.

First, we should not check against LIBGIT2_SOVERSION, but check against the major and minor version numbers. Also, instead of hardcoding the compatible versions, we now use the minor and major version numbers from the bundled libgit2 version.