summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Henkel <tobias.henkel@bmw.de>2020-04-16 14:48:32 +0200
committerTobias Henkel <tobias.henkel@bmw.de>2020-04-20 14:20:01 +0200
commitfebf3e9b7df5ea505b709c65707782f74c9e0d6c (patch)
tree4feba0e9cd9dc69c8c2643a1cc4dbe5576a8ed53
parentf5368eb4a42f237633ae86b87dbeebee72c4bb9a (diff)
downloadzuul-febf3e9b7df5ea505b709c65707782f74c9e0d6c.tar.gz
Detach head before reset
During repo reset we currently try to reset the head to the HEAD of the remote repo. In some cases this doesn't work so simply reset the current HEAD revision as a commit to detach the head upfront. Change-Id: I167e6ce92680c40d2067939cedaa5ed98b950515
-rw-r--r--zuul/merger/merger.py26
1 files changed, 13 insertions, 13 deletions
diff --git a/zuul/merger/merger.py b/zuul/merger/merger.py
index 0dc7264c8..3ff8e7b2a 100644
--- a/zuul/merger/merger.py
+++ b/zuul/merger/merger.py
@@ -287,20 +287,20 @@ class Repo(object):
repo = Repo._createRepoObject(local_path, env)
origin = repo.remotes.origin
- # Reset the working directory to the default remote branch.
+ # Detach HEAD so we can work with references without interfering
+ # with any active branch. Any remote ref will do as long as it can
+ # be dereferenced to an existing commit.
for ref in origin.refs:
- if ref.remote_head != "HEAD":
- continue
- # Use the ref the remote HEAD is pointing to
- head_ref = ref.ref
- head = head_ref.remote_head
- repo.create_head(head, head_ref, force=True)
- if log:
- log.debug("Reset to %s", head)
- else:
- messages.append("Reset to %s" % head)
- repo.head.reference = head
- break
+ try:
+ repo.head.reference = ref.commit
+ break
+ except Exception:
+ if log:
+ log.debug("Unable to detach HEAD to %s", ref)
+ else:
+ messages.append("Unable to detach HEAD to %s" % ref)
+ else:
+ raise Exception("Couldn't detach HEAD to any existing commit")
# Delete local heads that no longer exist on the remote end
remote_heads = {r.remote_head for r in origin.refs}