From: Naftaly RALAMBOARIVONY <[email protected]>

If the repo is in a detached HEAD state, create and check out a temporary branch
to attach HEAD. If the branch already exists, the error is raised via run_sh.

Add a check to verify that the Git state has not changed before and
after the test in the attached HEAD.

Signed-off-by: Naftaly RALAMBOARIVONY <[email protected]>
---
 meta/lib/patchtest/selftest/selftest | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/meta/lib/patchtest/selftest/selftest 
b/meta/lib/patchtest/selftest/selftest
index 01a0888499..43cccf4c85 100755
--- a/meta/lib/patchtest/selftest/selftest
+++ b/meta/lib/patchtest/selftest/selftest
@@ -120,6 +120,9 @@ def is_git_state_same(before, after):
 
     return ret
 
+def git_attach_head(temp_branch):
+    run_sh(f"git switch -C {temp_branch}")
+
 def git_detach_head():
     run_sh("git switch --detach HEAD")
     assert run_sh("git rev-parse --abbrev-ref HEAD") == "HEAD", "Failed to 
enter detached HEAD state"
@@ -136,10 +139,15 @@ def test(root, patch):
 
     return results
 
-def test_head_attached(patches, counts):
+def test_head_attached(patches, counts, branch):
+
+    git_attach_head(branch)
+    git_state_before = get_git_state()
     for patch_info in patches:
         results = test(patch_info["root"], patch_info["patch"])
         counts = analyze_result(results, patch_info, counts)
+    git_state_after = get_git_state()
+    assert is_git_state_same(git_state_before, git_state_after), "Repository 
state changed after attached HEAD test."
     return counts
 
 def test_head_detached(patches, counts):
@@ -160,10 +168,13 @@ def test_head_detached(patches, counts):
     return counts
 
 def run_tests(patches, counts):
+    temp_branch = "test_patchtest_head_attached"
     git_state = get_git_state()
-    counts = test_head_attached(patches, counts)
+    assert git_state['branch'] != temp_branch, f"Cannot run patchtest selftest 
while on branch '{temp_branch}'"
+    counts = test_head_attached(patches, counts, temp_branch)
     counts = test_head_detached(patches, counts)
     restore_git_state(git_state)
+    run_sh(f"git branch -D {temp_branch}")
 
     return counts
 
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#227544): 
https://lists.openembedded.org/g/openembedded-core/message/227544
Mute This Topic: https://lists.openembedded.org/mt/116730108/21656
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub 
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to