3 # Copyright (c) 2006 Carl D. Worth
6 test_description
='Test of the various options to git-rm.'
10 # Setup some files to be removed, some with funny characters
12 'Initialize test directory' \
13 "touch -- foo bar baz 'space embedded' -q &&
14 git-add -- foo bar baz 'space embedded' -q &&
15 git-commit -m 'add normal files' &&
17 if touch -- 'tab embedded' 'newline
20 git-add -- 'tab embedded' 'newline
22 git-commit -m 'add files with tabs and newlines'
24 say 'Your filesystem does not allow tabs in filenames.'
28 # Later we will try removing an unremovable path to make sure
29 # git-rm barfs, but if the test is run as root that cannot be
32 'Determine rm behavior' \
36 test -f test-file && test_failed_remove=y
41 'Pre-check that foo exists and is in index before git-rm foo' \
42 '[ -f foo ] && git-ls-files --error-unmatch foo'
45 'Test that git-rm foo succeeds' \
49 'Post-check that foo exists but is not in index after git-rm foo' \
50 '[ -f foo ] && ! git-ls-files --error-unmatch foo'
53 'Pre-check that bar exists and is in index before "git-rm bar"' \
54 '[ -f bar ] && git-ls-files --error-unmatch bar'
57 'Test that "git-rm bar" succeeds' \
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'
65 'Test that "git-rm -- -q" succeeds (remove a file that looks like an option)' \
68 test "$test_tabs" = y
&& test_expect_success \
69 "Test that \"git-rm -f\" succeeds with embedded space, tab, or newline characters." \
70 "git-rm -f 'space embedded' 'tab embedded' 'newline
73 if test "$test_failed_remove" = y
; then
76 'Test that "git-rm -f" fails if its rm fails' \
80 test_expect_success
'skipping removal failure (perhaps running as root?)' :
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'
87 test_expect_success
'Remove nonexistent file with --ignore-unmatch' '
88 git rm --ignore-unmatch nonexistent
91 test_expect_success
'"rm" command printed' '
92 echo frotz > 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"
101 test_expect_success
'"rm" command suppressed with --quiet' '
102 echo frotz > 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"
111 # Now, failure cases.
112 test_expect_success
'Re-add foo and baz' '
114 git ls-files --error-unmatch foo baz
117 test_expect_success
'Modify foo -- rm should refuse' '
122 git ls-files --error-unmatch foo baz
125 test_expect_success
'Modified foo -- rm -f should work' '
129 ! git ls-files --error-unmatch foo &&
130 ! git ls-files --error-unmatch bar
133 test_expect_success
'Re-add foo and baz for HEAD tests' '
135 git checkout HEAD -- baz &&
137 git ls-files --error-unmatch foo baz
140 test_expect_success
'foo is different in index from HEAD -- rm should refuse' '
144 git ls-files --error-unmatch foo baz
147 test_expect_success
'but with -f it should work.' '
151 ! git ls-files --error-unmatch foo
152 ! git ls-files --error-unmatch baz
155 test_expect_success
'Recursive test setup' '
157 echo qfwfq >frotz/nitfol &&
159 git commit -m "subdir test"
162 test_expect_success
'Recursive without -r fails' '
168 test_expect_success
'Recursive with -r but dirty' '
169 echo qfwfq >>frotz/nitfol
175 test_expect_success
'Recursive with -r -f' '
176 git rm -f -r frotz &&
177 ! test -f frotz/nitfol &&
181 test_expect_failure
'Remove nonexistent file returns nonzero exit status' '