diff options
author | Robin Rosenberg | 2010-12-18 22:31:37 +0000 |
---|---|---|
committer | Robin Rosenberg | 2010-12-19 10:35:59 +0000 |
commit | 056ca0e4d90e3c4397ee6902974d64ce0b46fa9e (patch) | |
tree | 1f146f4ca296065526f01a0ee49474f34203a1e2 /org.eclipse.egit.core.test/src/org/eclipse/egit | |
parent | 58c8f1d7a963f56fb4b8e4a896b39fcde1172a2d (diff) | |
download | egit-056ca0e4d90e3c4397ee6902974d64ce0b46fa9e.tar.gz egit-056ca0e4d90e3c4397ee6902974d64ce0b46fa9e.tar.xz egit-056ca0e4d90e3c4397ee6902974d64ce0b46fa9e.zip |
Interactive commit should delete empty trees
The commit operation as used from the commit dialog did not delete
trees when they became empty. Today Git does not leave empty trees,
it is not intended here and the user certainly does not expect it.
We also add a testcase for this, though the tests for the CommitOperation
lack a lot in general as the logic is not tested anywhere else. Moving
to DirCache will probably reduce the number of needed tests at this
place.
Bug: 314105
Change-Id: I897e364e476f942f8c5361a809f5fd849a972fee
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
Diffstat (limited to 'org.eclipse.egit.core.test/src/org/eclipse/egit')
-rw-r--r-- | org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/CommitOperationTest.java | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/CommitOperationTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/CommitOperationTest.java index 9bcb3324f5..9ee73f1c6e 100644 --- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/CommitOperationTest.java +++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/CommitOperationTest.java @@ -10,6 +10,7 @@ package org.eclipse.egit.core.test.op; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.io.File; @@ -28,6 +29,7 @@ import org.eclipse.jgit.api.Git; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.RevCommit; +import org.eclipse.jgit.treewalk.TreeWalk; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -102,4 +104,63 @@ public class CommitOperationTest extends GitTestCase { assertEquals("The.committer@some.com", secondCommit.getCommitterIdent().getEmailAddress()); } + @Test + public void testCommitEmptiedTree() throws Exception { + // Set up a directory structure + testUtils.addFileToProject(project.getProject(), + "sub1/a.txt", "some text"); + testUtils.addFileToProject(project.getProject(), + "sub2/b.txt", "some text"); + resources.add(project.getProject().getFolder("sub1")); + resources.add(project.getProject().getFolder("sub2")); + new AddToIndexOperation(resources).execute(null); + CommitOperation commitOperation = new CommitOperation(null, null, null, + TestUtils.AUTHOR, TestUtils.COMMITTER, + "first commit"); + commitOperation.setCommitAll(true); + commitOperation.setRepos(new Repository[]{repository}); + commitOperation.execute(null); + + Git git = new Git(repository); + Iterator<RevCommit> commits = git.log().call().iterator(); + RevCommit secondCommit = commits.next(); + TreeWalk treeWalk = new TreeWalk(repository); + treeWalk.addTree(secondCommit.getTree().getId()); + treeWalk.setRecursive(true); + treeWalk.setPostOrderTraversal(true); + assertTrue(treeWalk.next()); + assertEquals("sub1/a.txt", treeWalk.getPathString()); + assertTrue(treeWalk.next()); + assertEquals("sub1", treeWalk.getPathString()); + assertTrue(treeWalk.next()); + assertEquals("sub2/b.txt", treeWalk.getPathString()); + assertTrue(treeWalk.next()); + assertEquals("sub2", treeWalk.getPathString()); + assertFalse(treeWalk.next()); + + project.getProject().getFolder("sub2").delete(IResource.FORCE, null); + IFile[] filesToCommit = { project.getProject().getFile("sub2/b.txt") }; + ArrayList<IFile> notIndexed = new ArrayList<IFile>(); + notIndexed.add(filesToCommit[0]); + ArrayList<IFile> notTracked = new ArrayList<IFile>(); + Thread.sleep(1100); // Trouble in "fresh" detection of something + // Do this like the commit dialog does it + commitOperation = new CommitOperation(filesToCommit, notIndexed, notTracked, TestUtils.AUTHOR, TestUtils.COMMITTER, "second commit"); + commitOperation.setCommitAll(false); + commitOperation.execute(null); + + Thread.sleep(1100); // Trouble in "fresh" detection of something + git = new Git(repository); + commits = git.log().call().iterator(); + secondCommit = commits.next(); + treeWalk = new TreeWalk(repository); + treeWalk.addTree(secondCommit.getTree().getId()); + treeWalk.setRecursive(true); + treeWalk.setPostOrderTraversal(true); + assertTrue(treeWalk.next()); + assertEquals("sub1/a.txt", treeWalk.getPathString()); + assertTrue(treeWalk.next()); + assertEquals("sub1", treeWalk.getPathString()); + assertFalse(treeWalk.next()); + } } |