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