From 64f2407f19330d182728feeaf3d2c1a4092a2051 Mon Sep 17 00:00:00 2001 From: Thomas Wolf Date: Sat, 2 Nov 2019 19:26:42 +0100 Subject: WorkingTreeModifiedEvent: must be fired explicitly after merge A merge may write files to the working tree. After a successful merge one must fire a WorkingTreeModifiedEvent explicitly if getModifiedFiles() is not empty. Also, any touched files must be reported by the WorkingTreeModifiedEvent fired by DirCacheCheckout.checkout(). Bug: 552636 Change-Id: I5fab8279ed8be8a4ae34cddfa726836b9277aea6 Signed-off-by: Thomas Wolf --- .../eclipse/jgit/api/CherryPickCommandTest.java | 34 ++++++++++++++++++++++ .../org/eclipse/jgit/api/RebaseCommandTest.java | 14 ++++----- 2 files changed, 39 insertions(+), 9 deletions(-) (limited to 'org.eclipse.jgit.test/tst/org/eclipse') diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java index adeb8b839c..76958f1ddf 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java @@ -345,6 +345,40 @@ public class CherryPickCommandTest extends RepositoryTestCase { } } + @Test + public void testCherryPickNewFileFiresModifiedEvent() throws Exception { + ListenerHandle listener = null; + try (Git git = new Git(db)) { + writeTrashFile("test.txt", "a"); + git.add().addFilepattern("test.txt").call(); + git.commit().setMessage("commit1").call(); + git.checkout().setCreateBranch(true).setName("a").call(); + + writeTrashFile("side.txt", "side"); + git.add().addFilepattern("side.txt").call(); + RevCommit side = git.commit().setMessage("side").call(); + assertNotNull(side); + + assertNotNull(git.checkout().setName(Constants.MASTER).call()); + writeTrashFile("test.txt", "b"); + assertNotNull(git.add().addFilepattern("test.txt").call()); + assertNotNull(git.commit().setMessage("commit2").call()); + + ChangeRecorder recorder = new ChangeRecorder(); + listener = db.getListenerList() + .addWorkingTreeModifiedListener(recorder); + CherryPickResult result = git.cherryPick() + .include(side.getId()).call(); + assertEquals(CherryPickStatus.OK, result.getStatus()); + recorder.assertEvent(new String[] { "side.txt" }, + ChangeRecorder.EMPTY); + } finally { + if (listener != null) { + listener.remove(); + } + } + } + @Test public void testCherryPickOurCommitName() throws Exception { try (Git git = new Git(db)) { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java index 1b2c850192..7c8ec23848 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java @@ -57,12 +57,9 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; -import java.util.ArrayList; import java.util.Collections; -import java.util.HashSet; import java.util.Iterator; import java.util.List; -import java.util.Set; import org.eclipse.jgit.api.MergeResult.MergeStatus; import org.eclipse.jgit.api.RebaseCommand.InteractiveHandler; @@ -78,6 +75,7 @@ import org.eclipse.jgit.errors.AmbiguousObjectException; import org.eclipse.jgit.errors.IllegalTodoFileModification; import org.eclipse.jgit.errors.IncorrectObjectTypeException; import org.eclipse.jgit.errors.MissingObjectException; +import org.eclipse.jgit.events.ChangeRecorder; import org.eclipse.jgit.events.ListenerHandle; import org.eclipse.jgit.junit.RepositoryTestCase; import org.eclipse.jgit.lib.AbbreviatedObjectId; @@ -2014,10 +2012,9 @@ public class RebaseCommandTest extends RepositoryTestCase { checkoutBranch("refs/heads/topic"); writeTrashFile("sub/file0", "unstaged modified file0"); - Set modifiedFiles = new HashSet<>(); + ChangeRecorder recorder = new ChangeRecorder(); ListenerHandle handle = db.getListenerList() - .addWorkingTreeModifiedListener( - event -> modifiedFiles.addAll(event.getModified())); + .addWorkingTreeModifiedListener(recorder); try { // rebase assertEquals(Status.OK, git.rebase() @@ -2035,9 +2032,8 @@ public class RebaseCommandTest extends RepositoryTestCase { + "[sub/file0, mode:100644, content:file0]", indexState(CONTENT)); assertEquals(RepositoryState.SAFE, db.getRepositoryState()); - List modified = new ArrayList<>(modifiedFiles); - Collections.sort(modified); - assertEquals("[file1, sub/file0]", modified.toString()); + recorder.assertEvent(new String[] { "file1", "file2", "sub/file0" }, + new String[0]); } @Test -- cgit v1.2.3