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