Skip to contentSkip to conversation

patchtest: apply patch in repo root

PATCH In review Gyorgy Sarvari 2 participants 5 messages Sep 15, 2025 – Sep 19, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 patchtest: apply patch in repo root

Patchtest tries to apply the received patch on the repository, without specifying the directory, which means that the CWD is used. In case the patch modifies a content in a different folder (e.g. the script is running in ./meta, but the patch modifies ./meta-selftest), the patch will be skipped, but git still returns 0, instead of complaining.

To avoid such false positives, specify the working directory for applying the patch - the top of the repodir.

---
 meta/lib/patchtest/repo.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
meta/lib/patchtest/repo.py +2 -2
index 8ec8f68a0b..2cdd6736e4 100644
@@ -52,7 +52,7 @@ class PatchTestRepo(object):
         self._patchcanbemerged = True
         try:
             # Make sure to get the absolute path of the file
-            self.repo.git.execute(['git', 'apply', '--check', os.path.abspath(self.patch.path)], with_exceptions=True)
+            self.repo.git.execute(['git', '-C', self.repodir, 'apply', '--check', os.path.abspath(self.patch.path)], with_exceptions=True)
         except git.exc.GitCommandError as ce:
             self._patchcanbemerged = False
 
@@ -76,7 +76,7 @@ class PatchTestRepo(object):
 
     def merge(self):
         if self._patchcanbemerged:
-            self.repo.git.execute(['git', 'am', '--keep-cr', os.path.abspath(self.patch.path)])
+            self.repo.git.execute(['git', '-C', self.repodir, 'am', '--keep-cr', os.path.abspath(self.patch.path)])
             self._patchmerged = True
 
     def clean(self):
#1 lore raw

PATCH 2/4 patchtest: fix repo.canbemerged usage

Call it like a function to avoid it being interpreted as True always.

---
 meta/lib/patchtest/tests/test_mbox.py     | 2 +-
 meta/lib/patchtest/tests/test_metadata.py | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
meta/lib/patchtest/tests/test_mbox.py +1 -1
index dab733ea77..714c9b30af 100644
@@ -90,7 +90,7 @@ class TestMbox(base.Base):
                 " for master branch. Target detected is %s"
                 % PatchtestParser.repo.patch.branch
             )
-        if not PatchtestParser.repo.canbemerged:
+        if not PatchtestParser.repo.canbemerged():
             commithash, author, date, shortlog = headlog()
             self.fail(
                 "Series does not apply on top of target branch %s"
meta/lib/patchtest/tests/test_metadata.py +2 -2
index 2dee80b002..63d01819e7 100644
@@ -110,7 +110,7 @@ class TestMetadata(base.Metadata):
 
     def pretest_src_uri_left_files(self):
         # these tests just make sense on patches that can be merged
-        if not PatchtestParser.repo.canbemerged:
+        if not PatchtestParser.repo.canbemerged():
             self.skip("Patch cannot be merged")
         if not self.modified:
             self.skip('No modified recipes, skipping pretest')
@@ -127,7 +127,7 @@ class TestMetadata(base.Metadata):
 
     def test_src_uri_left_files(self):
         # these tests just make sense on patches that can be merged
-        if not PatchtestParser.repo.canbemerged:
+        if not PatchtestParser.repo.canbemerged():
             self.skip("Patch cannot be merged")
         if not self.modified:
             self.skip('No modified recipes, skipping pretest')
#2 lore raw

PATCH 3/4 patchtest: ignore patch file metadata from SRC_URI

In reply to Gyorgy Sarvari

The test_src_uri_left_files check prepares a list of patchfiles SRC_URI from before and after the patch is applied, looking for dangling patches.

The name of the files in this list can be incorrect, in case the URI contains some extra metadata (like patchdir), because os.path.basename will use the last portion of the line being processed, which is independent from the files in question.

To avoid this, try to use only the first portion of URI, before any extra metadata.

---
 meta/lib/patchtest/tests/test_metadata.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
meta/lib/patchtest/tests/test_metadata.py +2 -2
index 63d01819e7..30da8dbe60 100644
@@ -150,8 +150,8 @@ class TestMetadata(base.Metadata):
                 "%s-%s-%s" % (self.shortid(), patchtest_patterns.metadata_src_uri, pn)
             ].split()
 
