diff options
| author | Naftaly RALAMBOARIVONY <naftaly.ralamboarivony@smile.fr> | 2025-10-02 15:10:24 +0200 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2025-11-07 13:15:35 +0000 |
| commit | d02722a28cf32ebc18b6261b31459b9955dd74ba (patch) | |
| tree | cfb36f1dcd8e738c0412c95fe7e5f9f5b3671a32 | |
| parent | b44ed55bba3cc4248ddfa8137c795a20e679b961 (diff) | |
| download | poky-d02722a28cf32ebc18b6261b31459b9955dd74ba.tar.gz | |
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.
(From OE-Core rev: 38f09a807c0f0a30b5c1832446fd2d3bdfdcf6b3)
Signed-off-by: Naftaly RALAMBOARIVONY <naftaly.ralamboarivony@smile.fr>
Reviewed-by: Yoann Congal <yoann.congal@smile.fr>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
| -rw-r--r-- | meta/lib/patchtest/repo.py | 9 |
1 files changed, 7 insertions, 2 deletions
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): | |||
| 21 | self.repodir = repodir | 21 | self.repodir = repodir |
| 22 | self.repo = git.Repo.init(repodir) | 22 | self.repo = git.Repo.init(repodir) |
| 23 | self.patch = mbox.PatchSeries(patch) | 23 | self.patch = mbox.PatchSeries(patch) |
| 24 | self.current_branch = self.repo.active_branch.name | 24 | |
| 25 | if self.repo.head.is_detached: | ||
| 26 | self.current_commit = self.repo.head.commit.hexsha | ||
| 27 | self.current_branch = None | ||
| 28 | else: | ||
| 29 | self.current_branch = self.repo.active_branch.name | ||
| 25 | 30 | ||
| 26 | # targeted branch defined on the patch may be invalid, so make sure there | 31 | # targeted branch defined on the patch may be invalid, so make sure there |
| 27 | # is a corresponding remote branch | 32 | # is a corresponding remote branch |
| @@ -80,6 +85,6 @@ class PatchTestRepo(object): | |||
| 80 | self._patchmerged = True | 85 | self._patchmerged = True |
| 81 | 86 | ||
| 82 | def clean(self): | 87 | def clean(self): |
| 83 | self.repo.git.execute(['git', 'checkout', self.current_branch]) | 88 | self.repo.git.execute(['git', 'checkout', self.current_branch if self.current_branch else self.current_commit]) |
| 84 | self.repo.git.execute(['git', 'branch', '-D', self._workingbranch]) | 89 | self.repo.git.execute(['git', 'branch', '-D', self._workingbranch]) |
| 85 | self._patchmerged = False | 90 | self._patchmerged = False |
