Added a missing '(' in the opening comments.
[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 4
c8d19f90 5# This program is distributable under the terms of the GNU GPL (see
ff570659
WD
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 15CVSIGNORE='*.junk'
2b7dab68 16export CVSIGNORE
43a9d0e7 17
ff570659
WD
18# Build some files/dirs/links to copy
19
ff570659 20makepath "$fromdir/foo/down/to/you"
0314302e 21makepath "$fromdir/foo/sub"
ff570659 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"
90d5b12e
WD
25makepath "$fromdir/new/keep/this"
26makepath "$fromdir/new/lose/this"
bb558f67 27cat >"$fromdir/.filt" <<EOF
e7966626 28exclude down
bb558f67 29: .filt-temp
e7966626 30clear
bb558f67 31- .filt
201a2fe5
WD
32- *.bak
33- *.old
201a2fe5 34EOF
0314302e 35echo filtered-1 >"$fromdir/foo/file1"
ff570659 36echo removed >"$fromdir/foo/file2"
43a9d0e7 37echo cvsout >"$fromdir/foo/file2.old"
bb558f67
WD
38cat >"$fromdir/foo/.filt" <<EOF
39include .filt
0314302e 40- /file1
201a2fe5 41EOF
0314302e 42echo not-filtered-1 >"$fromdir/foo/sub/file1"
bb558f67 43cat >"$fromdir/bar/.filt" <<EOF
201a2fe5 44- home-cvs-exclude
bb558f67 45dir-merge .filt2
201a2fe5
WD
46+ to
47EOF
ead751c6 48echo cvsout >"$fromdir/bar/down/to/home-cvs-exclude"
bb558f67
WD
49cat >"$fromdir/bar/down/to/.filt2" <<EOF
50- .filt2
201a2fe5 51EOF
bb558f67 52cat >"$fromdir/bar/down/to/foo/.filt2" <<EOF
408aa7b2
WD
53+ *.junk
54EOF
ff570659 55echo keeper >"$fromdir/bar/down/to/foo/file1"
43a9d0e7 56echo cvsout >"$fromdir/bar/down/to/foo/file1.bak"
ff570659
WD
57echo gone >"$fromdir/bar/down/to/foo/file3"
58echo lost >"$fromdir/bar/down/to/foo/file4"
bb558f67 59echo weird >"$fromdir/bar/down/to/foo/+ file3"
408aa7b2 60echo cvsout-but-filtin >"$fromdir/bar/down/to/foo/file4.junk"
ff570659 61echo smashed >"$fromdir/bar/down/to/foo/to"
bb558f67 62cat >"$fromdir/bar/down/to/bar/.filt2" <<EOF
408aa7b2 63- *.deep
201a2fe5 64EOF
408aa7b2 65echo filtout >"$fromdir/bar/down/to/bar/baz/file5.deep"
201a2fe5 66# This one should be ineffectual
bb558f67 67cat >"$fromdir/mid/.filt2" <<EOF
201a2fe5
WD
68- extra
69EOF
43a9d0e7
WD
70echo cvsout >"$fromdir/mid/one-in-one-out"
71echo one-in-one-out >"$fromdir/mid/.cvsignore"
72echo cvsin >"$fromdir/mid/one-for-all"
bb558f67 73cat >"$fromdir/mid/.filt" <<EOF
201a2fe5
WD
74:C
75EOF
ead751c6 76echo cvsin >"$fromdir/mid/for/one-in-one-out"
ff570659
WD
77echo expunged >"$fromdir/mid/for/foo/extra"
78echo retained >"$fromdir/mid/for/foo/keep"
79ln -s too "$fromdir/bar/down/to/foo/sym"
80
f1dd0f27 81# Setup our test exclude/include files.
ff570659 82
ff570659
WD
83excl="$scratchdir/exclude-from"
84cat >"$excl" <<EOF
201a2fe5 85!
ff570659
WD
86# If the second line of these two lines does anything, it's a bug.
87+ **/bar
88- /bar
89# This should match against the whole path, not just the name.
90+ foo**too
0314302e
WD
91# These should float at the end of the path.
92+ foo/s?b/
ff570659 93- foo/*/
90d5b12e
WD
94# Test how /** differs from /***
95- new/keep/**
96- new/lose/***
ff570659
WD
97# Test some normal excludes. Competing lines are paired.
98+ t[o]/
99- to
100+ file4
101- file[2-9]
102- /mid/for/foo/extra
103EOF
104
f1dd0f27
WD
105cat >"$scratchdir/.cvsignore" <<EOF
106home-cvs-exclude
107EOF
108
ff570659 109# Create the chk dir with what we expect to be excluded
337a1a86 110
ff570659
WD
111checkit "$RSYNC -avv \"$fromdir/\" \"$chkdir/\"" "$fromdir" "$chkdir"
112
337a1a86 113sleep 1 # Ensures that the rm commands will tweak the directory times.
ff570659 114
ff570659 115rm -r "$chkdir"/foo/down
093acc5d 116rm -r "$chkdir"/mid/for/foo/and
90d5b12e
WD
117rm -r "$chkdir"/new/keep/this
118rm -r "$chkdir"/new/lose
ff570659 119rm "$chkdir"/foo/file[235-9]
093acc5d 120rm "$chkdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo/file[235-9]
ff570659
WD
121rm "$chkdir"/mid/for/foo/extra
122
337a1a86
WD
123# Un-tweak the directory times in our first (weak) exclude test (though
124# it's a good test of the --existing option).
125$RSYNC -av --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/"
ff570659 126
337a1a86 127# Now, test if rsync excludes the same files.
ff570659 128
201a2fe5 129checkit "$RSYNC -avv --exclude-from=\"$excl\" \
408aa7b2 130 --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
ff570659 131
43a9d0e7
WD
132# Modify the chk dir by removing cvs-ignored files and then tweaking the dir times.
133
134rm "$chkdir"/foo/*.old
135rm "$chkdir"/bar/down/to/foo/*.bak
136rm "$chkdir"/bar/down/to/foo/*.junk
137rm "$chkdir"/bar/down/to/home-cvs-exclude
138rm "$chkdir"/mid/one-in-one-out
139
e7966626 140$RSYNC -av --existing --filter='exclude,! */' "$fromdir/" "$chkdir/"
43a9d0e7
WD
141
142# Now, test if rsync excludes the same files, this time with --cvs-exclude
143# and --delete-excluded.
144
e7966626 145checkit "$RSYNC -avvC --filter=\"merge $excl\" --delete-excluded \
408aa7b2 146 --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
201a2fe5
WD
147
148# Modify the chk dir for our merge-exclude test and then tweak the dir times.
149
201a2fe5 150rm "$chkdir"/foo/file1
408aa7b2 151rm "$chkdir"/bar/down/to/bar/baz/*.deep
201a2fe5
WD
152cp -p "$fromdir"/bar/down/to/foo/*.junk "$chkdir"/bar/down/to/foo
153cp -p "$fromdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo
154
bb558f67 155$RSYNC -av --existing -f 'show .filt*' -f 'hide,! */' --del "$fromdir/" "$todir/"
408aa7b2
WD
156
157echo retained >"$todir"/bar/down/to/bar/baz/nodel.deep
158cp -p "$todir"/bar/down/to/bar/baz/nodel.deep "$chkdir"/bar/down/to/bar/baz
159
346402dd 160$RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
201a2fe5
WD
161
162# Now, test if rsync excludes the same files, this time with a merge-exclude
163# file.
164
408aa7b2 165checkit "sed '/!/d' \"$excl\" |
bb558f67 166 $RSYNC -avv -f dir-merge_.filt -f merge_- \
408aa7b2
WD
167 --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
168
bb558f67 169# Remove the files that will be deleted.
408aa7b2 170
bb558f67
WD
171rm "$chkdir"/.filt
172rm "$chkdir"/bar/.filt
173rm "$chkdir"/bar/down/to/.filt2
174rm "$chkdir"/bar/down/to/foo/.filt2
175rm "$chkdir"/bar/down/to/bar/.filt2
176rm "$chkdir"/mid/.filt
408aa7b2 177
a3e1363a 178$RSYNC -av --protocol=28 --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/"
408aa7b2 179
bb558f67
WD
180# Now, try the prior command with --delete-before and some side-specific
181# rules.
408aa7b2
WD
182
183checkit "sed '/!/d' \"$excl\" |
bb558f67 184 $RSYNC -avv -f :s_.filt -f .s_- -f P_nodel.deep \
408aa7b2 185 --delete-before \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
43a9d0e7 186
bb558f67
WD
187# Next, we'll test some rule-restricted filter files.
188
189cat >"$fromdir/bar/down/.excl" <<EOF
190file3
191EOF
192cat >"$fromdir/bar/down/to/foo/.excl" <<EOF
193+ file3
194*.bak
195EOF
196$RSYNC -av --del "$fromdir/" "$chkdir/"
197rm "$chkdir/bar/down/to/foo/file1.bak"
198rm "$chkdir/bar/down/to/foo/file3"
199rm "$chkdir/bar/down/to/foo/+ file3"
9a338344 200$RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
bb558f67
WD
201$RSYNC -av --delete-excluded --exclude='*' "$fromdir/" "$todir/"
202
203checkit "$RSYNC -avv -f dir-merge,-_.excl \
204 \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
205
05118158 206# The script would have aborted on error, so getting here means we've won.
ff570659 207exit 0