core.hidedotfiles: hide '.git' dir by default
[git/dscho.git] / t / t4125-apply-ws-fuzz.sh
blob9671de799949f8f67f906cd3db907e3a53cf4eef
1 #!/bin/sh
3 test_description='applying patch that has broken whitespaces in context'
5 . ./test-lib.sh
7 test_expect_success setup '
9 >file &&
10 git add file &&
12 # file-0 is full of whitespace breakages
13 for l in a bb c d eeee f ggg h
15 echo "$l "
16 done >file-0 &&
18 # patch-0 creates a whitespace broken file
19 cat file-0 >file &&
20 git diff >patch-0 &&
21 git add file &&
23 # file-1 is still full of whitespace breakages,
24 # but has one line updated, without fixing any
25 # whitespaces.
26 # patch-1 records that change.
27 sed -e "s/d/D/" file-0 >file-1 &&
28 cat file-1 >file &&
29 git diff >patch-1 &&
31 # patch-all is the effect of both patch-0 and patch-1
32 >file &&
33 git add file &&
34 cat file-1 >file &&
35 git diff >patch-all &&
37 # patch-2 is the same as patch-1 but is based
38 # on a version that already has whitespace fixed,
39 # and does not introduce whitespace breakages.
40 sed -e "s/ \$//" patch-1 >patch-2 &&
42 # If all whitespace breakages are fixed the contents
43 # should look like file-fixed
44 sed -e "s/ \$//" file-1 >file-fixed
48 test_expect_success nofix '
50 >file &&
51 git add file &&
53 # Baseline. Applying without fixing any whitespace
54 # breakages.
55 git apply --whitespace=nowarn patch-0 &&
56 git apply --whitespace=nowarn patch-1 &&
58 # The result should obviously match.
59 test_cmp file-1 file
62 test_expect_success 'withfix (forward)' '
64 >file &&
65 git add file &&
67 # The first application will munge the context lines
68 # the second patch depends on. We should be able to
69 # adjust and still apply.
70 git apply --whitespace=fix patch-0 &&
71 git apply --whitespace=fix patch-1 &&
73 test_cmp file-fixed file
76 test_expect_success 'withfix (backward)' '
78 >file &&
79 git add file &&
81 # Now we have a whitespace breakages on our side.
82 git apply --whitespace=nowarn patch-0 &&
84 # And somebody sends in a patch based on image
85 # with whitespace already fixed.
86 git apply --whitespace=fix patch-2 &&
88 # The result should accept the whitespace fixed
89 # postimage. But the line with "h" is beyond context
90 # horizon and left unfixed.
92 sed -e /h/d file-fixed >fixed-head &&
93 sed -e /h/d file >file-head &&
94 test_cmp fixed-head file-head &&
96 sed -n -e /h/p file-fixed >fixed-tail &&
97 sed -n -e /h/p file >file-tail &&
99 ! test_cmp fixed-tail file-tail
103 test_done