-            pretest_files = set([os.path.basename(patch) for patch in pretest_src_uri if patch.startswith('file://')])
-            test_files    = set([os.path.basename(patch) for patch in test_src_uri    if patch.startswith('file://')])
+            pretest_files = set([os.path.basename(patch.split(';')[0]) for patch in pretest_src_uri if patch.startswith('file://')])
+            test_files    = set([os.path.basename(patch.split(';')[0]) for patch in test_src_uri    if patch.startswith('file://')])
 
             # check if files were removed
             if len(test_files) < len(pretest_files):
#3 lore raw

PATCH 4/4 patchtest: update testdata for selftest

In reply to Gyorgy Sarvari

The test-patch for test_src_uri_left_files selftest got out of date. This patch updates it to make it apply on the repo again.

---
 .../files/TestMetadata.test_src_uri_left_files.fail      | 9 +++------
 .../files/TestMetadata.test_src_uri_left_files.pass      | 7 ++-----
 2 files changed, 5 insertions(+), 11 deletions(-)
meta/lib/patchtest/selftest/files/TestMetadata.test_src_uri_left_files.fail +3 -6
index 0a402d0a3e..13e1a75a66 100644
@@ -11,7 +11,7 @@ Signed-off-by: Trevor Gamblin <[email protected]>
  1 file changed, 2 deletions(-)
 
 diff --git a/meta-selftest/recipes-test/selftest-hello/selftest-hello_1.0.bb b/meta-selftest/recipes-test/selftest-hello/selftest-hello_1.0.bb
-index 2dc352d479e..e95270adaeb 100644
+index 0ffe7308ba..bd8f4245a2 100644
 --- a/meta-selftest/recipes-test/selftest-hello/selftest-hello_1.0.bb
 +++ b/meta-selftest/recipes-test/selftest-hello/selftest-hello_1.0.bb
 @@ -3,8 +3,6 @@ SECTION = "examples"
@@ -20,9 +20,6 @@ index 2dc352d479e..e95270adaeb 100644
  
 -SRC_URI = "file://helloworld.c"
 -
- S = "${WORKDIR}/sources"
- UNPACKDIR = "${S}"
+ S = "${UNPACKDIR}"
  
--- 
-2.45.1
-
+ do_compile() {
meta/lib/patchtest/selftest/files/TestMetadata.test_src_uri_left_files.pass +2 -5
index a675c028d0..c06580f054 100644
@@ -36,9 +36,6 @@ index 2dc352d479e..e95270adaeb 100644
  
 -SRC_URI = "file://helloworld.c"
 -
- S = "${WORKDIR}/sources"
- UNPACKDIR = "${S}"
+ S = "${UNPACKDIR}"
  
--- 
-2.45.1
-
+ do_compile() {
#4 lore raw
In reply to Gyorgy Sarvari

Hi,

Just wanted to say thanks for submitting these - I didn't catch them earlier.  :)

Quoted 45 lines · Gyorgy Sarvari via lists.openembedded.org

Patchtest tries to apply the received patch on the repository, without specifying the directory, which means that the CWD is used. In case the patch modifies a content in a different folder (e.g. the script is running in ./meta, but the patch modifies ./meta-selftest), the patch will be skipped, but git still returns 0, instead of complaining.

To avoid such false positives, specify the working directory for applying the patch - the top of the repodir.

---
  meta/lib/patchtest/repo.py | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
meta/lib/patchtest/repo.py +2 -3
index 8ec8f68a0b..2cdd6736e4 100644
@@ -52,7 +52,7 @@ class PatchTestRepo(object):
          self._patchcanbemerged = True
          try:
              # Make sure to get the absolute path of the file
-            self.repo.git.execute(['git', 'apply', '--check', os.path.abspath(self.patch.path)], with_exceptions=True)
+            self.repo.git.execute(['git', '-C', self.repodir, 'apply', '--check', os.path.abspath(self.patch.path)], with_exceptions=True)
          except git.exc.GitCommandError as ce:
              self._patchcanbemerged = False
 
@@ -76,7 +76,7 @@ class PatchTestRepo(object):
 
      def merge(self):
          if self._patchcanbemerged:
-            self.repo.git.execute(['git', 'am', '--keep-cr', os.path.abspath(self.patch.path)])
+            self.repo.git.execute(['git', '-C', self.repodir, 'am', '--keep-cr', os.path.abspath(self.patch.path)])
              self._patchmerged = True
 
      def clean(self):
 
-=-=-=-=-=-=-=-=-=-=-=-

Links: You receive all messages sent to this group.
View/Reply Online (#223391): https://lists.openembedded.org/g/openembedded-core/message/223391
Mute This Topic: https://lists.openembedded.org/mt/115250666/7611679
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-