From f6530ab6f20c08e22f5c6610ac8db5cbe1691be7 Mon Sep 17 00:00:00 2001 From: Uilian Ries Date: Fri, 3 Oct 2025 10:17:19 +0200 Subject: [PATCH 1/2] Add test to validate issue #35 Signed-off-by: Uilian Ries --- tests/run_tests.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/run_tests.py b/tests/run_tests.py index bcdc629..f8f019b 100755 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -521,6 +521,42 @@ def test_handle_full_index_patch_format(self): self.assertTrue(pto.apply()) self.assertEqual(os.stat(join(self.tmpdir, 'quote.txt')).st_mode, 0o644 | stat.S_IFREG) + +class TestPatchEmptyFile(unittest.TestCase): + + def setUp(self): + self.save_cwd = os.getcwd() + self.tmpdir = mkdtemp(prefix=self.__class__.__name__) + shutil.copytree(join(TESTS, 'emptypatches'), join(self.tmpdir, 'emptypatches')) + + def tearDown(self): + os.chdir(self.save_cwd) + remove_tree_force(self.tmpdir) + + @unittest.skipIf(platform.system() == "Windows", "File permission modes are not supported on Windows") + @unittest.expectedFailure # FIXME: https://github.com/conan-io/python-patch-ng/issues/35 + def test_apply_patch_only_file_mode(self): + """Test when a patch file is empty in terms of content, but has file + permission mode listed in the patch, the same should be applied to + the target file after patching. + """ + + os.chdir(self.tmpdir) + pto = patch_ng.fromfile(join(self.tmpdir, 'emptypatches', 'create755.patch')) + self.assertEqual(len(pto), 1) + self.assertEqual(pto.items[0].type, patch_ng.GIT) + self.assertEqual(pto.items[0].filemode, 0o100755) + self.assertTrue(pto.apply()) + self.assertTrue(os.path.exists(join(self.tmpdir, 'quote.txt'))) + self.assertEqual(os.stat(join(self.tmpdir, 'quote.txt')).st_mode, 0o755 | stat.S_IFREG) + + pto = patch_ng.fromfile(join(self.tmpdir, 'emptypatches', 'update644.patch')) + self.assertEqual(len(pto), 1) + self.assertEqual(pto.items[0].type, patch_ng.GIT) + self.assertEqual(pto.items[0].filemode, 0o100644) + self.assertTrue(pto.apply()) + self.assertEqual(os.stat(join(self.tmpdir, 'quote.txt')).st_mode, 0o644 | stat.S_IFREG) + class TestHelpers(unittest.TestCase): # unittest setting longMessage = True From b03520d5a8d52ce6996a78674d377cfc812caa98 Mon Sep 17 00:00:00 2001 From: Uilian Ries Date: Fri, 3 Oct 2025 10:17:50 +0200 Subject: [PATCH 2/2] Add empty patch for testing Signed-off-by: Uilian Ries --- tests/emptypatches/create755.patch | 21 +++++++++++++++++++++ tests/emptypatches/update644.patch | 16 ++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 tests/emptypatches/create755.patch create mode 100644 tests/emptypatches/update644.patch diff --git a/tests/emptypatches/create755.patch b/tests/emptypatches/create755.patch new file mode 100644 index 0000000..398ff4b --- /dev/null +++ b/tests/emptypatches/create755.patch @@ -0,0 +1,21 @@ +From 39fdfb57a112a3b00cc352b45d17aba4f0f58005 Mon Sep 17 00:00:00 2001 +From: John Doe +Date: Wed, 1 Oct 2025 12:39:25 +0200 +Subject: [PATCH] Add quotes.txt + +Signed-off-by: John Doe +--- + quote.txt | 1 + + 1 file changed, 1 insertion(+) + create mode 100755 quote.txt + +diff --git a/quote.txt b/quote.txt +new file mode 100755 +index 0000000000000000000000000000000000000000..cbfafe956ec35385f5b728daa390603ff71f1933 +--- /dev/null ++++ b/quote.txt +@@ -0,0 +1 @@ ++post malam segetem, serendum est. +-- +2.51.0 + diff --git a/tests/emptypatches/update644.patch b/tests/emptypatches/update644.patch new file mode 100644 index 0000000..eba8fd4 --- /dev/null +++ b/tests/emptypatches/update644.patch @@ -0,0 +1,16 @@ +From 9a6f61c8cabffc01811605577d6d276a07c8bb95 Mon Sep 17 00:00:00 2001 +From: John Doe +Date: Fri, 3 Oct 2025 08:57:43 +0200 +Subject: [PATCH] Change file permission + +Signed-off-by: John Doe +--- + quote.txt | 0 + 1 file changed, 0 insertions(+), 0 deletions(-) + mode change 100755 => 100644 quote.txt + +diff --git a/quote.txt b/quote.txt +old mode 100755 +new mode 100644 +-- +2.51.0