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