Added an anchored exclude to a filter file.
[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
13725744
WD
19set -x
20
ff570659
WD
21# Build some files/dirs/links to copy
22
ff570659 23makepath "$fromdir/foo/down/to/you"
0314302e 24makepath "$fromdir/foo/sub"
ff570659 25makepath "$fromdir/bar/down/to/foo/too"
408aa7b2 26makepath "$fromdir/bar/down/to/bar/baz"
ff570659 27makepath "$fromdir/mid/for/foo/and/that/is/who"
bb558f67 28cat >"$fromdir/.filt" <<EOF
e7966626 29exclude down
bb558f67 30: .filt-temp
e7966626 31clear
bb558f67 32- .filt
201a2fe5
WD
33- *.bak
34- *.old
201a2fe5 35EOF
0314302e 36echo filtered-1 >"$fromdir/foo/file1"
ff570659 37echo removed >"$fromdir/foo/file2"
43a9d0e7 38echo cvsout >"$fromdir/foo/file2.old"
bb558f67
WD
39cat >"$fromdir/foo/.filt" <<EOF
40include .filt
0314302e 41- /file1
201a2fe5 42EOF
0314302e 43echo not-filtered-1 >"$fromdir/foo/sub/file1"
bb558f67 44cat >"$fromdir/bar/.filt" <<EOF
201a2fe5 45- home-cvs-exclude
bb558f67 46dir-merge .filt2
201a2fe5
WD
47+ to
48EOF
ead751c6 49echo cvsout >"$fromdir/bar/down/to/home-cvs-exclude"
bb558f67
WD
50cat >"$fromdir/bar/down/to/.filt2" <<EOF
51- .filt2
201a2fe5 52EOF
bb558f67 53cat >"$fromdir/bar/down/to/foo/.filt2" <<EOF
408aa7b2
WD
54+ *.junk
55EOF
ff570659 56echo keeper >"$fromdir/bar/down/to/foo/file1"
43a9d0e7 57echo cvsout >"$fromdir/bar/down/to/foo/file1.bak"
ff570659
WD
58echo gone >"$fromdir/bar/down/to/foo/file3"
59echo lost >"$fromdir/bar/down/to/foo/file4"
bb558f67 60echo weird >"$fromdir/bar/down/to/foo/+ file3"
408aa7b2 61echo cvsout-but-filtin >"$fromdir/bar/down/to/foo/file4.junk"
ff570659 62echo smashed >"$fromdir/bar/down/to/foo/to"
bb558f67 63cat >"$fromdir/bar/down/to/bar/.filt2" <<EOF
408aa7b2 64- *.deep
201a2fe5 65EOF
408aa7b2 66echo filtout >"$fromdir/bar/down/to/bar/baz/file5.deep"
201a2fe5 67# This one should be ineffectual
bb558f67 68cat >"$fromdir/mid/.filt2" <<EOF
201a2fe5
WD
69- extra
70EOF
43a9d0e7
WD
71echo cvsout >"$fromdir/mid/one-in-one-out"
72echo one-in-one-out >"$fromdir/mid/.cvsignore"
73echo cvsin >"$fromdir/mid/one-for-all"
bb558f67 74cat >"$fromdir/mid/.filt" <<EOF
201a2fe5
WD
75:C
76EOF
ead751c6 77echo cvsin >"$fromdir/mid/for/one-in-one-out"
ff570659
WD
78echo expunged >"$fromdir/mid/for/foo/extra"
79echo retained >"$fromdir/mid/for/foo/keep"
80ln -s too "$fromdir/bar/down/to/foo/sym"
81
f1dd0f27 82# Setup our test exclude/include files.
ff570659 83
ff570659
WD
84excl="$scratchdir/exclude-from"
85cat >"$excl" <<EOF
201a2fe5 86!
ff570659
WD
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
0314302e
WD
92# These should float at the end of the path.
93+ foo/s?b/
ff570659
WD
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
f1dd0f27
WD
103cat >"$scratchdir/.cvsignore" <<EOF
104home-cvs-exclude
105EOF
106
ff570659 107# Create the chk dir with what we expect to be excluded
337a1a86 108
ff570659
WD
109checkit "$RSYNC -avv \"$fromdir/\" \"$chkdir/\"" "$fromdir" "$chkdir"
110
337a1a86 111sleep 1 # Ensures that the rm commands will tweak the directory times.
ff570659 112
ff570659 113rm -r "$chkdir"/foo/down
093acc5d 114rm -r "$chkdir"/mid/for/foo/and
ff570659 115rm "$chkdir"/foo/file[235-9]
093acc5d 116rm "$chkdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo/file[235-9]
ff570659
WD
117rm "$chkdir"/mid/for/foo/extra
118
337a1a86
WD
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/"
ff570659 122
337a1a86 123# Now, test if rsync excludes the same files.
ff570659 124
201a2fe5 125checkit "$RSYNC -avv --exclude-from=\"$excl\" \
408aa7b2 126 --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
ff570659 127
43a9d0e7
WD
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
e7966626 136$RSYNC -av --existing --filter='exclude,! */' "$fromdir/" "$chkdir/"
43a9d0e7
WD
137
138# Now, test if rsync excludes the same files, this time with --cvs-exclude
139# and --delete-excluded.
140
e7966626 141checkit "$RSYNC -avvC --filter=\"merge $excl\" --delete-excluded \
408aa7b2 142 --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
201a2fe5
WD
143
144# Modify the chk dir for our merge-exclude test and then tweak the dir times.
145
201a2fe5 146rm "$chkdir"/foo/file1
408aa7b2 147rm "$chkdir"/bar/down/to/bar/baz/*.deep
201a2fe5
WD
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
bb558f67 151$RSYNC -av --existing -f 'show .filt*' -f 'hide,! */' --del "$fromdir/" "$todir/"
408aa7b2
WD
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
346402dd 156$RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
201a2fe5
WD
157
158# Now, test if rsync excludes the same files, this time with a merge-exclude
159# file.
160
408aa7b2 161checkit "sed '/!/d' \"$excl\" |
bb558f67 162 $RSYNC -avv -f dir-merge_.filt -f merge_- \
408aa7b2
WD
163 --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
164
bb558f67 165# Remove the files that will be deleted.
408aa7b2 166
bb558f67
WD
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
408aa7b2 173
a3e1363a 174$RSYNC -av --protocol=28 --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/"
408aa7b2 175
bb558f67
WD
176# Now, try the prior command with --delete-before and some side-specific
177# rules.
408aa7b2
WD
178
179checkit "sed '/!/d' \"$excl\" |
bb558f67 180 $RSYNC -avv -f :s_.filt -f .s_- -f P_nodel.deep \
408aa7b2 181 --delete-before \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
43a9d0e7 182
bb558f67
WD
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"
9a338344 196$RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
bb558f67
WD
197$RSYNC -av --delete-excluded --exclude='*' "$fromdir/" "$todir/"
198
199checkit "$RSYNC -avv -f dir-merge,-_.excl \
200 \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
201
05118158 202# The script would have aborted on error, so getting here means we've won.
ff570659 203exit 0