From: Naftaly RALAMBOARIVONY Date: Thu, 2 Oct 2025 13:10:24 +0000 (+0200) Subject: patchtest: fix failure when oe-core repo is in detached HEAD X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fheads%2Fmathieu%2Fmaster-next-test3;p=thirdparty%2Fopenembedded%2Fopenembedded-core-contrib.git patchtest: fix failure when oe-core repo is in detached HEAD Patchtest fails when oe-core git repo is in a "detached HEAD" state: Error log: > File "/usr/lib/python3/dist-packages/git/repo/base.py", line 881, in active_branch return self.head.reference ^^^^^^^^^^^^^^^^^^^ > File "/usr/lib/python3/dist-packages/git/refs/symbolic.py", line 311, in _get_reference raise TypeError("%s is a detached symbolic reference as it points to %r" % (self, sha)) TypeError: HEAD is a detached symbolic reference as it points to '3dd31d3b29730fa1130645d76bb71914ac036335' None In this case, no current branch is available for the clean operation. To fix this, updates the checkout logic: - if a current branch is available, use it, - otherwise, fall back to the commit pointed to by HEAD. This ensures that the script works correctly even when HEAD is detached. Signed-off-by: Naftaly RALAMBOARIVONY Reviewed-by: Yoann Congal Signed-off-by: Mathieu Dubois-Briand --- diff --git a/meta/lib/patchtest/repo.py b/meta/lib/patchtest/repo.py index 2cdd6736e4..6a7d7d2d3b 100644 --- a/meta/lib/patchtest/repo.py +++ b/meta/lib/patchtest/repo.py @@ -21,7 +21,12 @@ class PatchTestRepo(object): self.repodir = repodir self.repo = git.Repo.init(repodir) self.patch = mbox.PatchSeries(patch) - self.current_branch = self.repo.active_branch.name + + if self.repo.head.is_detached: + self.current_commit = self.repo.head.commit.hexsha + self.current_branch = None + else: + self.current_branch = self.repo.active_branch.name # targeted branch defined on the patch may be invalid, so make sure there # is a corresponding remote branch @@ -80,6 +85,6 @@ class PatchTestRepo(object): self._patchmerged = True def clean(self): - self.repo.git.execute(['git', 'checkout', self.current_branch]) + self.repo.git.execute(['git', 'checkout', self.current_branch if self.current_branch else self.current_commit]) self.repo.git.execute(['git', 'branch', '-D', self._workingbranch]) self._patchmerged = False