]>
Commit | Line | Data |
---|---|---|
c1beba5b JH |
1 | #!/bin/sh |
2 | ||
3 | test_description='applying patch that has broken whitespaces in context' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | test_expect_success setup ' | |
8 | ||
9 | >file && | |
10 | git add file && | |
11 | ||
12 | # file-0 is full of whitespace breakages | |
efe26b9e | 13 | printf "%s \n" a bb c d eeee f ggg h >file-0 && |
c1beba5b JH |
14 | |
15 | # patch-0 creates a whitespace broken file | |
16 | cat file-0 >file && | |
17 | git diff >patch-0 && | |
18 | git add file && | |
19 | ||
20 | # file-1 is still full of whitespace breakages, | |
21 | # but has one line updated, without fixing any | |
22 | # whitespaces. | |
23 | # patch-1 records that change. | |
24 | sed -e "s/d/D/" file-0 >file-1 && | |
25 | cat file-1 >file && | |
26 | git diff >patch-1 && | |
27 | ||
28 | # patch-all is the effect of both patch-0 and patch-1 | |
29 | >file && | |
30 | git add file && | |
31 | cat file-1 >file && | |
32 | git diff >patch-all && | |
33 | ||
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. | |
9524cf29 | 37 | sed -e "s/ \$//" patch-1 >patch-2 && |
c1beba5b JH |
38 | |
39 | # If all whitespace breakages are fixed the contents | |
40 | # should look like file-fixed | |
9524cf29 | 41 | sed -e "s/ \$//" file-1 >file-fixed |
c1beba5b JH |
42 | |
43 | ' | |
44 | ||
45 | test_expect_success nofix ' | |
46 | ||
47 | >file && | |
48 | git add file && | |
49 | ||
50 | # Baseline. Applying without fixing any whitespace | |
51 | # breakages. | |
52 | git apply --whitespace=nowarn patch-0 && | |
53 | git apply --whitespace=nowarn patch-1 && | |
54 | ||
55 | # The result should obviously match. | |
82ebb0b6 | 56 | test_cmp file-1 file |
c1beba5b JH |
57 | ' |
58 | ||
59 | test_expect_success 'withfix (forward)' ' | |
60 | ||
61 | >file && | |
62 | git add file && | |
63 | ||
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 && | |
69 | ||
82ebb0b6 | 70 | test_cmp file-fixed file |
c1beba5b JH |
71 | ' |
72 | ||
73 | test_expect_success 'withfix (backward)' ' | |
74 | ||
75 | >file && | |
76 | git add file && | |
77 | ||
78 | # Now we have a whitespace breakages on our side. | |
79 | git apply --whitespace=nowarn patch-0 && | |
80 | ||
81 | # And somebody sends in a patch based on image | |
82 | # with whitespace already fixed. | |
83 | git apply --whitespace=fix patch-2 && | |
84 | ||
85 | # The result should accept the whitespace fixed | |
86 | # postimage. But the line with "h" is beyond context | |
87 | # horizon and left unfixed. | |
88 | ||
89 | sed -e /h/d file-fixed >fixed-head && | |
90 | sed -e /h/d file >file-head && | |
82ebb0b6 | 91 | test_cmp fixed-head file-head && |
c1beba5b JH |
92 | |
93 | sed -n -e /h/p file-fixed >fixed-tail && | |
94 | sed -n -e /h/p file >file-tail && | |
95 | ||
82ebb0b6 | 96 | ! test_cmp fixed-tail file-tail |
c1beba5b JH |
97 | |
98 | ' | |
99 | ||
100 | test_done |