3 test_description='applying patch that has broken whitespaces in context'
7 test_expect_success setup '
12 # file-0 is full of whitespace breakages
13 for l in a bb c d eeee f ggg h
18 # patch-0 creates a whitespace broken file
23 # file-1 is still full of whitespace breakages,
24 # but has one line updated, without fixing any
26 # patch-1 records that change.
27 sed -e "s/d/D/" file-0 >file-1 &&
31 # patch-all is the effect of both patch-0 and patch-1
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 '
53 # Baseline. Applying without fixing any whitespace
55 git apply --whitespace=nowarn patch-0 &&
56 git apply --whitespace=nowarn patch-1 &&
58 # The result should obviously match.
62 test_expect_success 'withfix (forward)' '
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)' '
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