git grep: use pager
[git.git] / t / t3600-rm.sh
blobe31cf93a00ab377355734b3d88d536d36fe734e1
1 #!/bin/sh
3 # Copyright (c) 2006 Carl D. Worth
6 test_description='Test of the various options to git-rm.'
8 . ./test-lib.sh
10 # Setup some files to be removed, some with funny characters
11 test_expect_success \
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' &&
16 test_tabs=y &&
17 if touch -- 'tab embedded' 'newline
18 embedded'
19 then
20 git-add -- 'tab embedded' 'newline
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"
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
30 # arranged.
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'
40 test_expect_success \
41 'Pre-check that foo exists and is in index before git-rm foo' \
42 '[ -f foo ] && git-ls-files --error-unmatch foo'
44 test_expect_success \
45 'Test that git-rm foo succeeds' \
46 'git-rm --cached foo'
48 test_expect_success \
49 'Post-check that foo exists but is not in index after git-rm foo' \
50 '[ -f foo ] && ! git-ls-files --error-unmatch foo'
52 test_expect_success \
53 'Pre-check that bar exists and is in index before "git-rm bar"' \
54 '[ -f bar ] && git-ls-files --error-unmatch bar'
56 test_expect_success \
57 'Test that "git-rm bar" succeeds' \
58 'git-rm bar'
60 test_expect_success \
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'
64 test_expect_success \
65 'Test that "git-rm -- -q" succeeds (remove a file that looks like an option)' \
66 'git-rm -- -q'
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
71 embedded'"
73 if test "$test_failed_remove" = y; then
74 chmod a-w .
75 test_expect_failure \
76 'Test that "git-rm -f" fails if its rm fails' \
77 'git-rm -f baz'
78 chmod 775 .
79 else
80 test_expect_success 'skipping removal failure (perhaps running as root?)' :
83 test_expect_success \
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 # Now, failure cases.
88 test_expect_success 'Re-add foo and baz' '
89 git add foo baz &&
90 git ls-files --error-unmatch foo baz
93 test_expect_success 'Modify foo -- rm should refuse' '
94 echo >>foo &&
95 ! git rm foo baz &&
96 test -f foo &&
97 test -f baz &&
98 git ls-files --error-unmatch foo baz
101 test_expect_success 'Modified foo -- rm -f should work' '
102 git rm -f foo baz &&
103 test ! -f foo &&
104 test ! -f baz &&
105 ! git ls-files --error-unmatch foo &&
106 ! git ls-files --error-unmatch bar
109 test_expect_success 'Re-add foo and baz for HEAD tests' '
110 echo frotz >foo &&
111 git checkout HEAD -- baz &&
112 git add foo baz &&
113 git ls-files --error-unmatch foo baz
116 test_expect_success 'foo is different in index from HEAD -- rm should refuse' '
117 ! git rm foo baz &&
118 test -f foo &&
119 test -f baz &&
120 git ls-files --error-unmatch foo baz
123 test_expect_success 'but with -f it should work.' '
124 git rm -f foo baz &&
125 test ! -f foo &&
126 test ! -f baz &&
127 ! git ls-files --error-unmatch foo
128 ! git ls-files --error-unmatch baz
131 test_expect_success 'Recursive test setup' '
132 mkdir -p frotz &&
133 echo qfwfq >frotz/nitfol &&
134 git add frotz &&
135 git commit -m "subdir test"
138 test_expect_success 'Recursive without -r fails' '
139 ! git rm frotz &&
140 test -d frotz &&
141 test -f frotz/nitfol
144 test_expect_success 'Recursive with -r but dirty' '
145 echo qfwfq >>frotz/nitfol
146 ! git rm -r frotz &&
147 test -d frotz &&
148 test -f frotz/nitfol
151 test_expect_success 'Recursive with -r -f' '
152 git rm -f -r frotz &&
153 ! test -f frotz/nitfol &&
154 ! test -d frotz
157 test_done