Improved the exclude testing by adding tests that exercise --cvs-exclude
[rsync/rsync.git] / testsuite / exclude.test
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
15 set -x
16
17 HOME="$scratchdir"
18 CVSIGNORE='*.junk'
19 export HOME CVSIGNORE
20
21 # Build some files/dirs/links to copy
22
23 fromdir="$scratchdir/from"
24 todir="$scratchdir/to"
25 chkdir="$scratchdir/chk"
26
27 echo home-cvs-exclude >"$scratchdir"/.cvsignore
28 makepath "$fromdir/foo/down/to/you"
29 makepath "$fromdir/bar/down/to/foo/too"
30 makepath "$fromdir/mid/for/foo/and/that/is/who"
31 echo kept >"$fromdir/foo/file1"
32 echo removed >"$fromdir/foo/file2"
33 echo cvsout >"$fromdir/foo/file2.old"
34 echo keeper >"$fromdir/bar/down/to/foo/file1"
35 echo cvsout >"$fromdir/bar/down/to/foo/file1.bak"
36 echo gone >"$fromdir/bar/down/to/foo/file3"
37 echo lost >"$fromdir/bar/down/to/foo/file4"
38 echo cvsout >"$fromdir/bar/down/to/foo/file4.junk"
39 echo smashed >"$fromdir/bar/down/to/foo/to"
40 echo cvsout >"$fromdir/bar/down/to/home-cvs-exclude"
41 echo cvsout >"$fromdir/mid/one-in-one-out"
42 echo one-in-one-out >"$fromdir/mid/.cvsignore"
43 echo cvsin >"$fromdir/mid/one-for-all"
44 echo expunged >"$fromdir/mid/for/foo/extra"
45 echo retained >"$fromdir/mid/for/foo/keep"
46 echo cvsin >"$fromdir/mid/for/one-in-one-out"
47 ln -s too "$fromdir/bar/down/to/foo/sym"
48
49 # Setup our test exclude/include file.
50
51 excl="$scratchdir/exclude-from"
52 cat >"$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
66 EOF
67
68 # Create the chk dir with what we expect to be excluded
69
70 checkit "$RSYNC -avv \"$fromdir/\" \"$chkdir/\"" "$fromdir" "$chkdir"
71
72 sleep 1 # Ensures that the rm commands will tweak the directory times.
73
74 rm -r "$chkdir"/foo/down
75 rm -r "$chkdir"/mid/for/foo/and
76 rm "$chkdir"/foo/file[235-9]
77 rm "$chkdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo/file[235-9]
78 rm "$chkdir"/mid/for/foo/extra
79
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/"
83
84 # Now, test if rsync excludes the same files.
85
86 checkit "$RSYNC -avv --exclude-from=$excl \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
87
88 # Modify the chk dir by removing cvs-ignored files and then tweaking the dir times.
89
90 rm "$chkdir"/foo/*.old
91 rm "$chkdir"/bar/down/to/foo/*.bak
92 rm "$chkdir"/bar/down/to/foo/*.junk
93 rm "$chkdir"/bar/down/to/home-cvs-exclude
94 rm "$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
101 checkit "$RSYNC -avvC --delete-excluded --exclude-from=$excl \
102     \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
103
104 # The script would have aborted on error, so getting here means we've won.
105 exit 0