]>
Commit | Line | Data |
---|---|---|
d4a1cab5 CW |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2006 Carl D. Worth | |
4 | # | |
5 | ||
5be60078 | 6 | test_description='Test of the various options to git rm.' |
d4a1cab5 CW |
7 | |
8 | . ./test-lib.sh | |
9 | ||
3844cdc8 | 10 | # Setup some files to be removed, some with funny characters |
22669a04 SP |
11 | test_expect_success \ |
12 | 'Initialize test directory' \ | |
13 | "touch -- foo bar baz 'space embedded' -q && | |
5be60078 | 14 | git add -- foo bar baz 'space embedded' -q && |
22669a04 SP |
15 | git-commit -m 'add normal files' && |
16 | test_tabs=y && | |
17 | if touch -- 'tab embedded' 'newline | |
d51fac53 | 18 | embedded' |
22669a04 | 19 | then |
5be60078 | 20 | git add -- 'tab embedded' 'newline |
22669a04 SP |
21 | embedded' && |
22 | git-commit -m 'add files with tabs and newlines' | |
23 | else | |
24 | say 'Your filesystem does not allow tabs in filenames.' | |
25 | test_tabs=n | |
26 | fi" | |
d4a1cab5 | 27 | |
2283645b | 28 | # Later we will try removing an unremovable path to make sure |
5be60078 | 29 | # git rm barfs, but if the test is run as root that cannot be |
2283645b | 30 | # arranged. |
22669a04 SP |
31 | test_expect_success \ |
32 | 'Determine rm behavior' \ | |
33 | ': >test-file | |
34 | chmod a-w . | |
35 | rm -f test-file | |
36 | test -f test-file && test_failed_remove=y | |
37 | chmod 775 . | |
38 | rm -f test-file' | |
2283645b | 39 | |
d4a1cab5 | 40 | test_expect_success \ |
5be60078 JH |
41 | 'Pre-check that foo exists and is in index before git rm foo' \ |
42 | '[ -f foo ] && git ls-files --error-unmatch foo' | |
d4a1cab5 CW |
43 | |
44 | test_expect_success \ | |
5be60078 JH |
45 | 'Test that git rm foo succeeds' \ |
46 | 'git rm --cached foo' | |
d4a1cab5 | 47 | |
bdecd9d4 MM |
48 | test_expect_success \ |
49 | 'Test that git rm --cached foo succeeds if the index matches the file' \ | |
50 | 'echo content > foo | |
51 | git add foo | |
52 | git rm --cached foo' | |
53 | ||
54 | test_expect_success \ | |
55 | 'Test that git rm --cached foo succeeds if the index matches the file' \ | |
56 | 'echo content > foo | |
57 | git add foo | |
58 | git commit -m foo | |
59 | echo "other content" > foo | |
60 | git rm --cached foo' | |
61 | ||
41ac414e JH |
62 | test_expect_success \ |
63 | 'Test that git rm --cached foo fails if the index matches neither the file nor HEAD' ' | |
64 | echo content > foo | |
bdecd9d4 MM |
65 | git add foo |
66 | git commit -m foo | |
67 | echo "other content" > foo | |
68 | git add foo | |
69 | echo "yet another content" > foo | |
41ac414e JH |
70 | ! git rm --cached foo |
71 | ' | |
bdecd9d4 MM |
72 | |
73 | test_expect_success \ | |
74 | 'Test that git rm --cached -f foo works in case where --cached only did not' \ | |
75 | 'echo content > foo | |
76 | git add foo | |
77 | git commit -m foo | |
78 | echo "other content" > foo | |
79 | git add foo | |
80 | echo "yet another content" > foo | |
81 | git rm --cached -f foo' | |
82 | ||
3844cdc8 | 83 | test_expect_success \ |
5be60078 JH |
84 | 'Post-check that foo exists but is not in index after git rm foo' \ |
85 | '[ -f foo ] && ! git ls-files --error-unmatch foo' | |
3844cdc8 CW |
86 | |
87 | test_expect_success \ | |
5be60078 JH |
88 | 'Pre-check that bar exists and is in index before "git rm bar"' \ |
89 | '[ -f bar ] && git ls-files --error-unmatch bar' | |
d4a1cab5 CW |
90 | |
91 | test_expect_success \ | |
5be60078 JH |
92 | 'Test that "git rm bar" succeeds' \ |
93 | 'git rm bar' | |
d4a1cab5 | 94 | |
3844cdc8 | 95 | test_expect_success \ |
5be60078 JH |
96 | 'Post-check that bar does not exist and is not in index after "git rm -f bar"' \ |
97 | '! [ -f bar ] && ! git ls-files --error-unmatch bar' | |
d4a1cab5 CW |
98 | |
99 | test_expect_success \ | |
5be60078 JH |
100 | 'Test that "git rm -- -q" succeeds (remove a file that looks like an option)' \ |
101 | 'git rm -- -q' | |
d4a1cab5 | 102 | |
d51fac53 | 103 | test "$test_tabs" = y && test_expect_success \ |
5be60078 JH |
104 | "Test that \"git rm -f\" succeeds with embedded space, tab, or newline characters." \ |
105 | "git rm -f 'space embedded' 'tab embedded' 'newline | |
3844cdc8 CW |
106 | embedded'" |
107 | ||
2283645b JH |
108 | if test "$test_failed_remove" = y; then |
109 | chmod a-w . | |
41ac414e | 110 | test_expect_success \ |
5be60078 | 111 | 'Test that "git rm -f" fails if its rm fails' \ |
41ac414e | 112 | '! git rm -f baz' |
2283645b JH |
113 | chmod 775 . |
114 | else | |
115 | test_expect_success 'skipping removal failure (perhaps running as root?)' : | |
d51fac53 | 116 | fi |
3844cdc8 CW |
117 | |
118 | test_expect_success \ | |
5be60078 JH |
119 | 'When the rm in "git rm -f" fails, it should not remove the file from the index' \ |
120 | 'git ls-files --error-unmatch baz' | |
3844cdc8 | 121 | |
bb1faf0d SG |
122 | test_expect_success 'Remove nonexistent file with --ignore-unmatch' ' |
123 | git rm --ignore-unmatch nonexistent | |
124 | ' | |
125 | ||
b48caa20 SG |
126 | test_expect_success '"rm" command printed' ' |
127 | echo frotz > test-file && | |
128 | git add test-file && | |
129 | git commit -m "add file for rm test" && | |
130 | git rm test-file > rm-output && | |
0feb4d1c | 131 | test `grep "^rm " rm-output | wc -l` = 1 && |
b48caa20 SG |
132 | rm -f test-file rm-output && |
133 | git commit -m "remove file from rm test" | |
134 | ' | |
135 | ||
136 | test_expect_success '"rm" command suppressed with --quiet' ' | |
137 | echo frotz > test-file && | |
138 | git add test-file && | |
139 | git commit -m "add file for rm --quiet test" && | |
140 | git rm --quiet test-file > rm-output && | |
141 | test `wc -l < rm-output` = 0 && | |
142 | rm -f test-file rm-output && | |
143 | git commit -m "remove file from rm --quiet test" | |
144 | ' | |
145 | ||
467e1b53 JH |
146 | # Now, failure cases. |
147 | test_expect_success 'Re-add foo and baz' ' | |
148 | git add foo baz && | |
149 | git ls-files --error-unmatch foo baz | |
150 | ' | |
151 | ||
152 | test_expect_success 'Modify foo -- rm should refuse' ' | |
153 | echo >>foo && | |
154 | ! git rm foo baz && | |
155 | test -f foo && | |
156 | test -f baz && | |
157 | git ls-files --error-unmatch foo baz | |
158 | ' | |
159 | ||
160 | test_expect_success 'Modified foo -- rm -f should work' ' | |
161 | git rm -f foo baz && | |
162 | test ! -f foo && | |
163 | test ! -f baz && | |
164 | ! git ls-files --error-unmatch foo && | |
165 | ! git ls-files --error-unmatch bar | |
166 | ' | |
167 | ||
168 | test_expect_success 'Re-add foo and baz for HEAD tests' ' | |
169 | echo frotz >foo && | |
170 | git checkout HEAD -- baz && | |
171 | git add foo baz && | |
172 | git ls-files --error-unmatch foo baz | |
173 | ' | |
174 | ||
175 | test_expect_success 'foo is different in index from HEAD -- rm should refuse' ' | |
176 | ! git rm foo baz && | |
177 | test -f foo && | |
178 | test -f baz && | |
179 | git ls-files --error-unmatch foo baz | |
180 | ' | |
181 | ||
182 | test_expect_success 'but with -f it should work.' ' | |
183 | git rm -f foo baz && | |
184 | test ! -f foo && | |
185 | test ! -f baz && | |
186 | ! git ls-files --error-unmatch foo | |
187 | ! git ls-files --error-unmatch baz | |
188 | ' | |
189 | ||
190 | test_expect_success 'Recursive test setup' ' | |
191 | mkdir -p frotz && | |
192 | echo qfwfq >frotz/nitfol && | |
193 | git add frotz && | |
194 | git commit -m "subdir test" | |
195 | ' | |
196 | ||
197 | test_expect_success 'Recursive without -r fails' ' | |
198 | ! git rm frotz && | |
199 | test -d frotz && | |
200 | test -f frotz/nitfol | |
201 | ' | |
202 | ||
203 | test_expect_success 'Recursive with -r but dirty' ' | |
204 | echo qfwfq >>frotz/nitfol | |
205 | ! git rm -r frotz && | |
206 | test -d frotz && | |
207 | test -f frotz/nitfol | |
208 | ' | |
209 | ||
210 | test_expect_success 'Recursive with -r -f' ' | |
211 | git rm -f -r frotz && | |
212 | ! test -f frotz/nitfol && | |
213 | ! test -d frotz | |
214 | ' | |
215 | ||
41ac414e JH |
216 | test_expect_success 'Remove nonexistent file returns nonzero exit status' ' |
217 | ! git rm nonexistent | |
b48caa20 SG |
218 | ' |
219 | ||
d4a1cab5 | 220 | test_done |