Fixed a problem sending include rules to an older rsync.
[rsync/rsync.git] / testsuite / exclude.test
CommitLineData
ff570659
WD
1#! /bin/sh
2
b62fd393 3# Copyright (C) 2003, 2004, 2005 by Wayne Davison <wayned@samba.org>
ff570659
WD
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
7892e5ac 13. "$suitedir/rsync.fns"
ff570659 14
43a9d0e7
WD
15HOME="$scratchdir"
16CVSIGNORE='*.junk'
17export HOME CVSIGNORE
18
ff570659
WD
19# Build some files/dirs/links to copy
20
ff570659
WD
21makepath "$fromdir/foo/down/to/you"
22makepath "$fromdir/bar/down/to/foo/too"
408aa7b2 23makepath "$fromdir/bar/down/to/bar/baz"
ff570659 24makepath "$fromdir/mid/for/foo/and/that/is/who"
bb558f67 25cat >"$fromdir/.filt" <<EOF
e7966626 26exclude down
bb558f67 27: .filt-temp
e7966626 28clear
bb558f67 29- .filt
201a2fe5
WD
30- *.bak
31- *.old
201a2fe5 32EOF
ff570659
WD
33echo kept >"$fromdir/foo/file1"
34echo removed >"$fromdir/foo/file2"
43a9d0e7 35echo cvsout >"$fromdir/foo/file2.old"
bb558f67
WD
36cat >"$fromdir/foo/.filt" <<EOF
37include .filt
201a2fe5
WD
38- file1
39EOF
bb558f67 40cat >"$fromdir/bar/.filt" <<EOF
201a2fe5 41- home-cvs-exclude
bb558f67 42dir-merge .filt2
201a2fe5
WD
43+ to
44EOF
ead751c6 45echo cvsout >"$fromdir/bar/down/to/home-cvs-exclude"
bb558f67
WD
46cat >"$fromdir/bar/down/to/.filt2" <<EOF
47- .filt2
201a2fe5 48EOF
bb558f67 49cat >"$fromdir/bar/down/to/foo/.filt2" <<EOF
408aa7b2
WD
50+ *.junk
51EOF
ff570659 52echo keeper >"$fromdir/bar/down/to/foo/file1"
43a9d0e7 53echo cvsout >"$fromdir/bar/down/to/foo/file1.bak"
ff570659
WD
54echo gone >"$fromdir/bar/down/to/foo/file3"
55echo lost >"$fromdir/bar/down/to/foo/file4"
bb558f67 56echo weird >"$fromdir/bar/down/to/foo/+ file3"
408aa7b2 57echo cvsout-but-filtin >"$fromdir/bar/down/to/foo/file4.junk"
ff570659 58echo smashed >"$fromdir/bar/down/to/foo/to"
bb558f67 59cat >"$fromdir/bar/down/to/bar/.filt2" <<EOF
408aa7b2 60- *.deep
201a2fe5 61EOF
408aa7b2 62echo filtout >"$fromdir/bar/down/to/bar/baz/file5.deep"
201a2fe5 63# This one should be ineffectual
bb558f67 64cat >"$fromdir/mid/.filt2" <<EOF
201a2fe5
WD
65- extra
66EOF
43a9d0e7
WD
67echo cvsout >"$fromdir/mid/one-in-one-out"
68echo one-in-one-out >"$fromdir/mid/.cvsignore"
69echo cvsin >"$fromdir/mid/one-for-all"
bb558f67 70cat >"$fromdir/mid/.filt" <<EOF
201a2fe5
WD
71:C
72EOF
ead751c6 73echo cvsin >"$fromdir/mid/for/one-in-one-out"
ff570659
WD
74echo expunged >"$fromdir/mid/for/foo/extra"
75echo retained >"$fromdir/mid/for/foo/keep"
76ln -s too "$fromdir/bar/down/to/foo/sym"
77
f1dd0f27 78# Setup our test exclude/include files.
ff570659 79
ff570659
WD
80excl="$scratchdir/exclude-from"
81cat >"$excl" <<EOF
201a2fe5 82!
ff570659
WD
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
96EOF
97
f1dd0f27
WD
98cat >"$scratchdir/.cvsignore" <<EOF
99home-cvs-exclude
100EOF
101
ff570659 102# Create the chk dir with what we expect to be excluded
337a1a86 103
ff570659
WD
104checkit "$RSYNC -avv \"$fromdir/\" \"$chkdir/\"" "$fromdir" "$chkdir"
105
337a1a86 106sleep 1 # Ensures that the rm commands will tweak the directory times.
ff570659 107
ff570659 108rm -r "$chkdir"/foo/down
093acc5d 109rm -r "$chkdir"/mid/for/foo/and
ff570659 110rm "$chkdir"/foo/file[235-9]
093acc5d 111rm "$chkdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo/file[235-9]
ff570659
WD
112rm "$chkdir"/mid/for/foo/extra
113
337a1a86
WD
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/"
ff570659 117
337a1a86 118# Now, test if rsync excludes the same files.
ff570659 119
201a2fe5 120checkit "$RSYNC -avv --exclude-from=\"$excl\" \
408aa7b2 121 --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
ff570659 122
43a9d0e7
WD
123# Modify the chk dir by removing cvs-ignored files and then tweaking the dir times.
124
125rm "$chkdir"/foo/*.old
126rm "$chkdir"/bar/down/to/foo/*.bak
127rm "$chkdir"/bar/down/to/foo/*.junk
128rm "$chkdir"/bar/down/to/home-cvs-exclude
129rm "$chkdir"/mid/one-in-one-out
130
e7966626 131$RSYNC -av --existing --filter='exclude,! */' "$fromdir/" "$chkdir/"
43a9d0e7
WD
132
133# Now, test if rsync excludes the same files, this time with --cvs-exclude
134# and --delete-excluded.
135
e7966626 136checkit "$RSYNC -avvC --filter=\"merge $excl\" --delete-excluded \
408aa7b2 137 --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
201a2fe5
WD
138
139# Modify the chk dir for our merge-exclude test and then tweak the dir times.
140
201a2fe5 141rm "$chkdir"/foo/file1
408aa7b2 142rm "$chkdir"/bar/down/to/bar/baz/*.deep
201a2fe5
WD
143cp -p "$fromdir"/bar/down/to/foo/*.junk "$chkdir"/bar/down/to/foo
144cp -p "$fromdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo
145
bb558f67 146$RSYNC -av --existing -f 'show .filt*' -f 'hide,! */' --del "$fromdir/" "$todir/"
408aa7b2
WD
147
148echo retained >"$todir"/bar/down/to/bar/baz/nodel.deep
149cp -p "$todir"/bar/down/to/bar/baz/nodel.deep "$chkdir"/bar/down/to/bar/baz
150
346402dd 151$RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
201a2fe5
WD
152
153# Now, test if rsync excludes the same files, this time with a merge-exclude
154# file.
155
408aa7b2 156checkit "sed '/!/d' \"$excl\" |
bb558f67 157 $RSYNC -avv -f dir-merge_.filt -f merge_- \
408aa7b2
WD
158 --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
159
bb558f67 160# Remove the files that will be deleted.
408aa7b2 161
bb558f67
WD
162rm "$chkdir"/.filt
163rm "$chkdir"/bar/.filt
164rm "$chkdir"/bar/down/to/.filt2
165rm "$chkdir"/bar/down/to/foo/.filt2
166rm "$chkdir"/bar/down/to/bar/.filt2
167rm "$chkdir"/mid/.filt
408aa7b2 168
346402dd 169$RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
408aa7b2 170
bb558f67
WD
171# Now, try the prior command with --delete-before and some side-specific
172# rules.
408aa7b2
WD
173
174checkit "sed '/!/d' \"$excl\" |
bb558f67 175 $RSYNC -avv -f :s_.filt -f .s_- -f P_nodel.deep \
408aa7b2 176 --delete-before \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
43a9d0e7 177
bb558f67
WD
178# Next, we'll test some rule-restricted filter files.
179
180cat >"$fromdir/bar/down/.excl" <<EOF
181file3
182EOF
183cat >"$fromdir/bar/down/to/foo/.excl" <<EOF
184+ file3
185*.bak
186EOF
187$RSYNC -av --del "$fromdir/" "$chkdir/"
188rm "$chkdir/bar/down/to/foo/file1.bak"
189rm "$chkdir/bar/down/to/foo/file3"
190rm "$chkdir/bar/down/to/foo/+ file3"
9a338344 191$RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
bb558f67
WD
192$RSYNC -av --delete-excluded --exclude='*' "$fromdir/" "$todir/"
193
194checkit "$RSYNC -avv -f dir-merge,-_.excl \
195 \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
196
05118158 197# The script would have aborted on error, so getting here means we've won.
ff570659 198exit 0