]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3600-rm.sh
Rewrite "git-frotz" to "git frotz"
[thirdparty/git.git] / t / t3600-rm.sh
CommitLineData
d4a1cab5
CW
1#!/bin/sh
2#
3# Copyright (c) 2006 Carl D. Worth
4#
5
5be60078 6test_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
11test_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 18embedded'
22669a04 19 then
5be60078 20 git add -- 'tab embedded' 'newline
22669a04
SP
21embedded' &&
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
31test_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 40test_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
44test_expect_success \
5be60078
JH
45 'Test that git rm foo succeeds' \
46 'git rm --cached foo'
d4a1cab5 47
3844cdc8 48test_expect_success \
5be60078
JH
49 'Post-check that foo exists but is not in index after git rm foo' \
50 '[ -f foo ] && ! git ls-files --error-unmatch foo'
3844cdc8
CW
51
52test_expect_success \
5be60078
JH
53 'Pre-check that bar exists and is in index before "git rm bar"' \
54 '[ -f bar ] && git ls-files --error-unmatch bar'
d4a1cab5
CW
55
56test_expect_success \
5be60078
JH
57 'Test that "git rm bar" succeeds' \
58 'git rm bar'
d4a1cab5 59
3844cdc8 60test_expect_success \
5be60078
JH
61 'Post-check that bar does not exist and is not in index after "git rm -f bar"' \
62 '! [ -f bar ] && ! git ls-files --error-unmatch bar'
d4a1cab5
CW
63
64test_expect_success \
5be60078
JH
65 'Test that "git rm -- -q" succeeds (remove a file that looks like an option)' \
66 'git rm -- -q'
d4a1cab5 67
d51fac53 68test "$test_tabs" = y && test_expect_success \
5be60078
JH
69 "Test that \"git rm -f\" succeeds with embedded space, tab, or newline characters." \
70 "git rm -f 'space embedded' 'tab embedded' 'newline
3844cdc8
CW
71embedded'"
72
2283645b
JH
73if test "$test_failed_remove" = y; then
74chmod a-w .
3844cdc8 75test_expect_failure \
5be60078
JH
76 'Test that "git rm -f" fails if its rm fails' \
77 'git rm -f baz'
2283645b
JH
78chmod 775 .
79else
80 test_expect_success 'skipping removal failure (perhaps running as root?)' :
d51fac53 81fi
3844cdc8
CW
82
83test_expect_success \
5be60078
JH
84 'When the rm in "git rm -f" fails, it should not remove the file from the index' \
85 'git ls-files --error-unmatch baz'
3844cdc8 86
bb1faf0d
SG
87test_expect_success 'Remove nonexistent file with --ignore-unmatch' '
88 git rm --ignore-unmatch nonexistent
89'
90
b48caa20
SG
91test_expect_success '"rm" command printed' '
92 echo frotz > test-file &&
93 git add test-file &&
94 git commit -m "add file for rm test" &&
95 git rm test-file > rm-output &&
96 test `egrep "^rm " rm-output | wc -l` = 1 &&
97 rm -f test-file rm-output &&
98 git commit -m "remove file from rm test"
99'
100
101test_expect_success '"rm" command suppressed with --quiet' '
102 echo frotz > test-file &&
103 git add test-file &&
104 git commit -m "add file for rm --quiet test" &&
105 git rm --quiet test-file > rm-output &&
106 test `wc -l < rm-output` = 0 &&
107 rm -f test-file rm-output &&
108 git commit -m "remove file from rm --quiet test"
109'
110
467e1b53
JH
111# Now, failure cases.
112test_expect_success 'Re-add foo and baz' '
113 git add foo baz &&
114 git ls-files --error-unmatch foo baz
115'
116
117test_expect_success 'Modify foo -- rm should refuse' '
118 echo >>foo &&
119 ! git rm foo baz &&
120 test -f foo &&
121 test -f baz &&
122 git ls-files --error-unmatch foo baz
123'
124
125test_expect_success 'Modified foo -- rm -f should work' '
126 git rm -f foo baz &&
127 test ! -f foo &&
128 test ! -f baz &&
129 ! git ls-files --error-unmatch foo &&
130 ! git ls-files --error-unmatch bar
131'
132
133test_expect_success 'Re-add foo and baz for HEAD tests' '
134 echo frotz >foo &&
135 git checkout HEAD -- baz &&
136 git add foo baz &&
137 git ls-files --error-unmatch foo baz
138'
139
140test_expect_success 'foo is different in index from HEAD -- rm should refuse' '
141 ! git rm foo baz &&
142 test -f foo &&
143 test -f baz &&
144 git ls-files --error-unmatch foo baz
145'
146
147test_expect_success 'but with -f it should work.' '
148 git rm -f foo baz &&
149 test ! -f foo &&
150 test ! -f baz &&
151 ! git ls-files --error-unmatch foo
152 ! git ls-files --error-unmatch baz
153'
154
155test_expect_success 'Recursive test setup' '
156 mkdir -p frotz &&
157 echo qfwfq >frotz/nitfol &&
158 git add frotz &&
159 git commit -m "subdir test"
160'
161
162test_expect_success 'Recursive without -r fails' '
163 ! git rm frotz &&
164 test -d frotz &&
165 test -f frotz/nitfol
166'
167
168test_expect_success 'Recursive with -r but dirty' '
169 echo qfwfq >>frotz/nitfol
170 ! git rm -r frotz &&
171 test -d frotz &&
172 test -f frotz/nitfol
173'
174
175test_expect_success 'Recursive with -r -f' '
176 git rm -f -r frotz &&
177 ! test -f frotz/nitfol &&
178 ! test -d frotz
179'
180
b48caa20
SG
181test_expect_failure 'Remove nonexistent file returns nonzero exit status' '
182 git rm nonexistent
183'
184
d4a1cab5 185test_done