Added testing for --filter and merge-file features.
[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 . "$suitedir/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 makepath "$fromdir/foo/down/to/you"
24 makepath "$fromdir/bar/down/to/foo/too"
25 makepath "$fromdir/mid/for/foo/and/that/is/who"
26 cat >"$fromdir/.excl" <<EOF
27 - down
28 : .excl-temp
29 !
30 - .excl
31 - *.bak
32 - *.old
33 - *.junk
34 EOF
35 echo kept >"$fromdir/foo/file1"
36 echo removed >"$fromdir/foo/file2"
37 echo cvsout >"$fromdir/foo/file2.old"
38 cat >"$fromdir/foo/.excl" <<EOF
39 + .excl
40 - file1
41 EOF
42 cat >"$fromdir/bar/.excl" <<EOF
43 - home-cvs-exclude
44 : .excl2
45 + to
46 EOF
47 echo cvsout >"$fromdir/bar/down/to/home-cvs-exclude"
48 cat >"$fromdir/bar/down/to/.excl2" <<EOF
49 - .excl2
50 EOF
51 echo keeper >"$fromdir/bar/down/to/foo/file1"
52 echo cvsout >"$fromdir/bar/down/to/foo/file1.bak"
53 echo gone >"$fromdir/bar/down/to/foo/file3"
54 echo lost >"$fromdir/bar/down/to/foo/file4"
55 echo cvsout >"$fromdir/bar/down/to/foo/file4.junk"
56 echo smashed >"$fromdir/bar/down/to/foo/to"
57 cat >"$fromdir/bar/down/to/foo/.excl2" <<EOF
58 + *.junk
59 EOF
60 # This one should be ineffectual
61 cat >"$fromdir/mid/.excl2" <<EOF
62 - extra
63 EOF
64 echo cvsout >"$fromdir/mid/one-in-one-out"
65 echo one-in-one-out >"$fromdir/mid/.cvsignore"
66 echo cvsin >"$fromdir/mid/one-for-all"
67 cat >"$fromdir/mid/.excl" <<EOF
68 :C
69 EOF
70 echo cvsin >"$fromdir/mid/for/one-in-one-out"
71 echo expunged >"$fromdir/mid/for/foo/extra"
72 echo retained >"$fromdir/mid/for/foo/keep"
73 ln -s too "$fromdir/bar/down/to/foo/sym"
74
75 # Setup our test exclude/include files.
76
77 excl="$scratchdir/exclude-from"
78 cat >"$excl" <<EOF
79 !
80 # If the second line of these two lines does anything, it's a bug.
81 + **/bar
82 - /bar
83 # This should match against the whole path, not just the name.
84 + foo**too
85 # This should float at the end of the path.
86 - foo/*/
87 # Test some normal excludes.  Competing lines are paired.
88 + t[o]/
89 - to
90 + file4
91 - file[2-9]
92 - /mid/for/foo/extra
93 EOF
94
95 cat >"$scratchdir/.cvsignore" <<EOF
96 home-cvs-exclude
97 EOF
98
99 # Create the chk dir with what we expect to be excluded
100
101 checkit "$RSYNC -avv \"$fromdir/\" \"$chkdir/\"" "$fromdir" "$chkdir"
102
103 sleep 1 # Ensures that the rm commands will tweak the directory times.
104
105 rm -r "$chkdir"/foo/down
106 rm -r "$chkdir"/mid/for/foo/and
107 rm "$chkdir"/foo/file[235-9]
108 rm "$chkdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo/file[235-9]
109 rm "$chkdir"/mid/for/foo/extra
110
111 # Un-tweak the directory times in our first (weak) exclude test (though
112 # it's a good test of the --existing option).
113 $RSYNC -av --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/"
114
115 # Now, test if rsync excludes the same files.
116
117 checkit "$RSYNC -avv --exclude-from=\"$excl\" \
118     --delete \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
119
120 # Modify the chk dir by removing cvs-ignored files and then tweaking the dir times.
121
122 rm "$chkdir"/foo/*.old
123 rm "$chkdir"/bar/down/to/foo/*.bak
124 rm "$chkdir"/bar/down/to/foo/*.junk
125 rm "$chkdir"/bar/down/to/home-cvs-exclude
126 rm "$chkdir"/mid/one-in-one-out
127
128 $RSYNC -av --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/"
129
130 # Now, test if rsync excludes the same files, this time with --cvs-exclude
131 # and --delete-excluded.
132
133 checkit "$RSYNC -avvC --filter=\". $excl\" \
134     --delete-excluded \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
135
136 # Modify the chk dir for our merge-exclude test and then tweak the dir times.
137
138 rm "$chkdir"/.excl
139 rm "$chkdir"/foo/file1
140 rm "$chkdir"/bar/.excl
141 rm "$chkdir"/bar/down/to/.excl2
142 rm "$chkdir"/bar/down/to/foo/.excl2
143 rm "$chkdir"/mid/.excl
144 cp -p "$fromdir"/bar/down/to/foo/*.junk "$chkdir"/bar/down/to/foo
145 cp -p "$fromdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo
146
147 $RSYNC -av --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/"
148
149 # Now, test if rsync excludes the same files, this time with a merge-exclude
150 # file.
151
152 checkit "sed '/!/d' \"$excl\" | $RSYNC -avv -f :_.excl -f ._- \
153     --delete-excluded \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
154
155 # The script would have aborted on error, so getting here means we've won.
156 exit 0