Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions tests/emptypatches/create755.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
From 39fdfb57a112a3b00cc352b45d17aba4f0f58005 Mon Sep 17 00:00:00 2001
From: John Doe <john.doe@mail.com>
Date: Wed, 1 Oct 2025 12:39:25 +0200
Subject: [PATCH] Add quotes.txt

Signed-off-by: John Doe <john.doe@mail.com>
---
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

16 changes: 16 additions & 0 deletions tests/emptypatches/update644.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
From 9a6f61c8cabffc01811605577d6d276a07c8bb95 Mon Sep 17 00:00:00 2001
From: John Doe <john.doe@mail.com>
Date: Fri, 3 Oct 2025 08:57:43 +0200
Subject: [PATCH] Change file permission

Signed-off-by: John Doe <john.doe@mail.com>
---
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
36 changes: 36 additions & 0 deletions tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down