aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse/jgit
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffEntryTest.java63
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffSubmoduleTest.java34
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/PathsTest.java18
3 files changed, 96 insertions, 19 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffEntryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffEntryTest.java
index 73c230ac68..de768118bf 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffEntryTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffEntryTest.java
@@ -59,9 +59,12 @@ import org.eclipse.jgit.diff.DiffEntry.ChangeType;
import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheEditor;
import org.eclipse.jgit.dircache.DirCacheEditor.PathEdit;
+import org.eclipse.jgit.internal.storage.file.FileRepository;
import org.eclipse.jgit.dircache.DirCacheEntry;
+import org.eclipse.jgit.junit.JGitTestUtil;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.lib.FileMode;
+import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.treewalk.EmptyTreeIterator;
import org.eclipse.jgit.treewalk.FileTreeIterator;
@@ -417,4 +420,64 @@ public class DiffEntryTest extends RepositoryTestCase {
assertEquals(FileMode.REGULAR_FILE, diff.getOldMode());
}
}
+
+ @Test
+ public void shouldReportSubmoduleReplacedByFileMove() throws Exception {
+ // Create a submodule
+ FileRepository submoduleStandalone = createWorkRepository();
+ JGitTestUtil.writeTrashFile(submoduleStandalone, "fileInSubmodule",
+ "submodule");
+ Git submoduleStandaloneGit = Git.wrap(submoduleStandalone);
+ submoduleStandaloneGit.add().addFilepattern("fileInSubmodule").call();
+ submoduleStandaloneGit.commit().setMessage("add file to submodule")
+ .call();
+
+ Repository submodule_db = Git.wrap(db).submoduleAdd()
+ .setPath("modules/submodule")
+ .setURI(submoduleStandalone.getDirectory().toURI().toString())
+ .call();
+ File submodule_trash = submodule_db.getWorkTree();
+ addRepoToClose(submodule_db);
+ writeTrashFile("fileInRoot", "root");
+ Git rootGit = Git.wrap(db);
+ rootGit.add().addFilepattern("fileInRoot").call();
+ rootGit.commit().setMessage("add submodule and root file").call();
+ // Dummy change on fileInRoot
+ writeTrashFile("fileInRoot", "changed");
+ rootGit.add().addFilepattern("fileInRoot").call();
+ RevCommit firstCommit = rootGit.commit().setMessage("change root file")
+ .call();
+ // Remove the submodule again and move fileInRoot into that subfolder
+ rootGit.rm().setCached(true).addFilepattern("modules/submodule").call();
+ recursiveDelete(submodule_trash);
+ JGitTestUtil.deleteTrashFile(db, "fileInRoot");
+ // Move the fileInRoot file
+ writeTrashFile("modules/submodule/fileInRoot", "changed");
+ rootGit.rm().addFilepattern("fileInRoot").addFilepattern("modules/")
+ .call();
+ rootGit.add().addFilepattern("modules/").call();
+ RevCommit secondCommit = rootGit.commit()
+ .setMessage("remove submodule and move root file")
+ .call();
+ // Diff should report submodule having been deleted and file moved
+ // (deleted and added)
+ try (TreeWalk walk = new TreeWalk(db)) {
+ walk.addTree(firstCommit.getTree());
+ walk.addTree(secondCommit.getTree());
+ walk.setRecursive(true);
+ List<DiffEntry> diffs = DiffEntry.scan(walk);
+ assertEquals(3, diffs.size());
+ DiffEntry e = diffs.get(0);
+ assertEquals(DiffEntry.ChangeType.DELETE, e.getChangeType());
+ assertEquals("fileInRoot", e.getOldPath());
+ e = diffs.get(1);
+ assertEquals(DiffEntry.ChangeType.DELETE, e.getChangeType());
+ assertEquals("modules/submodule", e.getOldPath());
+ assertEquals(FileMode.GITLINK, e.getOldMode());
+ e = diffs.get(2);
+ assertEquals(DiffEntry.ChangeType.ADD, e.getChangeType());
+ assertEquals("modules/submodule/fileInRoot", e.getNewPath());
+ }
+
+ }
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffSubmoduleTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffSubmoduleTest.java
index 93ada4f301..fa7f5ab522 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffSubmoduleTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffSubmoduleTest.java
@@ -43,12 +43,14 @@
package org.eclipse.jgit.lib;
+import static org.junit.Assert.assertArrayEquals;
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.Arrays;
import java.util.Set;
import org.eclipse.jgit.api.CloneCommand;
@@ -128,7 +130,8 @@ public class IndexDiffSubmoduleTest extends RepositoryTestCase {
IndexDiff indexDiff = new IndexDiff(db2, Constants.HEAD,
new FileTreeIterator(db2));
indexDiff.setIgnoreSubmoduleMode(mode);
- assertFalse(indexDiff.diff());
+ boolean changed = indexDiff.diff();
+ assertFalse(changed);
}
@Theory
@@ -263,4 +266,33 @@ public class IndexDiffSubmoduleTest extends RepositoryTestCase {
assertDiff(indexDiff, mode, IgnoreSubmoduleMode.ALL,
IgnoreSubmoduleMode.DIRTY, IgnoreSubmoduleMode.UNTRACKED);
}
+
+ @Theory
+ public void testSubmoduleReplacedByMovedFile(IgnoreSubmoduleMode mode)
+ throws Exception {
+ Git git = Git.wrap(db);
+ git.rm().setCached(true).addFilepattern("modules/submodule").call();
+ recursiveDelete(submodule_trash);
+ JGitTestUtil.deleteTrashFile(db, "fileInRoot");
+ // Move the fileInRoot file
+ writeTrashFile("modules/submodule/fileInRoot", "root");
+ git.rm().addFilepattern("fileInRoot").addFilepattern("modules/").call();
+ git.add().addFilepattern("modules/").call();
+ IndexDiff indexDiff = new IndexDiff(db, Constants.HEAD,
+ new FileTreeIterator(db));
+ indexDiff.setIgnoreSubmoduleMode(mode);
+ assertTrue(indexDiff.diff());
+ String[] removed = indexDiff.getRemoved().toArray(new String[0]);
+ Arrays.sort(removed);
+ if (IgnoreSubmoduleMode.ALL.equals(mode)) {
+ assertArrayEquals(new String[] { "fileInRoot" }, removed);
+ } else {
+ assertArrayEquals(
+ new String[] { "fileInRoot", "modules/submodule" },
+ removed);
+ }
+ assertEquals("[modules/submodule/fileInRoot]",
+ indexDiff.getAdded().toString());
+ }
+
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/PathsTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/PathsTest.java
index f78cbe2601..7542ec8910 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/PathsTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/PathsTest.java
@@ -89,29 +89,14 @@ public class PathsTest {
a, 0, a.length, FileMode.TREE.getBits(),
b, 0, b.length, FileMode.TREE.getBits()));
assertEquals(0, compare(
- a, 0, a.length, FileMode.TREE.getBits(),
- b, 0, b.length, FileMode.GITLINK.getBits()));
- assertEquals(0, compare(
- a, 0, a.length, FileMode.GITLINK.getBits(),
- b, 0, b.length, FileMode.GITLINK.getBits()));
- assertEquals(0, compare(
- a, 0, a.length, FileMode.GITLINK.getBits(),
- b, 0, b.length, FileMode.TREE.getBits()));
- assertEquals(0, compare(
a, 0, a.length, FileMode.REGULAR_FILE.getBits(),
b, 0, b.length, FileMode.REGULAR_FILE.getBits()));
assertEquals(-47, compare(
a, 0, a.length, FileMode.REGULAR_FILE.getBits(),
b, 0, b.length, FileMode.TREE.getBits()));
- assertEquals(0, compare(
- a, 0, a.length, FileMode.REGULAR_FILE.getBits(),
- b, 0, b.length, FileMode.GITLINK.getBits()));
assertEquals(47, compare(
a, 0, a.length, FileMode.TREE.getBits(),
b, 0, b.length, FileMode.REGULAR_FILE.getBits()));
- assertEquals(0, compare(
- a, 0, a.length, FileMode.GITLINK.getBits(),
- b, 0, b.length, FileMode.REGULAR_FILE.getBits()));
assertEquals(0, compareSameName(
a, 0, a.length,
@@ -119,9 +104,6 @@ public class PathsTest {
assertEquals(0, compareSameName(
a, 0, a.length,
b, 0, b.length, FileMode.REGULAR_FILE.getBits()));
- assertEquals(0, compareSameName(
- a, 0, a.length,
- b, 0, b.length, FileMode.GITLINK.getBits()));
a = Constants.encode("a.c");
b = Constants.encode("a");