diff options
author | Shawn Pearce <spearce@spearce.org> | 2011-11-04 10:14:46 -0400 |
---|---|---|
committer | Code Review <codereview-daemon@eclipse.org> | 2011-11-04 10:14:46 -0400 |
commit | ede88c60a50db05717fcd65d326df59ba2f85c22 (patch) | |
tree | fd3c8b024144d204856ef34307a0f112fa25ca38 /org.eclipse.jgit.test | |
parent | 85a9ab7410c464a95d1951b381bee4d4e294fff7 (diff) | |
parent | 931b931ee830057a6c713ed8ccc56b75aa50d195 (diff) | |
download | jgit-ede88c60a50db05717fcd65d326df59ba2f85c22.tar.gz jgit-ede88c60a50db05717fcd65d326df59ba2f85c22.zip |
Merge "Provide an id for submodule entries."
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java | 171 |
1 files changed, 171 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java index 0b12058c88..064100839e 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java @@ -45,19 +45,26 @@ package org.eclipse.jgit.treewalk; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.io.File; import java.security.MessageDigest; import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCacheCheckout; +import org.eclipse.jgit.dircache.DirCacheEditor; import org.eclipse.jgit.dircache.DirCacheEntry; +import org.eclipse.jgit.dircache.DirCacheIterator; +import org.eclipse.jgit.dircache.DirCacheEditor.PathEdit; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectReader; import org.eclipse.jgit.lib.RepositoryTestCase; +import org.eclipse.jgit.revwalk.RevCommit; +import org.eclipse.jgit.treewalk.filter.PathFilter; import org.eclipse.jgit.util.FileUtils; import org.eclipse.jgit.util.RawParseUtils; import org.junit.Before; @@ -208,6 +215,170 @@ public class FileTreeIteratorTest extends RepositoryTestCase { assertFalse(fti.isModified(dce, false)); } + @Test + public void submoduleHeadMatchesIndex() throws Exception { + Git git = new Git(db); + writeTrashFile("file.txt", "content"); + git.add().addFilepattern("file.txt").call(); + final RevCommit id = git.commit().setMessage("create file").call(); + final String path = "sub"; + DirCache cache = db.lockDirCache(); + DirCacheEditor editor = cache.editor(); + editor.add(new PathEdit(path) { + + public void apply(DirCacheEntry ent) { + ent.setFileMode(FileMode.GITLINK); + ent.setObjectId(id); + } + }); + editor.commit(); + + Git.cloneRepository().setURI(db.getDirectory().toURI().toString()) + .setDirectory(new File(db.getWorkTree(), path)).call(); + + TreeWalk walk = new TreeWalk(db); + DirCacheIterator indexIter = new DirCacheIterator(db.readDirCache()); + FileTreeIterator workTreeIter = new FileTreeIterator(db); + walk.addTree(indexIter); + walk.addTree(workTreeIter); + walk.setFilter(PathFilter.create(path)); + + assertTrue(walk.next()); + assertTrue(indexIter.idEqual(workTreeIter)); + } + + @Test + public void submoduleWithNoGitDirectory() throws Exception { + Git git = new Git(db); + writeTrashFile("file.txt", "content"); + git.add().addFilepattern("file.txt").call(); + final RevCommit id = git.commit().setMessage("create file").call(); + final String path = "sub"; + DirCache cache = db.lockDirCache(); + DirCacheEditor editor = cache.editor(); + editor.add(new PathEdit(path) { + + public void apply(DirCacheEntry ent) { + ent.setFileMode(FileMode.GITLINK); + ent.setObjectId(id); + } + }); + editor.commit(); + + File submoduleRoot = new File(db.getWorkTree(), path); + assertTrue(submoduleRoot.mkdir()); + assertTrue(new File(submoduleRoot, Constants.DOT_GIT).mkdir()); + + TreeWalk walk = new TreeWalk(db); + DirCacheIterator indexIter = new DirCacheIterator(db.readDirCache()); + FileTreeIterator workTreeIter = new FileTreeIterator(db); + walk.addTree(indexIter); + walk.addTree(workTreeIter); + walk.setFilter(PathFilter.create(path)); + + assertTrue(walk.next()); + assertFalse(indexIter.idEqual(workTreeIter)); + assertEquals(ObjectId.zeroId(), workTreeIter.getEntryObjectId()); + } + + @Test + public void submoduleWithNoHead() throws Exception { + Git git = new Git(db); + writeTrashFile("file.txt", "content"); + git.add().addFilepattern("file.txt").call(); + final RevCommit id = git.commit().setMessage("create file").call(); + final String path = "sub"; + DirCache cache = db.lockDirCache(); + DirCacheEditor editor = cache.editor(); + editor.add(new PathEdit(path) { + + public void apply(DirCacheEntry ent) { + ent.setFileMode(FileMode.GITLINK); + ent.setObjectId(id); + } + }); + editor.commit(); + + assertNotNull(Git.init().setDirectory(new File(db.getWorkTree(), path)) + .call().getRepository()); + + TreeWalk walk = new TreeWalk(db); + DirCacheIterator indexIter = new DirCacheIterator(db.readDirCache()); + FileTreeIterator workTreeIter = new FileTreeIterator(db); + walk.addTree(indexIter); + walk.addTree(workTreeIter); + walk.setFilter(PathFilter.create(path)); + + assertTrue(walk.next()); + assertFalse(indexIter.idEqual(workTreeIter)); + assertEquals(ObjectId.zeroId(), workTreeIter.getEntryObjectId()); + } + + @Test + public void submoduleDirectoryIterator() throws Exception { + Git git = new Git(db); + writeTrashFile("file.txt", "content"); + git.add().addFilepattern("file.txt").call(); + final RevCommit id = git.commit().setMessage("create file").call(); + final String path = "sub"; + DirCache cache = db.lockDirCache(); + DirCacheEditor editor = cache.editor(); + editor.add(new PathEdit(path) { + + public void apply(DirCacheEntry ent) { + ent.setFileMode(FileMode.GITLINK); + ent.setObjectId(id); + } + }); + editor.commit(); + + Git.cloneRepository().setURI(db.getDirectory().toURI().toString()) + .setDirectory(new File(db.getWorkTree(), path)).call(); + + TreeWalk walk = new TreeWalk(db); + DirCacheIterator indexIter = new DirCacheIterator(db.readDirCache()); + FileTreeIterator workTreeIter = new FileTreeIterator(db.getWorkTree(), + db.getFS(), db.getConfig().get(WorkingTreeOptions.KEY)); + walk.addTree(indexIter); + walk.addTree(workTreeIter); + walk.setFilter(PathFilter.create(path)); + + assertTrue(walk.next()); + assertTrue(indexIter.idEqual(workTreeIter)); + } + + @Test + public void submoduleNestedWithHeadMatchingIndex() throws Exception { + Git git = new Git(db); + writeTrashFile("file.txt", "content"); + git.add().addFilepattern("file.txt").call(); + final RevCommit id = git.commit().setMessage("create file").call(); + final String path = "sub/dir1/dir2"; + DirCache cache = db.lockDirCache(); + DirCacheEditor editor = cache.editor(); + editor.add(new PathEdit(path) { + + public void apply(DirCacheEntry ent) { + ent.setFileMode(FileMode.GITLINK); + ent.setObjectId(id); + } + }); + editor.commit(); + + Git.cloneRepository().setURI(db.getDirectory().toURI().toString()) + .setDirectory(new File(db.getWorkTree(), path)).call(); + + TreeWalk walk = new TreeWalk(db); + DirCacheIterator indexIter = new DirCacheIterator(db.readDirCache()); + FileTreeIterator workTreeIter = new FileTreeIterator(db); + walk.addTree(indexIter); + walk.addTree(workTreeIter); + walk.setFilter(PathFilter.create(path)); + + assertTrue(walk.next()); + assertTrue(indexIter.idEqual(workTreeIter)); + } + private static String nameOf(final AbstractTreeIterator i) { return RawParseUtils.decode(Constants.CHARSET, i.path, 0, i.pathLen); } |