summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorHan-Wen NIenhuys <hanwen@google.com>2023-03-31 06:24:32 -0400
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2023-03-31 06:24:32 -0400
commitd1746842733d41df1e3e61536cc20e66611829fa (patch)
tree3483031b58c5cbd61e6bce400c3af7d0d681b888 /org.eclipse.jgit.test
parentc5617711a1b4d5d0807cc7eed702b78d114d46b3 (diff)
parent903645835bd2b2a2e7907b59795c1c23de0f2611 (diff)
downloadjgit-d1746842733d41df1e3e61536cc20e66611829fa.tar.gz
jgit-d1746842733d41df1e3e61536cc20e66611829fa.zip
Merge "PatchApplier: Check for existence of src/dest files before any operation"
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchApplierTest.java70
1 files changed, 68 insertions, 2 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchApplierTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchApplierTest.java
index 2a7ad2a815..eeec149871 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchApplierTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchApplierTest.java
@@ -93,12 +93,16 @@ public class PatchApplierTest {
}
protected void initPreImage(String aName) throws Exception {
- File f = new File(db.getWorkTree(), aName);
preImage = IO
.readWholeStream(getTestResource(aName + "_PreImage"), 0)
.array();
+ addFile(aName, preImage);
+ }
+
+ protected void addFile(String aName, byte[] b) throws Exception {
+ File f = new File(db.getWorkTree(), aName);
+ Files.write(f.toPath(), b);
try (Git git = new Git(db)) {
- Files.write(f.toPath(), preImage);
git.add().addFilepattern(aName).call();
}
}
@@ -373,6 +377,68 @@ public class PatchApplierTest {
}
@Test
+ public void testAddAlreadyExistingFile() throws Exception {
+ addFile("M1", "existing content".getBytes());
+ init("M1", false, false);
+
+ Result result = applyPatch();
+
+ assertEquals(1, result.getErrors().size());
+ assertEquals(0, result.getPaths().size());
+ }
+
+ @Test
+ public void testDeleteNonexistentFile() throws Exception {
+ init("NonASCIIDel", false, false);
+
+ Result result = applyPatch();
+
+ assertEquals(1, result.getErrors().size());
+ assertEquals(0, result.getPaths().size());
+ }
+
+ @Test
+ public void testModifyNonexistentFile() throws Exception {
+ init("ShiftDown", false, true);
+
+ Result result = applyPatch();
+
+ assertEquals(1, result.getErrors().size());
+ assertEquals(0, result.getPaths().size());
+ }
+
+ @Test
+ public void testRenameNonexistentFile() throws Exception {
+ init("RenameNoHunks", false, true);
+
+ Result result = applyPatch();
+
+ assertEquals(1, result.getErrors().size());
+ assertEquals(0, result.getPaths().size());
+ }
+
+ @Test
+ public void testCopyNonexistentFile() throws Exception {
+ init("CopyWithHunks", false, true);
+
+ Result result = applyPatch();
+
+ assertEquals(1, result.getErrors().size());
+ assertEquals(0, result.getPaths().size());
+ }
+
+ @Test
+ public void testCopyOnTopAlreadyExistingFile() throws Exception {
+ addFile("CopyResult", "existing content".getBytes());
+ init("CopyWithHunks", true, false);
+
+ Result result = applyPatch();
+
+ assertEquals(1, result.getErrors().size());
+ assertEquals(0, result.getPaths().size());
+ }
+
+ @Test
public void testDoesNotAffectUnrelatedFiles() throws Exception {
initPreImage("Unaffected");
String expectedUnaffectedText = initPostImage("Unaffected");