Reworked libgit2 usage.

Should now be much closer to the results obtained when cloning and
pulling with Git, hopefully avoiding the weird bug reports I've been
getting.

Now, if the repo doesn't exist, it is cloned, and if it does exist, the
existence of a local branch is ensured, HEAD is updated to point to it
correctly, and detached more robustly during roll-back.

'Only' thing left to implement is updating the local branch, if it
exists, to match the remote branch it tracks.
Seems to fix a weird crash during updating.