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