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