Fix for misleading "missing delta bases" error.

This addresses issue libgit2/issues/2721

Created a new pull request. The previous one got mixed with the fix for memory leak issue inadvertently.
Incorporated CR comments from @vmg on previous PR
I don't want to nitpick too much, but opening braces should go on the same line as the `if`