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 printf "%s \n" a bb c d eeee f ggg h >file-0 &&
15 # patch-0 creates a whitespace broken file
20 # file-1 is still full of whitespace breakages,
21 # but has one line updated, without fixing any
23 # patch-1 records that change.
24 sed -e "s/d/D/" file-0 >file-1 &&
28 # patch-all is the effect of both patch-0 and patch-1
32 git diff >patch-all &&
34 # patch-2 is the same as patch-1 but is based
35 # on a version that already has whitespace fixed,
36 # and does not introduce whitespace breakages.
37 sed -e "s/ \$//" patch-1 >patch-2 &&
39 # If all whitespace breakages are fixed the contents
40 # should look like file-fixed
41 sed -e "s/ \$//" file-1 >file-fixed
45 test_expect_success nofix
'
50 # Baseline. Applying without fixing any whitespace
52 git apply --whitespace=nowarn patch-0 &&
53 git apply --whitespace=nowarn patch-1 &&
55 # The result should obviously match.
59 test_expect_success
'withfix (forward)' '
64 # The first application will munge the context lines
65 # the second patch depends on. We should be able to
66 # adjust and still apply.
67 git apply --whitespace=fix patch-0 &&
68 git apply --whitespace=fix patch-1 &&
70 test_cmp file-fixed file
73 test_expect_success
'withfix (backward)' '
78 # Now we have a whitespace breakages on our side.
79 git apply --whitespace=nowarn patch-0 &&
81 # And somebody sends in a patch based on image
82 # with whitespace already fixed.
83 git apply --whitespace=fix patch-2 &&
85 # The result should accept the whitespace fixed
86 # postimage. But the line with "h" is beyond context
87 # horizon and left unfixed.
89 sed -e /h/d file-fixed >fixed-head &&
90 sed -e /h/d file >file-head &&
91 test_cmp fixed-head file-head &&
93 sed -n -e /h/p file-fixed >fixed-tail &&
94 sed -n -e /h/p file >file-tail &&
96 ! test_cmp fixed-tail file-tail