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