t4108: replace create_file with test_write_lines
[git/raj.git] / t / t4108-apply-threeway.sh
blobb109ecbd9fc76eb505d089f2b62bbb7d496eb0c1
1 #!/bin/sh
3 test_description='git apply --3way'
5 . ./test-lib.sh
7 sanitize_conflicted_diff () {
8 sed -e '
9 /^index /d
10 s/^\(+[<>][<>][<>][<>]*\) .*/\1/
14 test_expect_success setup '
15 test_tick &&
16 test_write_lines 1 2 3 4 5 6 7 >one &&
17 cat one >two &&
18 git add one two &&
19 git commit -m initial &&
21 git branch side &&
23 test_tick &&
24 test_write_lines 1 two 3 4 5 six 7 >one &&
25 test_write_lines 1 two 3 4 5 6 7 >two &&
26 git commit -a -m master &&
28 git checkout side &&
29 test_write_lines 1 2 3 4 five 6 7 >one &&
30 test_write_lines 1 2 3 4 five 6 7 >two &&
31 git commit -a -m side &&
33 git checkout master
36 test_expect_success 'apply without --3way' '
37 git diff side^ side >P.diff &&
39 # should fail to apply
40 git reset --hard &&
41 git checkout master^0 &&
42 test_must_fail git apply --index P.diff &&
43 # should leave things intact
44 git diff-files --exit-code &&
45 git diff-index --exit-code --cached HEAD
48 test_expect_success 'apply with --3way' '
49 # Merging side should be similar to applying this patch
50 git diff ...side >P.diff &&
52 # The corresponding conflicted merge
53 git reset --hard &&
54 git checkout master^0 &&
55 test_must_fail git merge --no-commit side &&
56 git ls-files -s >expect.ls &&
57 git diff HEAD | sanitize_conflicted_diff >expect.diff &&
59 # should fail to apply
60 git reset --hard &&
61 git checkout master^0 &&
62 test_must_fail git apply --index --3way P.diff &&
63 git ls-files -s >actual.ls &&
64 git diff HEAD | sanitize_conflicted_diff >actual.diff &&
66 # The result should resemble the corresponding merge
67 test_cmp expect.ls actual.ls &&
68 test_cmp expect.diff actual.diff
71 test_expect_success 'apply with --3way with rerere enabled' '
72 git config rerere.enabled true &&
74 # Merging side should be similar to applying this patch
75 git diff ...side >P.diff &&
77 # The corresponding conflicted merge
78 git reset --hard &&
79 git checkout master^0 &&
80 test_must_fail git merge --no-commit side &&
82 # Manually resolve and record the resolution
83 test_write_lines 1 two 3 4 five six 7 >one &&
84 git rerere &&
85 cat one >expect &&
87 # should fail to apply
88 git reset --hard &&
89 git checkout master^0 &&
90 test_must_fail git apply --index --3way P.diff &&
92 # but rerere should have replayed the recorded resolution
93 test_cmp expect one
96 test_expect_success 'apply -3 with add/add conflict setup' '
97 git reset --hard &&
99 git checkout -b adder &&
100 test_write_lines 1 2 3 4 5 6 7 >three &&
101 test_write_lines 1 2 3 4 5 6 7 >four &&
102 git add three four &&
103 git commit -m "add three and four" &&
105 git checkout -b another adder^ &&
106 test_write_lines 1 2 3 4 5 6 7 >three &&
107 test_write_lines 1 2 3 four 5 6 7 >four &&
108 git add three four &&
109 git commit -m "add three and four" &&
111 # Merging another should be similar to applying this patch
112 git diff adder...another >P.diff &&
114 git checkout adder^0 &&
115 test_must_fail git merge --no-commit another &&
116 git ls-files -s >expect.ls &&
117 git diff HEAD | sanitize_conflicted_diff >expect.diff
120 test_expect_success 'apply -3 with add/add conflict' '
121 # should fail to apply ...
122 git reset --hard &&
123 git checkout adder^0 &&
124 test_must_fail git apply --index --3way P.diff &&
125 # ... and leave conflicts in the index and in the working tree
126 git ls-files -s >actual.ls &&
127 git diff HEAD | sanitize_conflicted_diff >actual.diff &&
129 # The result should resemble the corresponding merge
130 test_cmp expect.ls actual.ls &&
131 test_cmp expect.diff actual.diff
134 test_expect_success 'apply -3 with add/add conflict (dirty working tree)' '
135 # should fail to apply ...
136 git reset --hard &&
137 git checkout adder^0 &&
138 echo >>four &&
139 cat four >four.save &&
140 cat three >three.save &&
141 git ls-files -s >expect.ls &&
142 test_must_fail git apply --index --3way P.diff &&
143 # ... and should not touch anything
144 git ls-files -s >actual.ls &&
145 test_cmp expect.ls actual.ls &&
146 test_cmp four.save four &&
147 test_cmp three.save three
150 test_done