Cherry picking REUC fixes

Cherry picking https://github.com/libgit2/libgit2/pull/1591 which was reverted after merging https://github.com/libgit2/libgit2/pull/1593.  Isn't this what automerge is supposed to handle for us?  :/