1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.api;
11
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertTrue;
14
15 import java.io.File;
16 import java.io.IOException;
17
18 import org.eclipse.jgit.api.errors.GitAPIException;
19 import org.eclipse.jgit.api.errors.JGitInternalException;
20 import org.eclipse.jgit.junit.RepositoryTestCase;
21 import org.junit.Before;
22 import org.junit.Test;
23
24 public class RmCommandTest extends RepositoryTestCase {
25
26 private Git git;
27
28 private static final String FILE = "test.txt";
29
30 @Override
31 @Before
32 public void setUp() throws Exception {
33 super.setUp();
34 git = new Git(db);
35
36 writeTrashFile(FILE, "Hello world");
37 git.add().addFilepattern(FILE).call();
38 git.commit().setMessage("Initial commit").call();
39 }
40
41 @Test
42 public void testRemove() throws JGitInternalException,
43 IllegalStateException, IOException, GitAPIException {
44 assertEquals("[test.txt, mode:100644, content:Hello world]",
45 indexState(CONTENT));
46 RmCommand command = git.rm();
47 command.addFilepattern(FILE);
48 command.call();
49 assertEquals("", indexState(CONTENT));
50 }
51
52 @Test
53 public void testRemoveCached() throws Exception {
54 File newFile = writeTrashFile("new.txt", "new");
55 git.add().addFilepattern(newFile.getName()).call();
56 assertEquals("[new.txt, mode:100644][test.txt, mode:100644]",
57 indexState(0));
58
59 git.rm().setCached(true).addFilepattern(newFile.getName()).call();
60
61 assertEquals("[test.txt, mode:100644]", indexState(0));
62 assertTrue("File should not have been removed.", newFile.exists());
63 }
64 }