diff options
author | Clark Boylan <clark.boylan@gmail.com> | 2015-05-14 15:51:57 -0700 |
---|---|---|
committer | Clark Boylan <clark.boylan@gmail.com> | 2015-05-14 15:51:57 -0700 |
commit | f5e16815546fa6d9e7edbc8b41a4e5ae68d12378 (patch) | |
tree | 8f073d69d9c08b96376346107c95c046c8561345 | |
parent | 62dc90832a2196f82128ff2e64f0c57cec02294f (diff) | |
download | zuul-f5e16815546fa6d9e7edbc8b41a4e5ae68d12378.tar.gz |
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
-rw-r--r-- | zuul/lib/cloner.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/zuul/lib/cloner.py b/zuul/lib/cloner.py index 67e238a8a..39e2e346f 100644 --- a/zuul/lib/cloner.py +++ b/zuul/lib/cloner.py @@ -125,9 +125,14 @@ class Cloner(object): 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: |