Fixed a problem sending include rules to an older rsync.
[rsync/rsync.git] / testsuite / exclude.test
... / ...
CommitLineData
1#! /bin/sh
2
3# Copyright (C) 2003, 2004, 2005 by Wayne Davison <wayned@samba.org>
4
5# This program is distributable under the terms of the GNU GPL see
6# COPYING).
7
8# Test rsync handling of exclude/include directives.
9
10# Test some of the more obscure wildcard handling of exclude/include
11# processing.
12
13. "$suitedir/rsync.fns"
14
15HOME="$scratchdir"
16CVSIGNORE='*.junk'
17export HOME CVSIGNORE
18
19# Build some files/dirs/links to copy
20
21makepath "$fromdir/foo/down/to/you"
22makepath "$fromdir/bar/down/to/foo/too"
23makepath "$fromdir/bar/down/to/bar/baz"
24makepath "$fromdir/mid/for/foo/and/that/is/who"
25cat >"$fromdir/.filt" <<EOF
26exclude down
27: .filt-temp
28clear
29- .filt
30- *.bak
31- *.old
32EOF
33echo kept >"$fromdir/foo/file1"
34echo removed >"$fromdir/foo/file2"
35echo cvsout >"$fromdir/foo/file2.old"
36cat >"$fromdir/foo/.filt" <<EOF
37include .filt
38- file1
39EOF
40cat >"$fromdir/bar/.filt" <<EOF
41- home-cvs-exclude
42dir-merge .filt2
43+ to
44EOF
45echo cvsout >"$fromdir/bar/down/to/home-cvs-exclude"
46cat >"$fromdir/bar/down/to/.filt2" <<EOF
47- .filt2
48EOF
49cat >"$fromdir/bar/down/to/foo/.filt2" <<EOF
50+ *.junk
51EOF
52echo keeper >"$fromdir/bar/down/to/foo/file1"
53echo cvsout >"$fromdir/bar/down/to/foo/file1.bak"
54echo gone >"$fromdir/bar/down/to/foo/file3"
55echo lost >"$fromdir/bar/down/to/foo/file4"
56echo weird >"$fromdir/bar/down/to/foo/+ file3"
57echo cvsout-but-filtin >"$fromdir/bar/down/to/foo/file4.junk"
58echo smashed >"$fromdir/bar/down/to/foo/to"
59cat >"$fromdir/bar/down/to/bar/.filt2" <<EOF
60- *.deep
61EOF
62echo filtout >"$fromdir/bar/down/to/bar/baz/file5.deep"
63# This one should be ineffectual
64cat >"$fromdir/mid/.filt2" <<EOF
65- extra
66EOF
67echo cvsout >"$fromdir/mid/one-in-one-out"
68echo one-in-one-out >"$fromdir/mid/.cvsignore"
69echo cvsin >"$fromdir/mid/one-for-all"
70cat >"$fromdir/mid/.filt" <<EOF
71:C
72EOF
73echo cvsin >"$fromdir/mid/for/one-in-one-out"
74echo expunged >"$fromdir/mid/for/foo/extra"
75echo retained >"$fromdir/mid/for/foo/keep"
76ln -s too "$fromdir/bar/down/to/foo/sym"
77
78# Setup our test exclude/include files.
79
80excl="$scratchdir/exclude-from"
81cat >"$excl" <<EOF
82!
83# If the second line of these two lines does anything, it's a bug.
84+ **/bar
85- /bar
86# This should match against the whole path, not just the name.
87+ foo**too
88# This should float at the end of the path.
89- foo/*/
90# Test some normal excludes. Competing lines are paired.
91+ t[o]/
92- to
93+ file4
94- file[2-9]
95- /mid/for/foo/extra
96EOF
97
98cat >"$scratchdir/.cvsignore" <<EOF
99home-cvs-exclude
100EOF
101
102# Create the chk dir with what we expect to be excluded
103
104checkit "$RSYNC -avv \"$fromdir/\" \"$chkdir/\"" "$fromdir" "$chkdir"
105
106sleep 1 # Ensures that the rm commands will tweak the directory times.
107
108rm -r "$chkdir"/foo/down
109rm -r "$chkdir"/mid/for/foo/and
110rm "$chkdir"/foo/file[235-9]
111rm "$chkdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo/file[235-9]
112rm "$chkdir"/mid/for/foo/extra
113
114# Un-tweak the directory times in our first (weak) exclude test (though
115# it's a good test of the --existing option).
116$RSYNC -av --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/"
117
118# Now, test if rsync excludes the same files.
119
120checkit "$RSYNC -avv --exclude-from=\"$excl\" \
121 --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
122
123# Modify the chk dir by removing cvs-ignored files and then tweaking the dir times.
124
125rm "$chkdir"/foo/*.old
126rm "$chkdir"/bar/down/to/foo/*.bak
127rm "$chkdir"/bar/down/to/foo/*.junk
128rm "$chkdir"/bar/down/to/home-cvs-exclude
129rm "$chkdir"/mid/one-in-one-out
130
131$RSYNC -av --existing --filter='exclude,! */' "$fromdir/" "$chkdir/"
132
133# Now, test if rsync excludes the same files, this time with --cvs-exclude
134# and --delete-excluded.
135
136checkit "$RSYNC -avvC --filter=\"merge $excl\" --delete-excluded \
137 --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
138
139# Modify the chk dir for our merge-exclude test and then tweak the dir times.
140
141rm "$chkdir"/foo/file1
142rm "$chkdir"/bar/down/to/bar/baz/*.deep
143cp -p "$fromdir"/bar/down/to/foo/*.junk "$chkdir"/bar/down/to/foo
144cp -p "$fromdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo
145
146$RSYNC -av --existing -f 'show .filt*' -f 'hide,! */' --del "$fromdir/" "$todir/"
147
148echo retained >"$todir"/bar/down/to/bar/baz/nodel.deep
149cp -p "$todir"/bar/down/to/bar/baz/nodel.deep "$chkdir"/bar/down/to/bar/baz
150
151$RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
152
153# Now, test if rsync excludes the same files, this time with a merge-exclude
154# file.
155
156checkit "sed '/!/d' \"$excl\" |
157 $RSYNC -avv -f dir-merge_.filt -f merge_- \
158 --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
159
160# Remove the files that will be deleted.
161
162rm "$chkdir"/.filt
163rm "$chkdir"/bar/.filt
164rm "$chkdir"/bar/down/to/.filt2
165rm "$chkdir"/bar/down/to/foo/.filt2
166rm "$chkdir"/bar/down/to/bar/.filt2
167rm "$chkdir"/mid/.filt
168
169$RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
170
171# Now, try the prior command with --delete-before and some side-specific
172# rules.
173
174checkit "sed '/!/d' \"$excl\" |
175 $RSYNC -avv -f :s_.filt -f .s_- -f P_nodel.deep \
176 --delete-before \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
177
178# Next, we'll test some rule-restricted filter files.
179
180cat >"$fromdir/bar/down/.excl" <<EOF
181file3
182EOF
183cat >"$fromdir/bar/down/to/foo/.excl" <<EOF
184+ file3
185*.bak
186EOF
187$RSYNC -av --del "$fromdir/" "$chkdir/"
188rm "$chkdir/bar/down/to/foo/file1.bak"
189rm "$chkdir/bar/down/to/foo/file3"
190rm "$chkdir/bar/down/to/foo/+ file3"
191$RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
192$RSYNC -av --delete-excluded --exclude='*' "$fromdir/" "$todir/"
193
194checkit "$RSYNC -avv -f dir-merge,-_.excl \
195 \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
196
197# The script would have aborted on error, so getting here means we've won.
198exit 0