Make sure that our protocol-28 compatibility is OK.
[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 # Build some files/dirs/links to copy
20
21 makepath "$fromdir/foo/down/to/you"
22 makepath "$fromdir/bar/down/to/foo/too"
23 makepath "$fromdir/bar/down/to/bar/baz"
24 makepath "$fromdir/mid/for/foo/and/that/is/who"
25 cat >"$fromdir/.filt" <<EOF
26 exclude down
27 : .filt-temp
28 clear
29 - .filt
30 - *.bak
31 - *.old
32 EOF
33 echo kept >"$fromdir/foo/file1"
34 echo removed >"$fromdir/foo/file2"
35 echo cvsout >"$fromdir/foo/file2.old"
36 cat >"$fromdir/foo/.filt" <<EOF
37 include .filt
38 - file1
39 EOF
40 cat >"$fromdir/bar/.filt" <<EOF
41 - home-cvs-exclude
42 dir-merge .filt2
43 + to
44 EOF
45 echo cvsout >"$fromdir/bar/down/to/home-cvs-exclude"
46 cat >"$fromdir/bar/down/to/.filt2" <<EOF
47 - .filt2
48 EOF
49 cat >"$fromdir/bar/down/to/foo/.filt2" <<EOF
50 + *.junk
51 EOF
52 echo keeper >"$fromdir/bar/down/to/foo/file1"
53 echo cvsout >"$fromdir/bar/down/to/foo/file1.bak"
54 echo gone >"$fromdir/bar/down/to/foo/file3"
55 echo lost >"$fromdir/bar/down/to/foo/file4"
56 echo weird >"$fromdir/bar/down/to/foo/+ file3"
57 echo cvsout-but-filtin >"$fromdir/bar/down/to/foo/file4.junk"
58 echo smashed >"$fromdir/bar/down/to/foo/to"
59 cat >"$fromdir/bar/down/to/bar/.filt2" <<EOF
60 - *.deep
61 EOF
62 echo filtout >"$fromdir/bar/down/to/bar/baz/file5.deep"
63 # This one should be ineffectual
64 cat >"$fromdir/mid/.filt2" <<EOF
65 - extra
66 EOF
67 echo cvsout >"$fromdir/mid/one-in-one-out"
68 echo one-in-one-out >"$fromdir/mid/.cvsignore"
69 echo cvsin >"$fromdir/mid/one-for-all"
70 cat >"$fromdir/mid/.filt" <<EOF
71 :C
72 EOF
73 echo cvsin >"$fromdir/mid/for/one-in-one-out"
74 echo expunged >"$fromdir/mid/for/foo/extra"
75 echo retained >"$fromdir/mid/for/foo/keep"
76 ln -s too "$fromdir/bar/down/to/foo/sym"
77
78 # Setup our test exclude/include files.
79
80 excl="$scratchdir/exclude-from"
81 cat >"$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
96 EOF
97
98 cat >"$scratchdir/.cvsignore" <<EOF
99 home-cvs-exclude
100 EOF
101
102 # Create the chk dir with what we expect to be excluded
103
104 checkit "$RSYNC -avv \"$fromdir/\" \"$chkdir/\"" "$fromdir" "$chkdir"
105
106 sleep 1 # Ensures that the rm commands will tweak the directory times.
107
108 rm -r "$chkdir"/foo/down
109 rm -r "$chkdir"/mid/for/foo/and
110 rm "$chkdir"/foo/file[235-9]
111 rm "$chkdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo/file[235-9]
112 rm "$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
120 checkit "$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
125 rm "$chkdir"/foo/*.old
126 rm "$chkdir"/bar/down/to/foo/*.bak
127 rm "$chkdir"/bar/down/to/foo/*.junk
128 rm "$chkdir"/bar/down/to/home-cvs-exclude
129 rm "$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
136 checkit "$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
141 rm "$chkdir"/foo/file1
142 rm "$chkdir"/bar/down/to/bar/baz/*.deep
143 cp -p "$fromdir"/bar/down/to/foo/*.junk "$chkdir"/bar/down/to/foo
144 cp -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
148 echo retained >"$todir"/bar/down/to/bar/baz/nodel.deep
149 cp -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
156 checkit "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
162 rm "$chkdir"/.filt
163 rm "$chkdir"/bar/.filt
164 rm "$chkdir"/bar/down/to/.filt2
165 rm "$chkdir"/bar/down/to/foo/.filt2
166 rm "$chkdir"/bar/down/to/bar/.filt2
167 rm "$chkdir"/mid/.filt
168
169 $RSYNC -av --protocol=28 --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/"
170
171 # Now, try the prior command with --delete-before and some side-specific
172 # rules.
173
174 checkit "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
180 cat >"$fromdir/bar/down/.excl" <<EOF
181 file3
182 EOF
183 cat >"$fromdir/bar/down/to/foo/.excl" <<EOF
184 + file3
185 *.bak
186 EOF
187 $RSYNC -av --del "$fromdir/" "$chkdir/"
188 rm "$chkdir/bar/down/to/foo/file1.bak"
189 rm "$chkdir/bar/down/to/foo/file3"
190 rm "$chkdir/bar/down/to/foo/+ file3"
191 $RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
192 $RSYNC -av --delete-excluded --exclude='*' "$fromdir/" "$todir/"
193
194 checkit "$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.
198 exit 0