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