We now test all the patterns using both a normal wildtest run and
[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
19set -x
20
21# Build some files/dirs/links to copy
22
23makepath "$fromdir/foo/down/to/you"
24makepath "$fromdir/foo/sub"
25makepath "$fromdir/bar/down/to/foo/too"
26makepath "$fromdir/bar/down/to/bar/baz"
27makepath "$fromdir/mid/for/foo/and/that/is/who"
28cat >"$fromdir/.filt" <<EOF
29exclude down
30: .filt-temp
31clear
32- .filt
33- *.bak
34- *.old
35EOF
36echo filtered-1 >"$fromdir/foo/file1"
37echo removed >"$fromdir/foo/file2"
38echo cvsout >"$fromdir/foo/file2.old"
39cat >"$fromdir/foo/.filt" <<EOF
40include .filt
41- /file1
42EOF
43echo not-filtered-1 >"$fromdir/foo/sub/file1"
44cat >"$fromdir/bar/.filt" <<EOF
45- home-cvs-exclude
46dir-merge .filt2
47+ to
48EOF
49echo cvsout >"$fromdir/bar/down/to/home-cvs-exclude"
50cat >"$fromdir/bar/down/to/.filt2" <<EOF
51- .filt2
52EOF
53cat >"$fromdir/bar/down/to/foo/.filt2" <<EOF
54+ *.junk
55EOF
56echo keeper >"$fromdir/bar/down/to/foo/file1"
57echo cvsout >"$fromdir/bar/down/to/foo/file1.bak"
58echo gone >"$fromdir/bar/down/to/foo/file3"
59echo lost >"$fromdir/bar/down/to/foo/file4"
60echo weird >"$fromdir/bar/down/to/foo/+ file3"
61echo cvsout-but-filtin >"$fromdir/bar/down/to/foo/file4.junk"
62echo smashed >"$fromdir/bar/down/to/foo/to"
63cat >"$fromdir/bar/down/to/bar/.filt2" <<EOF
64- *.deep
65EOF
66echo filtout >"$fromdir/bar/down/to/bar/baz/file5.deep"
67# This one should be ineffectual
68cat >"$fromdir/mid/.filt2" <<EOF
69- extra
70EOF
71echo cvsout >"$fromdir/mid/one-in-one-out"
72echo one-in-one-out >"$fromdir/mid/.cvsignore"
73echo cvsin >"$fromdir/mid/one-for-all"
74cat >"$fromdir/mid/.filt" <<EOF
75:C
76EOF
77echo cvsin >"$fromdir/mid/for/one-in-one-out"
78echo expunged >"$fromdir/mid/for/foo/extra"
79echo retained >"$fromdir/mid/for/foo/keep"
80ln -s too "$fromdir/bar/down/to/foo/sym"
81
82# Setup our test exclude/include files.
83
84excl="$scratchdir/exclude-from"
85cat >"$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
101EOF
102
103cat >"$scratchdir/.cvsignore" <<EOF
104home-cvs-exclude
105EOF
106
107# Create the chk dir with what we expect to be excluded
108
109checkit "$RSYNC -avv \"$fromdir/\" \"$chkdir/\"" "$fromdir" "$chkdir"
110
111sleep 1 # Ensures that the rm commands will tweak the directory times.
112
113rm -r "$chkdir"/foo/down
114rm -r "$chkdir"/mid/for/foo/and
115rm "$chkdir"/foo/file[235-9]
116rm "$chkdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo/file[235-9]
117rm "$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
125checkit "$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
130rm "$chkdir"/foo/*.old
131rm "$chkdir"/bar/down/to/foo/*.bak
132rm "$chkdir"/bar/down/to/foo/*.junk
133rm "$chkdir"/bar/down/to/home-cvs-exclude
134rm "$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
141checkit "$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
146rm "$chkdir"/foo/file1
147rm "$chkdir"/bar/down/to/bar/baz/*.deep
148cp -p "$fromdir"/bar/down/to/foo/*.junk "$chkdir"/bar/down/to/foo
149cp -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
153echo retained >"$todir"/bar/down/to/bar/baz/nodel.deep
154cp -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
161checkit "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
167rm "$chkdir"/.filt
168rm "$chkdir"/bar/.filt
169rm "$chkdir"/bar/down/to/.filt2
170rm "$chkdir"/bar/down/to/foo/.filt2
171rm "$chkdir"/bar/down/to/bar/.filt2
172rm "$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
179checkit "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
185cat >"$fromdir/bar/down/.excl" <<EOF
186file3
187EOF
188cat >"$fromdir/bar/down/to/foo/.excl" <<EOF
189+ file3
190*.bak
191EOF
192$RSYNC -av --del "$fromdir/" "$chkdir/"
193rm "$chkdir/bar/down/to/foo/file1.bak"
194rm "$chkdir/bar/down/to/foo/file3"
195rm "$chkdir/bar/down/to/foo/+ file3"
196$RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
197$RSYNC -av --delete-excluded --exclude='*' "$fromdir/" "$todir/"
198
199checkit "$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.
203exit 0