]> source.dussan.org Git - jgit.git/commitdiff
ApplyCommand: fix ApplyResult#updatedFiles 31/195131/5
authorHan-Wen Nienhuys <hanwen@google.com>
Wed, 10 Aug 2022 15:46:12 +0000 (17:46 +0200)
committerHan-Wen NIenhuys <hanwen@google.com>
Tue, 23 Aug 2022 13:23:23 +0000 (09:23 -0400)
On executing a copy, mark the destination as updated.

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

Change-Id: Ied5b9b0e5a14eac59a06cdd0961e25e143f50ff0

org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java
org.eclipse.jgit/src/org/eclipse/jgit/api/ApplyCommand.java

index 584d1496314b6fbbc425ea3dea02f080dd6ac6e1..40764b739bd3159550f11c3cc31708a09b74c802 100644 (file)
@@ -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));
index 88bc7ddd2df2b05536ea24e7f2a5289531a99112..64fba98b496e3c2fbfd30071935b90e74e216dc7 100644 (file)
@@ -157,13 +157,14 @@ public class ApplyCommand extends GitCommand<ApplyResult> {
                                                                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);
                        }