The setting of HOME got moved to rsync.fns.
[rsync/rsync.git] / testsuite / exclude.test
... / ...
CommitLineData
1#! /bin/sh
2
3# Copyright (C) 2003, 2004, 2005 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
15CVSIGNORE='*.junk'
16export CVSIGNORE
17
18set -x
19
20# Build some files/dirs/links to copy
21
22makepath "$fromdir/foo/down/to/you"
23makepath "$fromdir/foo/sub"
24makepath "$fromdir/bar/down/to/foo/too"
25makepath "$fromdir/bar/down/to/bar/baz"
26makepath "$fromdir/mid/for/foo/and/that/is/who"
27makepath "$fromdir/new/keep/this"
28makepath "$fromdir/new/lose/this"
29cat >"$fromdir/.filt" <<EOF
30exclude down
31: .filt-temp
32clear
33- .filt
34- *.bak
35- *.old
36EOF
37echo filtered-1 >"$fromdir/foo/file1"
38echo removed >"$fromdir/foo/file2"
39echo cvsout >"$fromdir/foo/file2.old"
40cat >"$fromdir/foo/.filt" <<EOF
41include .filt
42- /file1
43EOF
44echo not-filtered-1 >"$fromdir/foo/sub/file1"
45cat >"$fromdir/bar/.filt" <<EOF
46- home-cvs-exclude
47dir-merge .filt2
48+ to
49EOF
50echo cvsout >"$fromdir/bar/down/to/home-cvs-exclude"
51cat >"$fromdir/bar/down/to/.filt2" <<EOF
52- .filt2
53EOF
54cat >"$fromdir/bar/down/to/foo/.filt2" <<EOF
55+ *.junk
56EOF
57echo keeper >"$fromdir/bar/down/to/foo/file1"
58echo cvsout >"$fromdir/bar/down/to/foo/file1.bak"
59echo gone >"$fromdir/bar/down/to/foo/file3"
60echo lost >"$fromdir/bar/down/to/foo/file4"
61echo weird >"$fromdir/bar/down/to/foo/+ file3"
62echo cvsout-but-filtin >"$fromdir/bar/down/to/foo/file4.junk"
63echo smashed >"$fromdir/bar/down/to/foo/to"
64cat >"$fromdir/bar/down/to/bar/.filt2" <<EOF
65- *.deep
66EOF
67echo filtout >"$fromdir/bar/down/to/bar/baz/file5.deep"
68# This one should be ineffectual
69cat >"$fromdir/mid/.filt2" <<EOF
70- extra
71EOF
72echo cvsout >"$fromdir/mid/one-in-one-out"
73echo one-in-one-out >"$fromdir/mid/.cvsignore"
74echo cvsin >"$fromdir/mid/one-for-all"
75cat >"$fromdir/mid/.filt" <<EOF
76:C
77EOF
78echo cvsin >"$fromdir/mid/for/one-in-one-out"
79echo expunged >"$fromdir/mid/for/foo/extra"
80echo retained >"$fromdir/mid/for/foo/keep"
81ln -s too "$fromdir/bar/down/to/foo/sym"
82
83# Setup our test exclude/include files.
84
85excl="$scratchdir/exclude-from"
86cat >"$excl" <<EOF
87!
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
93# These should float at the end of the path.
94+ foo/s?b/
95- foo/*/
96# Test how /** differs from /***
97- new/keep/**
98- new/lose/***
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
107cat >"$scratchdir/.cvsignore" <<EOF
108home-cvs-exclude
109EOF
110
111# Create the chk dir with what we expect to be excluded
112
113checkit "$RSYNC -avv \"$fromdir/\" \"$chkdir/\"" "$fromdir" "$chkdir"
114
115sleep 1 # Ensures that the rm commands will tweak the directory times.
116
117rm -r "$chkdir"/foo/down
118rm -r "$chkdir"/mid/for/foo/and
119rm -r "$chkdir"/new/keep/this
120rm -r "$chkdir"/new/lose
121rm "$chkdir"/foo/file[235-9]
122rm "$chkdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo/file[235-9]
123rm "$chkdir"/mid/for/foo/extra
124
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/"
128
129# Now, test if rsync excludes the same files.
130
131checkit "$RSYNC -avv --exclude-from=\"$excl\" \
132 --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
133
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
142$RSYNC -av --existing --filter='exclude,! */' "$fromdir/" "$chkdir/"
143
144# Now, test if rsync excludes the same files, this time with --cvs-exclude
145# and --delete-excluded.
146
147checkit "$RSYNC -avvC --filter=\"merge $excl\" --delete-excluded \
148 --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
149
150# Modify the chk dir for our merge-exclude test and then tweak the dir times.
151
152rm "$chkdir"/foo/file1
153rm "$chkdir"/bar/down/to/bar/baz/*.deep
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
157$RSYNC -av --existing -f 'show .filt*' -f 'hide,! */' --del "$fromdir/" "$todir/"
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
162$RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
163
164# Now, test if rsync excludes the same files, this time with a merge-exclude
165# file.
166
167checkit "sed '/!/d' \"$excl\" |
168 $RSYNC -avv -f dir-merge_.filt -f merge_- \
169 --delete-during \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
170
171# Remove the files that will be deleted.
172
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
179
180$RSYNC -av --protocol=28 --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/"
181
182# Now, try the prior command with --delete-before and some side-specific
183# rules.
184
185checkit "sed '/!/d' \"$excl\" |
186 $RSYNC -avv -f :s_.filt -f .s_- -f P_nodel.deep \
187 --delete-before \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
188
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"
202$RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
203$RSYNC -av --delete-excluded --exclude='*' "$fromdir/" "$todir/"
204
205checkit "$RSYNC -avv -f dir-merge,-_.excl \
206 \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
207
208# The script would have aborted on error, so getting here means we've won.
209exit 0