3 test_description
='applying patch that has broken whitespaces in context'
5 TEST_PASSES_SANITIZE_LEAK
=true
8 test_expect_success setup
'
13 # file-0 is full of whitespace breakages
14 printf "%s \n" a bb c d eeee f ggg h >file-0 &&
16 # patch-0 creates a whitespace broken file
21 # file-1 is still full of whitespace breakages,
22 # but has one line updated, without fixing any
24 # patch-1 records that change.
25 sed -e "s/d/D/" file-0 >file-1 &&
29 # patch-all is the effect of both patch-0 and patch-1
33 git diff >patch-all &&
35 # patch-2 is the same as patch-1 but is based
36 # on a version that already has whitespace fixed,
37 # and does not introduce whitespace breakages.
38 sed -e "s/ \$//" patch-1 >patch-2 &&
40 # If all whitespace breakages are fixed the contents
41 # should look like file-fixed
42 sed -e "s/ \$//" file-1 >file-fixed
46 test_expect_success nofix
'
51 # Baseline. Applying without fixing any whitespace
53 git apply --whitespace=nowarn patch-0 &&
54 git apply --whitespace=nowarn patch-1 &&
56 # The result should obviously match.
60 test_expect_success
'withfix (forward)' '
65 # The first application will munge the context lines
66 # the second patch depends on. We should be able to
67 # adjust and still apply.
68 git apply --whitespace=fix patch-0 &&
69 git apply --whitespace=fix patch-1 &&
71 test_cmp file-fixed file
74 test_expect_success
'withfix (backward)' '
79 # Now we have a whitespace breakages on our side.
80 git apply --whitespace=nowarn patch-0 &&
82 # And somebody sends in a patch based on image
83 # with whitespace already fixed.
84 git apply --whitespace=fix patch-2 &&
86 # The result should accept the whitespace fixed
87 # postimage. But the line with "h" is beyond context
88 # horizon and left unfixed.
90 sed -e /h/d file-fixed >fixed-head &&
91 sed -e /h/d file >file-head &&
92 test_cmp fixed-head file-head &&
94 sed -n -e /h/p file-fixed >fixed-tail &&
95 sed -n -e /h/p file >file-tail &&
97 ! test_cmp fixed-tail file-tail