Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Rosenberg2011-01-12 17:45:08 -0500
committerCode Review2011-01-12 17:45:08 -0500
commit793536b04173611f49a8a4c4e105cf39c4aef052 (patch)
tree95c73c9c153dd8509a5f6196e5a72f52518c565d /org.eclipse.egit.core.test
parent1ad7131564f00b7c67bb45deaa74f86c5132584e (diff)
parent056ca0e4d90e3c4397ee6902974d64ce0b46fa9e (diff)
downloadegit-793536b04173611f49a8a4c4e105cf39c4aef052.tar.gz
egit-793536b04173611f49a8a4c4e105cf39c4aef052.tar.xz
egit-793536b04173611f49a8a4c4e105cf39c4aef052.zip
Merge "Interactive commit should delete empty trees"
Diffstat (limited to 'org.eclipse.egit.core.test')
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/CommitOperationTest.java61
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 9bcb3324f..9ee73f1c6 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());
+ }
}

Back to the top