Fix git prune order in zuul-cloner

The prune() operation relies on `git branch -d -r` to remove remote
branches that are not valid. `git branch` seems to require that the repo
HEAD refer to something in refs/heads and explodes if it does not.
Unfortunately the repo reset() operation in zuul sets HEAD to point to
refs/remotes/origin/master which is not in refs/heads. This leads to
prune() breaking if run after reset().

Example explosion:
git.exc.GitCommandError: 'git branch -d -r origin/fetch_master' returned with exit code 128
stderr: 'fatal: HEAD not found below refs/heads!'

Thankfully the fix is simple. We can prune() bad refs prior to reseting,
at this point in time the value of HEAD is still valid for `git branch`
allowing prune to do its job, then we reset to the origin ref.

Change-Id: If97668f729db395fc697465d56c7d0667f994d0d
diff --git a/zuul/lib/cloner.py b/zuul/lib/cloner.py
index 67e238a..39e2e34 100644
--- a/zuul/lib/cloner.py
+++ b/zuul/lib/cloner.py
@@ -125,9 +125,14 @@
 
         repo = self.cloneUpstream(project, dest)
 
-        repo.reset()
         # Ensure that we don't have stale remotes around
         repo.prune()
+        # We must reset after pruning because reseting sets HEAD to point
+        # at refs/remotes/origin/master, but `git branch` which prune runs
+        # explodes if HEAD does not point at something in refs/heads.
+        # Later with repo.checkout() we set HEAD to something that
+        # `git branch` is happy with.
+        repo.reset()
 
         indicated_branch = self.branch or self.zuul_branch
         if project in self.project_branches: