From 25aceffdc58fdc5707c908fb4c3584116703046e Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Wed, 10 Aug 2022 17:46:12 +0200 Subject: [PATCH] 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 --- .../tst/org/eclipse/jgit/api/ApplyCommandTest.java | 14 +++++++------- .../src/org/eclipse/jgit/api/ApplyCommand.java | 11 ++++++----- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java index 584d149631..40764b739b 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java @@ -525,9 +525,9 @@ public class ApplyCommandTest extends RepositoryTestCase { @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 class ApplyCommandTest extends RepositoryTestCase { @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 class ApplyCommandTest extends RepositoryTestCase { 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)); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/ApplyCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/ApplyCommand.java index 88bc7ddd2d..64fba98b49 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/ApplyCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/ApplyCommand.java @@ -157,13 +157,14 @@ public class ApplyCommand extends GitCommand { 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); } -- 2.39.5