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
1 file changed