1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 package org.eclipse.jgit.pgm;
44
45 import static org.eclipse.jgit.junit.JGitTestUtil.check;
46 import static org.junit.Assert.assertEquals;
47 import static org.junit.Assert.assertFalse;
48 import static org.junit.Assert.assertTrue;
49
50 import org.eclipse.jgit.api.Git;
51 import org.eclipse.jgit.lib.CLIRepositoryTestCase;
52 import org.junit.Test;
53
54 public class CleanTest extends CLIRepositoryTestCase {
55 @Test
56 public void testCleanRequiresForce() throws Exception {
57 try (Git git = new Git(db)) {
58 assertArrayOfLinesEquals(
59 new String[] { "Removing a", "Removing b" },
60 execute("git clean"));
61 } catch (Die e) {
62
63
64
65 assertEquals(
66 "fatal: clean.requireForce defaults to true and neither -n nor -f given; refusing to clean",
67 e.getMessage());
68 }
69 }
70
71 @Test
72 public void testCleanRequiresForceConfig() throws Exception {
73 try (Git git = new Git(db)) {
74 git.getRepository().getConfig().setBoolean("clean", null,
75 "requireForce", false);
76 assertArrayOfLinesEquals(
77 new String[] { "" },
78 execute("git clean"));
79 }
80 }
81
82 @Test
83 public void testCleanLeaveDirs() throws Exception {
84 try (Git git = new Git(db)) {
85 git.commit().setMessage("initial commit").call();
86
87 writeTrashFile("dir/file", "someData");
88 writeTrashFile("a", "someData");
89 writeTrashFile("b", "someData");
90
91
92 assertTrue(check(db, "a"));
93 assertTrue(check(db, "b"));
94 assertTrue(check(db, "dir/file"));
95
96
97 assertArrayOfLinesEquals(
98 new String[] { "Removing a", "Removing b" },
99 execute("git clean -n"));
100 assertTrue(check(db, "a"));
101 assertTrue(check(db, "b"));
102 assertTrue(check(db, "dir/file"));
103
104
105 assertArrayOfLinesEquals(
106 new String[] { "Removing a", "Removing b" },
107 execute("git clean -f"));
108 assertFalse(check(db, "a"));
109 assertFalse(check(db, "b"));
110 assertTrue(check(db, "dir/file"));
111 }
112 }
113
114 @Test
115 public void testCleanDeleteDirs() throws Exception {
116 try (Git git = new Git(db)) {
117 git.commit().setMessage("initial commit").call();
118
119 writeTrashFile("dir/file", "someData");
120 writeTrashFile("a", "someData");
121 writeTrashFile("b", "someData");
122
123
124 assertTrue(check(db, "a"));
125 assertTrue(check(db, "b"));
126 assertTrue(check(db, "dir/file"));
127
128 assertArrayOfLinesEquals(
129 new String[] { "Removing a", "Removing b",
130 "Removing dir/" },
131 execute("git clean -d -f"));
132 assertFalse(check(db, "a"));
133 assertFalse(check(db, "b"));
134 assertFalse(check(db, "dir/file"));
135 }
136 }
137 }