blob: 9671de799949f8f67f906cd3db907e3a53cf4eef [file] [log] [blame]
Junio C Hamanoc1beba52008-01-30 15:24:34 -08001#!/bin/sh
2
3test_description='applying patch that has broken whitespaces in context'
4
5. ./test-lib.sh
6
7test_expect_success setup '
8
9 >file &&
10 git add file &&
11
12 # file-0 is full of whitespace breakages
13 for l in a bb c d eeee f ggg h
14 do
15 echo "$l "
16 done >file-0 &&
17
18 # patch-0 creates a whitespace broken file
19 cat file-0 >file &&
20 git diff >patch-0 &&
21 git add file &&
22
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 &&
30
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 &&
36
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.
Stephen Boyd9524cf22010-01-26 15:08:31 -080040 sed -e "s/ \$//" patch-1 >patch-2 &&
Junio C Hamanoc1beba52008-01-30 15:24:34 -080041
42 # If all whitespace breakages are fixed the contents
43 # should look like file-fixed
Stephen Boyd9524cf22010-01-26 15:08:31 -080044 sed -e "s/ \$//" file-1 >file-fixed
Junio C Hamanoc1beba52008-01-30 15:24:34 -080045
46'
47
48test_expect_success nofix '
49
50 >file &&
51 git add file &&
52
53 # Baseline. Applying without fixing any whitespace
54 # breakages.
55 git apply --whitespace=nowarn patch-0 &&
56 git apply --whitespace=nowarn patch-1 &&
57
58 # The result should obviously match.
Jeff King82ebb0b2008-03-12 17:36:36 -040059 test_cmp file-1 file
Junio C Hamanoc1beba52008-01-30 15:24:34 -080060'
61
62test_expect_success 'withfix (forward)' '
63
64 >file &&
65 git add file &&
66
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 &&
72
Jeff King82ebb0b2008-03-12 17:36:36 -040073 test_cmp file-fixed file
Junio C Hamanoc1beba52008-01-30 15:24:34 -080074'
75
76test_expect_success 'withfix (backward)' '
77
78 >file &&
79 git add file &&
80
81 # Now we have a whitespace breakages on our side.
82 git apply --whitespace=nowarn patch-0 &&
83
84 # And somebody sends in a patch based on image
85 # with whitespace already fixed.
86 git apply --whitespace=fix patch-2 &&
87
88 # The result should accept the whitespace fixed
89 # postimage. But the line with "h" is beyond context
90 # horizon and left unfixed.
91
92 sed -e /h/d file-fixed >fixed-head &&
93 sed -e /h/d file >file-head &&
Jeff King82ebb0b2008-03-12 17:36:36 -040094 test_cmp fixed-head file-head &&
Junio C Hamanoc1beba52008-01-30 15:24:34 -080095
96 sed -n -e /h/p file-fixed >fixed-tail &&
97 sed -n -e /h/p file >file-tail &&
98
Jeff King82ebb0b2008-03-12 17:36:36 -040099 ! test_cmp fixed-tail file-tail
Junio C Hamanoc1beba52008-01-30 15:24:34 -0800100
101'
102
103test_done