Improved the depth calculation in sanitize_path() so that it properly
[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
23echo home-cvs-exclude >"$scratchdir"/.cvsignore
24makepath "$fromdir/foo/down/to/you"
25makepath "$fromdir/bar/down/to/foo/too"
26makepath "$fromdir/mid/for/foo/and/that/is/who"
27echo kept >"$fromdir/foo/file1"
28echo removed >"$fromdir/foo/file2"
29echo cvsout >"$fromdir/foo/file2.old"
30echo cvsout >"$fromdir/bar/down/to/home-cvs-exclude"
31echo keeper >"$fromdir/bar/down/to/foo/file1"
32echo cvsout >"$fromdir/bar/down/to/foo/file1.bak"
33echo gone >"$fromdir/bar/down/to/foo/file3"
34echo lost >"$fromdir/bar/down/to/foo/file4"
35echo cvsout >"$fromdir/bar/down/to/foo/file4.junk"
36echo smashed >"$fromdir/bar/down/to/foo/to"
37echo cvsout >"$fromdir/mid/one-in-one-out"
38echo one-in-one-out >"$fromdir/mid/.cvsignore"
39echo cvsin >"$fromdir/mid/one-for-all"
40echo cvsin >"$fromdir/mid/for/one-in-one-out"
41echo expunged >"$fromdir/mid/for/foo/extra"
42echo retained >"$fromdir/mid/for/foo/keep"
43ln -s too "$fromdir/bar/down/to/foo/sym"
44
45# Setup our test exclude/include file.
46
47excl="$scratchdir/exclude-from"
48cat >"$excl" <<EOF
49# If the second line of these two lines does anything, it's a bug.
50+ **/bar
51- /bar
52# This should match against the whole path, not just the name.
53+ foo**too
54# This should float at the end of the path.
55- foo/*/
56# Test some normal excludes. Competing lines are paired.
57+ t[o]/
58- to
59+ file4
60- file[2-9]
61- /mid/for/foo/extra
62EOF
63
64# Create the chk dir with what we expect to be excluded
65
66checkit "$RSYNC -avv \"$fromdir/\" \"$chkdir/\"" "$fromdir" "$chkdir"
67
68sleep 1 # Ensures that the rm commands will tweak the directory times.
69
70rm -r "$chkdir"/foo/down
71rm -r "$chkdir"/mid/for/foo/and
72rm "$chkdir"/foo/file[235-9]
73rm "$chkdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo/file[235-9]
74rm "$chkdir"/mid/for/foo/extra
75
76# Un-tweak the directory times in our first (weak) exclude test (though
77# it's a good test of the --existing option).
78$RSYNC -av --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/"
79
80# Now, test if rsync excludes the same files.
81
82checkit "$RSYNC -avv --exclude-from=$excl \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
83
84# Modify the chk dir by removing cvs-ignored files and then tweaking the dir times.
85
86rm "$chkdir"/foo/*.old
87rm "$chkdir"/bar/down/to/foo/*.bak
88rm "$chkdir"/bar/down/to/foo/*.junk
89rm "$chkdir"/bar/down/to/home-cvs-exclude
90rm "$chkdir"/mid/one-in-one-out
91
92$RSYNC -av --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/"
93
94# Now, test if rsync excludes the same files, this time with --cvs-exclude
95# and --delete-excluded.
96
97checkit "$RSYNC -avvC --delete-excluded --exclude-from=$excl \
98 \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
99
100# The script would have aborted on error, so getting here means we've won.
101exit 0