Skip to content

Commit c904f6e

Browse files
committed
Validate when moving a file
Signed-off-by: Uilian Ries <uilianr@jfrog.com>
1 parent 283d7fa commit c904f6e

2 files changed

Lines changed: 88 additions & 0 deletions

File tree

tests/movefile/0001-quote.patch

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
From 90ffe300b588f40f1409deb414498af8bc681072 Mon Sep 17 00:00:00 2001
2+
From: John Doe <john.doe@mail.com>
3+
Date: Fri, 3 Oct 2025 11:28:55 +0200
4+
Subject: [PATCH 1/3] Add file
5+
6+
Signed-off-by: John Doe <john.doe@mail.com>
7+
---
8+
quotes.txt | 1 +
9+
1 file changed, 1 insertion(+)
10+
create mode 100644 quotes.txt
11+
12+
diff --git a/quotes.txt b/quotes.txt
13+
new file mode 100644
14+
index 0000000000000000000000000000000000000000..6da41619625400f0b6c99beccc47c328f3967366
15+
--- /dev/null
16+
+++ b/quotes.txt
17+
@@ -0,0 +1 @@
18+
+in herbis, salus.
19+
--
20+
2.51.0
21+
22+
23+
From a055d1be31d11c149bfd9ca88d9554199d57d444 Mon Sep 17 00:00:00 2001
24+
From: John Doe <john.doe@mail.com>
25+
Date: Fri, 3 Oct 2025 11:29:27 +0200
26+
Subject: [PATCH 2/3] Move file
27+
28+
Signed-off-by: John Doe <john.doe@mail.com>
29+
---
30+
quotes.txt => quote/quotes.txt | 0
31+
1 file changed, 0 insertions(+), 0 deletions(-)
32+
rename quotes.txt => quote/quotes.txt (100%)
33+
34+
diff --git a/quotes.txt b/quote/quotes.txt
35+
similarity index 100%
36+
rename from quotes.txt
37+
rename to quote/quotes.txt
38+
--
39+
2.51.0
40+
41+
42+
From c275530ce83dc6eeeae671c2082660f1b6c16c4f Mon Sep 17 00:00:00 2001
43+
From: John Doe <john.doe@mail.com>
44+
Date: Fri, 3 Oct 2025 11:30:14 +0200
45+
Subject: [PATCH 3/3] Update quote
46+
47+
Signed-off-by: John Doe <john.doe@mail.com>
48+
---
49+
quote/quotes.txt | 2 +-
50+
1 file changed, 1 insertion(+), 1 deletion(-)
51+
52+
diff --git a/quote/quotes.txt b/quote/quotes.txt
53+
index 6da41619625400f0b6c99beccc47c328f3967366..928532e38b2a8e607814da280bb9e02862d2b4ea 100644
54+
--- a/quote/quotes.txt
55+
+++ b/quote/quotes.txt
56+
@@ -1 +1 @@
57+
-in herbis, salus.
58+
+dum tempus habemus, operemur bonum.
59+
--
60+
2.51.0
61+

tests/run_tests.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,33 @@ def test_apply_patch_only_file_mode(self):
557557
self.assertTrue(pto.apply())
558558
self.assertEqual(os.stat(join(self.tmpdir, 'quote.txt')).st_mode, 0o644 | stat.S_IFREG)
559559

560+
class TestMoveAndPatch(unittest.TestCase):
561+
562+
def setUp(self):
563+
self.save_cwd = os.getcwd()
564+
self.tmpdir = mkdtemp(prefix=self.__class__.__name__)
565+
shutil.copytree(join(TESTS, 'movefile'), join(self.tmpdir, 'movefile'))
566+
567+
def tearDown(self):
568+
os.chdir(self.save_cwd)
569+
remove_tree_force(self.tmpdir)
570+
571+
def test_add_move_and_update_file(self):
572+
"""When a patch file contains a file move (rename) and an update to the file,
573+
the patch should be applied correctly.
574+
575+
Reported by https://github.com/conan-io/python-patch-ng/issues/24
576+
"""
577+
578+
os.chdir(self.tmpdir)
579+
pto = patch_ng.fromfile(join(self.tmpdir, 'movefile', '0001-quote.patch'))
580+
self.assertEqual(len(pto), 2)
581+
self.assertEqual(pto.items[0].type, patch_ng.GIT)
582+
self.assertEqual(pto.items[1].type, patch_ng.GIT)
583+
self.assertTrue(pto.apply())
584+
self.assertTrue(os.path.exists(join(self.tmpdir, 'quote', 'quotes.txt')))
585+
586+
560587
class TestHelpers(unittest.TestCase):
561588
# unittest setting
562589
longMessage = True

0 commit comments

Comments
 (0)