This could use some C love. It's just some string mangling, no need to go in Ruby land. libgit2/libgit2#1810 could help a bit.