@@ -521,6 +521,42 @@ def test_handle_full_index_patch_format(self):
521521 self .assertTrue (pto .apply ())
522522 self .assertEqual (os .stat (join (self .tmpdir , 'quote.txt' )).st_mode , 0o644 | stat .S_IFREG )
523523
524+
525+ class TestPatchEmptyFile (unittest .TestCase ):
526+
527+ def setUp (self ):
528+ self .save_cwd = os .getcwd ()
529+ self .tmpdir = mkdtemp (prefix = self .__class__ .__name__ )
530+ shutil .copytree (join (TESTS , 'emptypatches' ), join (self .tmpdir , 'emptypatches' ))
531+
532+ def tearDown (self ):
533+ os .chdir (self .save_cwd )
534+ remove_tree_force (self .tmpdir )
535+
536+ @unittest .skipIf (platform .system () == "Windows" , "File permission modes are not supported on Windows" )
537+ @unittest .expectedFailure # FIXME: https://github.com/conan-io/python-patch-ng/issues/35
538+ def test_apply_patch_only_file_mode (self ):
539+ """Test when a patch file is empty in terms of content, but has file
540+ permission mode listed in the patch, the same should be applied to
541+ the target file after patching.
542+ """
543+
544+ os .chdir (self .tmpdir )
545+ pto = patch_ng .fromfile (join (self .tmpdir , 'emptypatches' , 'create755.patch' ))
546+ self .assertEqual (len (pto ), 1 )
547+ self .assertEqual (pto .items [0 ].type , patch_ng .GIT )
548+ self .assertEqual (pto .items [0 ].filemode , 0o100755 )
549+ self .assertTrue (pto .apply ())
550+ self .assertTrue (os .path .exists (join (self .tmpdir , 'quote.txt' )))
551+ self .assertEqual (os .stat (join (self .tmpdir , 'quote.txt' )).st_mode , 0o755 | stat .S_IFREG )
552+
553+ pto = patch_ng .fromfile (join (self .tmpdir , 'emptypatches' , 'update644.patch' ))
554+ self .assertEqual (len (pto ), 1 )
555+ self .assertEqual (pto .items [0 ].type , patch_ng .GIT )
556+ self .assertEqual (pto .items [0 ].filemode , 0o100644 )
557+ self .assertTrue (pto .apply ())
558+ self .assertEqual (os .stat (join (self .tmpdir , 'quote.txt' )).st_mode , 0o644 | stat .S_IFREG )
559+
524560class TestHelpers (unittest .TestCase ):
525561 # unittest setting
526562 longMessage = True
0 commit comments