Merge branch 'lt/apply'
[git/git.git] / t / t3600-rm.sh
CommitLineData
d4a1cab5
CW
1#!/bin/sh
2#
3# Copyright (c) 2006 Carl D. Worth
4#
5
6test_description='Test of the various options to git-rm.'
7
8. ./test-lib.sh
9
3844cdc8 10# Setup some files to be removed, some with funny characters
d51fac53
AR
11touch -- foo bar baz 'space embedded' -q
12git-add -- foo bar baz 'space embedded' -q
13git-commit -m "add normal files"
14test_tabs=y
15if touch -- 'tab embedded' 'newline
16embedded'
17then
18git-add -- 'tab embedded' 'newline
19embedded'
20git-commit -m "add files with tabs and newlines"
21else
22 say 'Your filesystem does not allow tabs in filenames.'
23 test_tabs=n
24fi
d4a1cab5 25
2283645b
JH
26# Later we will try removing an unremovable path to make sure
27# git-rm barfs, but if the test is run as root that cannot be
28# arranged.
29: >test-file
30chmod a-w .
31rm -f test-file
32test -f test-file && test_failed_remove=y
33chmod 775 .
34rm -f test-file
35
d4a1cab5 36test_expect_success \
3844cdc8
CW
37 'Pre-check that foo exists and is in index before git-rm foo' \
38 '[ -f foo ] && git-ls-files --error-unmatch foo'
d4a1cab5
CW
39
40test_expect_success \
41 'Test that git-rm foo succeeds' \
42 'git-rm foo'
43
3844cdc8
CW
44test_expect_success \
45 'Post-check that foo exists but is not in index after git-rm foo' \
46 '[ -f foo ] && ! git-ls-files --error-unmatch foo'
47
48test_expect_success \
49 'Pre-check that bar exists and is in index before "git-rm -f bar"' \
50 '[ -f bar ] && git-ls-files --error-unmatch bar'
d4a1cab5
CW
51
52test_expect_success \
3844cdc8 53 'Test that "git-rm -f bar" succeeds' \
d4a1cab5
CW
54 'git-rm -f bar'
55
3844cdc8
CW
56test_expect_success \
57 'Post-check that bar does not exist and is not in index after "git-rm -f bar"' \
58 '! [ -f bar ] && ! git-ls-files --error-unmatch bar'
d4a1cab5
CW
59
60test_expect_success \
3844cdc8 61 'Test that "git-rm -- -q" succeeds (remove a file that looks like an option)' \
d4a1cab5
CW
62 'git-rm -- -q'
63
d51fac53 64test "$test_tabs" = y && test_expect_success \
3844cdc8
CW
65 "Test that \"git-rm -f\" succeeds with embedded space, tab, or newline characters." \
66 "git-rm -f 'space embedded' 'tab embedded' 'newline
67embedded'"
68
2283645b
JH
69if test "$test_failed_remove" = y; then
70chmod a-w .
3844cdc8
CW
71test_expect_failure \
72 'Test that "git-rm -f" fails if its rm fails' \
73 'git-rm -f baz'
2283645b
JH
74chmod 775 .
75else
76 test_expect_success 'skipping removal failure (perhaps running as root?)' :
d51fac53 77fi
3844cdc8
CW
78
79test_expect_success \
80 'When the rm in "git-rm -f" fails, it should not remove the file from the index' \
81 'git-ls-files --error-unmatch baz'
82
d4a1cab5 83test_done