Improved checkit() and rsync_ls_lR() to work with filenames that
[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"
408aa7b2 25makepath "$fromdir/bar/down/to/bar/baz"
ff570659 26makepath "$fromdir/mid/for/foo/and/that/is/who"
201a2fe5 27cat >"$fromdir/.excl" <<EOF
e7966626 28exclude down
201a2fe5 29: .excl-temp
e7966626 30clear
201a2fe5
WD
31- .excl
32- *.bak
33- *.old
201a2fe5 34EOF
ff570659
WD
35echo kept >"$fromdir/foo/file1"
36echo removed >"$fromdir/foo/file2"
43a9d0e7 37echo cvsout >"$fromdir/foo/file2.old"
201a2fe5 38cat >"$fromdir/foo/.excl" <<EOF
e7966626 39include .excl
201a2fe5
WD
40- file1
41EOF
42cat >"$fromdir/bar/.excl" <<EOF
43- home-cvs-exclude
e7966626 44dir-merge .excl2
201a2fe5
WD
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
408aa7b2
WD
51cat >"$fromdir/bar/down/to/foo/.excl2" <<EOF
52+ *.junk
53EOF
ff570659 54echo keeper >"$fromdir/bar/down/to/foo/file1"
43a9d0e7 55echo cvsout >"$fromdir/bar/down/to/foo/file1.bak"
ff570659
WD
56echo gone >"$fromdir/bar/down/to/foo/file3"
57echo lost >"$fromdir/bar/down/to/foo/file4"
408aa7b2 58echo cvsout-but-filtin >"$fromdir/bar/down/to/foo/file4.junk"
ff570659 59echo smashed >"$fromdir/bar/down/to/foo/to"
408aa7b2
WD
60cat >"$fromdir/bar/down/to/bar/.excl2" <<EOF
61- *.deep
201a2fe5 62EOF
408aa7b2 63echo filtout >"$fromdir/bar/down/to/bar/baz/file5.deep"
201a2fe5
WD
64# This one should be ineffectual
65cat >"$fromdir/mid/.excl2" <<EOF
66- extra
67EOF
43a9d0e7
WD
68echo cvsout >"$fromdir/mid/one-in-one-out"
69echo one-in-one-out >"$fromdir/mid/.cvsignore"
70echo cvsin >"$fromdir/mid/one-for-all"
201a2fe5
WD
71cat >"$fromdir/mid/.excl" <<EOF
72:C
73EOF
ead751c6 74echo cvsin >"$fromdir/mid/for/one-in-one-out"
ff570659
WD
75echo expunged >"$fromdir/mid/for/foo/extra"
76echo retained >"$fromdir/mid/for/foo/keep"
77ln -s too "$fromdir/bar/down/to/foo/sym"
78
f1dd0f27 79# Setup our test exclude/include files.
ff570659 80
ff570659
WD
81excl="$scratchdir/exclude-from"
82cat >"$excl" <<EOF
201a2fe5 83!
ff570659
WD
84# If the second line of these two lines does anything, it's a bug.
85+ **/bar
86- /bar
87# This should match against the whole path, not just the name.
88+ foo**too
89# This should float at the end of the path.
90- foo/*/
91# Test some normal excludes. Competing lines are paired.
92+ t[o]/
93- to
94+ file4
95- file[2-9]
96- /mid/for/foo/extra
97EOF
98
f1dd0f27
WD
99cat >"$scratchdir/.cvsignore" <<EOF
100home-cvs-exclude
101EOF
102
ff570659 103# Create the chk dir with what we expect to be excluded
337a1a86 104
ff570659
WD
105checkit "$RSYNC -avv \"$fromdir/\" \"$chkdir/\"" "$fromdir" "$chkdir"
106
337a1a86 107sleep 1 # Ensures that the rm commands will tweak the directory times.
ff570659 108
ff570659 109rm -r "$chkdir"/foo/down
093acc5d 110rm -r "$chkdir"/mid/for/foo/and
ff570659 111rm "$chkdir"/foo/file[235-9]
093acc5d 112rm "$chkdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo/file[235-9]
ff570659
WD
113rm "$chkdir"/mid/for/foo/extra
114
337a1a86
WD
115# Un-tweak the directory times in our first (weak) exclude test (though
116# it's a good test of the --existing option).
117$RSYNC -av --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/"
ff570659 118
337a1a86 119# Now, test if rsync excludes the same files.
ff570659 120
201a2fe5 121checkit "$RSYNC -avv --exclude-from=\"$excl\" \
408aa7b2 122 --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
ff570659 123
43a9d0e7
WD
124# Modify the chk dir by removing cvs-ignored files and then tweaking the dir times.
125
126rm "$chkdir"/foo/*.old
127rm "$chkdir"/bar/down/to/foo/*.bak
128rm "$chkdir"/bar/down/to/foo/*.junk
129rm "$chkdir"/bar/down/to/home-cvs-exclude
130rm "$chkdir"/mid/one-in-one-out
131
e7966626 132$RSYNC -av --existing --filter='exclude,! */' "$fromdir/" "$chkdir/"
43a9d0e7
WD
133
134# Now, test if rsync excludes the same files, this time with --cvs-exclude
135# and --delete-excluded.
136
e7966626 137checkit "$RSYNC -avvC --filter=\"merge $excl\" --delete-excluded \
408aa7b2 138 --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
201a2fe5
WD
139
140# Modify the chk dir for our merge-exclude test and then tweak the dir times.
141
201a2fe5 142rm "$chkdir"/foo/file1
408aa7b2 143rm "$chkdir"/bar/down/to/bar/baz/*.deep
201a2fe5
WD
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
408aa7b2 147$RSYNC -av --existing --delete-excluded \
346402dd 148 --include='.excl*' --filter='-! */' "$fromdir/" "$todir/"
408aa7b2
WD
149
150echo retained >"$todir"/bar/down/to/bar/baz/nodel.deep
151cp -p "$todir"/bar/down/to/bar/baz/nodel.deep "$chkdir"/bar/down/to/bar/baz
152
346402dd 153$RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
201a2fe5
WD
154
155# Now, test if rsync excludes the same files, this time with a merge-exclude
156# file.
157
408aa7b2 158checkit "sed '/!/d' \"$excl\" |
e7966626 159 $RSYNC -avv -f dir-merge_.excl -f merge_- \
408aa7b2
WD
160 --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
161
162# Remove the files that --delete-excluded will delete.
163
164rm "$chkdir"/.excl
165rm "$chkdir"/bar/.excl
166rm "$chkdir"/bar/down/to/.excl2
167rm "$chkdir"/bar/down/to/foo/.excl2
168rm "$chkdir"/bar/down/to/bar/.excl2
169rm "$chkdir"/mid/.excl
170rm "$chkdir"/bar/down/to/bar/baz/nodel.deep
171
346402dd 172$RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
408aa7b2
WD
173
174# Finally, try the prior command with --delete-before and --delete-excluded.
175
176checkit "sed '/!/d' \"$excl\" |
177 $RSYNC -avv -f :_.excl -f ._- --delete-excluded \
178 --delete-before \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
43a9d0e7 179
05118158 180# The script would have aborted on error, so getting here means we've won.
ff570659 181exit 0