|
|
|
@ -43,11 +43,13 @@
|
|
|
|
|
|
|
|
|
|
package org.eclipse.jgit.lib; |
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
|
import static org.junit.Assert.assertFalse; |
|
|
|
|
import static org.junit.Assert.assertTrue; |
|
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
|
|
import org.eclipse.jgit.api.Git; |
|
|
|
|
import org.eclipse.jgit.api.errors.GitAPIException; |
|
|
|
@ -118,6 +120,31 @@ public class IndexDiffSubmoduleTest extends RepositoryTestCase {
|
|
|
|
|
assertTrue(indexDiff.diff()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void assertDiff(IndexDiff indexDiff, IgnoreSubmoduleMode mode, |
|
|
|
|
IgnoreSubmoduleMode... expectedEmptyModes) throws IOException { |
|
|
|
|
boolean diffResult = indexDiff.diff(); |
|
|
|
|
Set<String> submodulePaths = indexDiff |
|
|
|
|
.getPathsWithIndexMode(FileMode.GITLINK); |
|
|
|
|
boolean emptyExpected = false; |
|
|
|
|
for (IgnoreSubmoduleMode empty : expectedEmptyModes) { |
|
|
|
|
if (mode.equals(empty)) { |
|
|
|
|
emptyExpected = true; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (emptyExpected) { |
|
|
|
|
assertFalse("diff should be false with mode=" + mode, |
|
|
|
|
diffResult); |
|
|
|
|
assertEquals("should have no paths with FileMode.GITLINK", 0, |
|
|
|
|
submodulePaths.size()); |
|
|
|
|
} else { |
|
|
|
|
assertTrue("diff should be true with mode=" + mode, |
|
|
|
|
diffResult); |
|
|
|
|
assertTrue("submodule path should have FileMode.GITLINK", |
|
|
|
|
submodulePaths.contains("modules/submodule")); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Theory |
|
|
|
|
public void testDirtySubmoduleWorktree(IgnoreSubmoduleMode mode) |
|
|
|
|
throws IOException { |
|
|
|
@ -125,13 +152,8 @@ public class IndexDiffSubmoduleTest extends RepositoryTestCase {
|
|
|
|
|
IndexDiff indexDiff = new IndexDiff(db, Constants.HEAD, |
|
|
|
|
new FileTreeIterator(db)); |
|
|
|
|
indexDiff.setIgnoreSubmoduleMode(mode); |
|
|
|
|
if (mode.equals(IgnoreSubmoduleMode.ALL) |
|
|
|
|
|| mode.equals(IgnoreSubmoduleMode.DIRTY)) |
|
|
|
|
assertFalse("diff should be false with mode=" + mode, |
|
|
|
|
indexDiff.diff()); |
|
|
|
|
else |
|
|
|
|
assertTrue("diff should be true with mode=" + mode, |
|
|
|
|
indexDiff.diff()); |
|
|
|
|
assertDiff(indexDiff, mode, IgnoreSubmoduleMode.ALL, |
|
|
|
|
IgnoreSubmoduleMode.DIRTY); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Theory |
|
|
|
@ -145,12 +167,7 @@ public class IndexDiffSubmoduleTest extends RepositoryTestCase {
|
|
|
|
|
IndexDiff indexDiff = new IndexDiff(db, Constants.HEAD, |
|
|
|
|
new FileTreeIterator(db)); |
|
|
|
|
indexDiff.setIgnoreSubmoduleMode(mode); |
|
|
|
|
if (mode.equals(IgnoreSubmoduleMode.ALL)) |
|
|
|
|
assertFalse("diff should be false with mode=" + mode, |
|
|
|
|
indexDiff.diff()); |
|
|
|
|
else |
|
|
|
|
assertTrue("diff should be true with mode=" + mode, |
|
|
|
|
indexDiff.diff()); |
|
|
|
|
assertDiff(indexDiff, mode, IgnoreSubmoduleMode.ALL); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Theory |
|
|
|
@ -163,13 +180,8 @@ public class IndexDiffSubmoduleTest extends RepositoryTestCase {
|
|
|
|
|
IndexDiff indexDiff = new IndexDiff(db, Constants.HEAD, |
|
|
|
|
new FileTreeIterator(db)); |
|
|
|
|
indexDiff.setIgnoreSubmoduleMode(mode); |
|
|
|
|
if (mode.equals(IgnoreSubmoduleMode.ALL) |
|
|
|
|
|| mode.equals(IgnoreSubmoduleMode.DIRTY)) |
|
|
|
|
assertFalse("diff should be false with mode=" + mode, |
|
|
|
|
indexDiff.diff()); |
|
|
|
|
else |
|
|
|
|
assertTrue("diff should be true with mode=" + mode, |
|
|
|
|
indexDiff.diff()); |
|
|
|
|
assertDiff(indexDiff, mode, IgnoreSubmoduleMode.ALL, |
|
|
|
|
IgnoreSubmoduleMode.DIRTY); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Theory |
|
|
|
@ -183,13 +195,8 @@ public class IndexDiffSubmoduleTest extends RepositoryTestCase {
|
|
|
|
|
IndexDiff indexDiff = new IndexDiff(db, Constants.HEAD, |
|
|
|
|
new FileTreeIterator(db)); |
|
|
|
|
indexDiff.setIgnoreSubmoduleMode(mode); |
|
|
|
|
if (mode.equals(IgnoreSubmoduleMode.ALL) |
|
|
|
|
|| mode.equals(IgnoreSubmoduleMode.DIRTY)) |
|
|
|
|
assertFalse("diff should be false with mode=" + mode, |
|
|
|
|
indexDiff.diff()); |
|
|
|
|
else |
|
|
|
|
assertTrue("diff should be true with mode=" + mode, |
|
|
|
|
indexDiff.diff()); |
|
|
|
|
assertDiff(indexDiff, mode, IgnoreSubmoduleMode.ALL, |
|
|
|
|
IgnoreSubmoduleMode.DIRTY); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Theory |
|
|
|
@ -200,13 +207,7 @@ public class IndexDiffSubmoduleTest extends RepositoryTestCase {
|
|
|
|
|
IndexDiff indexDiff = new IndexDiff(db, Constants.HEAD, |
|
|
|
|
new FileTreeIterator(db)); |
|
|
|
|
indexDiff.setIgnoreSubmoduleMode(mode); |
|
|
|
|
if (mode.equals(IgnoreSubmoduleMode.ALL) |
|
|
|
|
|| mode.equals(IgnoreSubmoduleMode.DIRTY) |
|
|
|
|
|| mode.equals(IgnoreSubmoduleMode.UNTRACKED)) |
|
|
|
|
assertFalse("diff should be false with mode=" + mode, |
|
|
|
|
indexDiff.diff()); |
|
|
|
|
else |
|
|
|
|
assertTrue("diff should be true with mode=" + mode, |
|
|
|
|
indexDiff.diff()); |
|
|
|
|
assertDiff(indexDiff, mode, IgnoreSubmoduleMode.ALL, |
|
|
|
|
IgnoreSubmoduleMode.DIRTY, IgnoreSubmoduleMode.UNTRACKED); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|