Improved checkit() and rsync_ls_lR() to work with filenames that
[rsync/rsync.git] / testsuite / exclude.test
... / ...
CommitLineData
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
13. "$suitedir/rsync.fns"
14
15set -x
16
17HOME="$scratchdir"
18CVSIGNORE='*.junk'
19export HOME CVSIGNORE
20
21# Build some files/dirs/links to copy
22
23makepath "$fromdir/foo/down/to/you"
24makepath "$fromdir/bar/down/to/foo/too"
25makepath "$fromdir/bar/down/to/bar/baz"
26makepath "$fromdir/mid/for/foo/and/that/is/who"
27cat >"$fromdir/.excl" <<EOF
28exclude down
29: .excl-temp
30clear
31- .excl
32- *.bak
33- *.old
34EOF
35echo kept >"$fromdir/foo/file1"
36echo removed >"$fromdir/foo/file2"
37echo cvsout >"$fromdir/foo/file2.old"
38cat >"$fromdir/foo/.excl" <<EOF
39include .excl
40- file1
41EOF
42cat >"$fromdir/bar/.excl" <<EOF
43- home-cvs-exclude
44dir-merge .excl2
45+ to
46EOF
47echo cvsout >"$fromdir/bar/down/to/home-cvs-exclude"
48cat >"$fromdir/bar/down/to/.excl2" <<EOF
49- .excl2
50EOF
51cat >"$fromdir/bar/down/to/foo/.excl2" <<EOF
52+ *.junk
53EOF
54echo keeper >"$fromdir/bar/down/to/foo/file1"
55echo cvsout >"$fromdir/bar/down/to/foo/file1.bak"
56echo gone >"$fromdir/bar/down/to/foo/file3"
57echo lost >"$fromdir/bar/down/to/foo/file4"
58echo cvsout-but-filtin >"$fromdir/bar/down/to/foo/file4.junk"
59echo smashed >"$fromdir/bar/down/to/foo/to"
60cat >"$fromdir/bar/down/to/bar/.excl2" <<EOF
61- *.deep
62EOF
63echo filtout >"$fromdir/bar/down/to/bar/baz/file5.deep"
64# This one should be ineffectual
65cat >"$fromdir/mid/.excl2" <<EOF
66- extra
67EOF
68echo cvsout >"$fromdir/mid/one-in-one-out"
69echo one-in-one-out >"$fromdir/mid/.cvsignore"
70echo cvsin >"$fromdir/mid/one-for-all"
71cat >"$fromdir/mid/.excl" <<EOF
72:C
73EOF
74echo cvsin >"$fromdir/mid/for/one-in-one-out"
75echo expunged >"$fromdir/mid/for/foo/extra"
76echo retained >"$fromdir/mid/for/foo/keep"
77ln -s too "$fromdir/bar/down/to/foo/sym"
78
79# Setup our test exclude/include files.
80
81excl="$scratchdir/exclude-from"
82cat >"$excl" <<EOF
83!
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
99cat >"$scratchdir/.cvsignore" <<EOF
100home-cvs-exclude
101EOF
102
103# Create the chk dir with what we expect to be excluded
104
105checkit "$RSYNC -avv \"$fromdir/\" \"$chkdir/\"" "$fromdir" "$chkdir"
106
107sleep 1 # Ensures that the rm commands will tweak the directory times.
108
109rm -r "$chkdir"/foo/down
110rm -r "$chkdir"/mid/for/foo/and
111rm "$chkdir"/foo/file[235-9]
112rm "$chkdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo/file[235-9]
113rm "$chkdir"/mid/for/foo/extra
114
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/"
118
119# Now, test if rsync excludes the same files.
120
121checkit "$RSYNC -avv --exclude-from=\"$excl\" \
122 --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
123
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
132$RSYNC -av --existing --filter='exclude,! */' "$fromdir/" "$chkdir/"
133
134# Now, test if rsync excludes the same files, this time with --cvs-exclude
135# and --delete-excluded.
136
137checkit "$RSYNC -avvC --filter=\"merge $excl\" --delete-excluded \
138 --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
139
140# Modify the chk dir for our merge-exclude test and then tweak the dir times.
141
142rm "$chkdir"/foo/file1
143rm "$chkdir"/bar/down/to/bar/baz/*.deep
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 --delete-excluded \
148 --include='.excl*' --filter='-! */' "$fromdir/" "$todir/"
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
153$RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
154
155# Now, test if rsync excludes the same files, this time with a merge-exclude
156# file.
157
158checkit "sed '/!/d' \"$excl\" |
159 $RSYNC -avv -f dir-merge_.excl -f merge_- \
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
172$RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
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"
179
180# The script would have aborted on error, so getting here means we've won.
181exit 0