ApplyCommand: fix ApplyResult#updatedFiles

On executing a copy, mark the destination as updated.

On executing a rename, mark both source and destination as updated.

Change-Id: Ied5b9b0e5a14eac59a06cdd0961e25e143f50ff0
This commit is contained in:
Han-Wen Nienhuys 2022-08-10 17:46:12 +02:00 committed by Han-Wen NIenhuys
parent 0887111ba5
commit 25aceffdc5
2 changed files with 13 additions and 12 deletions

View File

@ -525,9 +525,9 @@ public void testNonASCIIDel() throws Exception {
@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));
assertEquals(2, result.getUpdatedFiles().size());
assertTrue(result.getUpdatedFiles().contains(new File(db.getWorkTree(), "RenameNoHunks")));
assertTrue(result.getUpdatedFiles().contains(new File(db.getWorkTree(), "nested/subdir/Renamed")));
checkFile(new File(db.getWorkTree(), "nested/subdir/Renamed"),
b.getString(0, b.size(), false));
}
@ -535,9 +535,9 @@ public void testRenameNoHunks() throws Exception {
@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));
assertEquals(2, result.getUpdatedFiles().size());
assertTrue(result.getUpdatedFiles().contains(new File(db.getWorkTree(), "RenameWithHunks")));
assertTrue(result.getUpdatedFiles().contains(new File(db.getWorkTree(), "nested/subdir/Renamed")));
checkFile(new File(db.getWorkTree(), "nested/subdir/Renamed"),
b.getString(0, b.size(), false));
}
@ -546,7 +546,7 @@ public void testRenameWithHunks() throws Exception {
public void testCopyWithHunks() throws Exception {
ApplyResult result = init("CopyWithHunks", true, true);
assertEquals(1, result.getUpdatedFiles().size());
assertEquals(new File(db.getWorkTree(), "CopyWithHunks"), result.getUpdatedFiles()
assertEquals(new File(db.getWorkTree(), "CopyResult"), result.getUpdatedFiles()
.get(0));
checkFile(new File(db.getWorkTree(), "CopyResult"),
b.getString(0, b.size(), false));

View File

@ -157,13 +157,14 @@ public ApplyResult call() throws GitAPIException, PatchFormatException,
JGitText.get().renameFileFailed, f, dest), e);
}
apply(repository, fh.getOldPath(), cache, dest, fh);
r.addUpdatedFile(dest);
break;
case COPY:
f = getFile(fh.getOldPath(), false);
File target = getFile(fh.getNewPath(), false);
FileUtils.mkdirs(target.getParentFile(), true);
Files.copy(f.toPath(), target.toPath());
apply(repository, fh.getOldPath(), cache, target, fh);
File src = getFile(fh.getOldPath(), false);
f = getFile(fh.getNewPath(), false);
FileUtils.mkdirs(f.getParentFile(), true);
Files.copy(src.toPath(), f.toPath());
apply(repository, fh.getOldPath(), cache, f, fh);
}
r.addUpdatedFile(f);
}