Skip to content
This repository has been archived by the owner on Jan 18, 2021. It is now read-only.

Commit

Permalink
Apply hunks when renaming from patch files (#24)
Browse files Browse the repository at this point in the history
* Apply hunks when renaming if available

* Add tests
  • Loading branch information
jackwickham authored Mar 25, 2020
1 parent ef988ea commit b28d70e
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
diff --git a/RenameNoHunks b/nested/subdir/Renamed
similarity index 100%
rename from RenameNoHunks
rename to nested/subdir/Renamed
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
line1
line2
line3
line4
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
line1
line2
line3
line4
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/RenameWithHunks b/nested/subdir/Renamed
similarity index 75%
rename from RenameWithHunks
rename to nested/subdir/Renamed
index 0000000..de98044
--- a/RenameWithHunks
+++ b/nested/subdir/Renamed
@@ -1,4 +1,4 @@
line1
-line2
+lineB
line3
line4
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
line1
lineB
line3
line4
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
line1
line2
line3
line4
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,26 @@ public void testNonASCIIDel() throws Exception {
assertFalse(new File(db.getWorkTree(), "NonASCIIDel").exists());
}

@Test
public void testRenameNoHunks() throws Exception {
ApplyResult result = init("RenameNoHunks", true, true);
assertEquals(1, result.getUpdatedFiles().size());
assertEquals(new File(db.getWorkTree(), "RenameNoHunks"), result.getUpdatedFiles()
.get(0));
checkFile(new File(db.getWorkTree(), "nested/subdir/Renamed"),
b.getString(0, b.size(), false));
}

@Test
public void testRenameWithHunks() throws Exception {
ApplyResult result = init("RenameWithHunks", true, true);
assertEquals(1, result.getUpdatedFiles().size());
assertEquals(new File(db.getWorkTree(), "RenameWithHunks"), result.getUpdatedFiles()
.get(0));
checkFile(new File(db.getWorkTree(), "nested/subdir/Renamed"),
b.getString(0, b.size(), false));
}

private static byte[] readFile(final String patchFile) throws IOException {
final InputStream in = getTestResource(patchFile);
if (in == null) {
Expand Down
3 changes: 3 additions & 0 deletions org.eclipse.jgit/src/org/eclipse/jgit/api/ApplyCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ public ApplyResult call() throws GitAPIException, PatchFormatException,
throw new PatchApplyException(MessageFormat.format(
JGitText.get().renameFileFailed, f, dest), e);
}
if (!fh.getHunks().isEmpty()) {
apply(dest, fh);
}
break;
case COPY:
f = getFile(fh.getOldPath(), false);
Expand Down

0 comments on commit b28d70e

Please sign in to comment.