]> source.dussan.org Git - jgit.git/commitdiff
Fire WorkingTreeModifiedEvent if cherry-pick failed with conflicts 30/150030/4
authorMatthias Sohn <matthias.sohn@sap.com>
Mon, 23 Sep 2019 22:14:12 +0000 (00:14 +0200)
committerMatthias Sohn <matthias.sohn@sap.com>
Thu, 26 Sep 2019 13:10:05 +0000 (15:10 +0200)
Otherwise the paths modified by a cherry-pick with conflicts won't be
reported as modified via WorkingTreeModifiedEvents.

Change-Id: I875b67c0d2f68efdf90a9c32b80a2e074ed3570d
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java
org.eclipse.jgit/src/org/eclipse/jgit/api/CherryPickCommand.java

index fbc2cf67e17ceab54a1c2bbf0578021da5d06a8e..adeb8b839c2e47a60fa11379f6b7da0be2c820f5 100644 (file)
@@ -58,6 +58,8 @@ import org.eclipse.jgit.api.errors.GitAPIException;
 import org.eclipse.jgit.api.errors.JGitInternalException;
 import org.eclipse.jgit.api.errors.MultipleParentsNotAllowedException;
 import org.eclipse.jgit.dircache.DirCache;
+import org.eclipse.jgit.events.ChangeRecorder;
+import org.eclipse.jgit.events.ListenerHandle;
 import org.eclipse.jgit.junit.RepositoryTestCase;
 import org.eclipse.jgit.lib.ConfigConstants;
 import org.eclipse.jgit.lib.Constants;
@@ -324,6 +326,25 @@ public class CherryPickCommandTest extends RepositoryTestCase {
                }
        }
 
+       @Test
+       public void testCherryPickConflictFiresModifiedEvent() throws Exception {
+               ListenerHandle listener = null;
+               try (Git git = new Git(db)) {
+                       RevCommit sideCommit = prepareCherryPick(git);
+                       ChangeRecorder recorder = new ChangeRecorder();
+                       listener = db.getListenerList()
+                                       .addWorkingTreeModifiedListener(recorder);
+                       CherryPickResult result = git.cherryPick()
+                                       .include(sideCommit.getId()).call();
+                       assertEquals(CherryPickStatus.CONFLICTING, result.getStatus());
+                       recorder.assertEvent(new String[] { "a" }, ChangeRecorder.EMPTY);
+               } finally {
+                       if (listener != null) {
+                               listener.remove();
+                       }
+               }
+       }
+
        @Test
        public void testCherryPickOurCommitName() throws Exception {
                try (Git git = new Git(db)) {
index c9dd547b4930e74c004e79c83a0077dfde00bc48..15352ec73da368b01f62ebcc5b635845f4f59010 100644 (file)
@@ -57,6 +57,7 @@ import org.eclipse.jgit.api.errors.UnmergedPathsException;
 import org.eclipse.jgit.api.errors.WrongRepositoryStateException;
 import org.eclipse.jgit.dircache.DirCacheCheckout;
 import org.eclipse.jgit.errors.MissingObjectException;
+import org.eclipse.jgit.events.WorkingTreeModifiedEvent;
 import org.eclipse.jgit.internal.JGitText;
 import org.eclipse.jgit.lib.AnyObjectId;
 import org.eclipse.jgit.lib.Constants;
@@ -188,6 +189,9 @@ public class CherryPickCommand extends GitCommand<CherryPickResult> {
                                                repo.writeCherryPickHead(srcCommit.getId());
                                        repo.writeMergeCommitMsg(message);
 
+                                       repo.fireEvent(new WorkingTreeModifiedEvent(
+                                                       merger.getModifiedFiles(), null));
+
                                        return CherryPickResult.CONFLICT;
                                }
                        }