@@ -4,37 +4,31 @@ test_description='git apply --3way'
4
4
5
5
. ./test-lib.sh
6
6
7
- create_file () {
8
- for i
9
- do
10
- echo " $i "
11
- done
12
- }
13
-
14
- sanitize_conflicted_diff () {
7
+ print_sanitized_conflicted_diff () {
8
+ git diff HEAD > diff.raw &&
15
9
sed -e '
16
10
/^index /d
17
- s/^\(+[<>][<>][<>][<>]*\) .*/\1/
18
- '
11
+ s/^\(+[<>| ][<>| ][<>| ][<>| ]*\) .*/\1/
12
+ ' diff.raw
19
13
}
20
14
21
15
test_expect_success setup '
22
16
test_tick &&
23
- create_file >one 1 2 3 4 5 6 7 &&
17
+ test_write_lines 1 2 3 4 5 6 7 >one &&
24
18
cat one >two &&
25
19
git add one two &&
26
20
git commit -m initial &&
27
21
28
22
git branch side &&
29
23
30
24
test_tick &&
31
- create_file >one 1 two 3 4 5 six 7 &&
32
- create_file >two 1 two 3 4 5 6 7 &&
25
+ test_write_lines 1 two 3 4 5 six 7 >one &&
26
+ test_write_lines 1 two 3 4 5 6 7 >two &&
33
27
git commit -a -m master &&
34
28
35
29
git checkout side &&
36
- create_file >one 1 2 3 4 five 6 7 &&
37
- create_file >two 1 2 3 4 five 6 7 &&
30
+ test_write_lines 1 2 3 4 five 6 7 >one &&
31
+ test_write_lines 1 2 3 4 five 6 7 >two &&
38
32
git commit -a -m side &&
39
33
40
34
git checkout master
@@ -52,7 +46,7 @@ test_expect_success 'apply without --3way' '
52
46
git diff-index --exit-code --cached HEAD
53
47
'
54
48
55
- test_expect_success ' apply with --3way ' '
49
+ test_apply_with_3way () {
56
50
# Merging side should be similar to applying this patch
57
51
git diff ...side > P.diff &&
58
52
@@ -61,22 +55,31 @@ test_expect_success 'apply with --3way' '
61
55
git checkout master^0 &&
62
56
test_must_fail git merge --no-commit side &&
63
57
git ls-files -s > expect.ls &&
64
- git diff HEAD | sanitize_conflicted_diff >expect.diff &&
58
+ print_sanitized_conflicted_diff > expect.diff &&
65
59
66
60
# should fail to apply
67
61
git reset --hard &&
68
62
git checkout master^0 &&
69
63
test_must_fail git apply --index --3way P.diff &&
70
64
git ls-files -s > actual.ls &&
71
- git diff HEAD | sanitize_conflicted_diff >actual.diff &&
65
+ print_sanitized_conflicted_diff > actual.diff &&
72
66
73
67
# The result should resemble the corresponding merge
74
68
test_cmp expect.ls actual.ls &&
75
69
test_cmp expect.diff actual.diff
70
+ }
71
+
72
+ test_expect_success ' apply with --3way' '
73
+ test_apply_with_3way
74
+ '
75
+
76
+ test_expect_success ' apply with --3way with merge.conflictStyle = diff3' '
77
+ test_config merge.conflictStyle diff3 &&
78
+ test_apply_with_3way
76
79
'
77
80
78
81
test_expect_success ' apply with --3way with rerere enabled' '
79
- git config rerere.enabled true &&
82
+ test_config rerere.enabled true &&
80
83
81
84
# Merging side should be similar to applying this patch
82
85
git diff ...side >P.diff &&
@@ -87,7 +90,7 @@ test_expect_success 'apply with --3way with rerere enabled' '
87
90
test_must_fail git merge --no-commit side &&
88
91
89
92
# Manually resolve and record the resolution
90
- create_file 1 two 3 4 five six 7 >one &&
93
+ test_write_lines 1 two 3 4 five six 7 >one &&
91
94
git rerere &&
92
95
cat one >expect &&
93
96
@@ -104,14 +107,14 @@ test_expect_success 'apply -3 with add/add conflict setup' '
104
107
git reset --hard &&
105
108
106
109
git checkout -b adder &&
107
- create_file 1 2 3 4 5 6 7 >three &&
108
- create_file 1 2 3 4 5 6 7 >four &&
110
+ test_write_lines 1 2 3 4 5 6 7 >three &&
111
+ test_write_lines 1 2 3 4 5 6 7 >four &&
109
112
git add three four &&
110
113
git commit -m "add three and four" &&
111
114
112
115
git checkout -b another adder^ &&
113
- create_file 1 2 3 4 5 6 7 >three &&
114
- create_file 1 2 3 four 5 6 7 >four &&
116
+ test_write_lines 1 2 3 4 5 6 7 >three &&
117
+ test_write_lines 1 2 3 four 5 6 7 >four &&
115
118
git add three four &&
116
119
git commit -m "add three and four" &&
117
120
@@ -121,7 +124,7 @@ test_expect_success 'apply -3 with add/add conflict setup' '
121
124
git checkout adder^0 &&
122
125
test_must_fail git merge --no-commit another &&
123
126
git ls-files -s >expect.ls &&
124
- git diff HEAD | sanitize_conflicted_diff >expect.diff
127
+ print_sanitized_conflicted_diff >expect.diff
125
128
'
126
129
127
130
test_expect_success ' apply -3 with add/add conflict' '
@@ -131,7 +134,7 @@ test_expect_success 'apply -3 with add/add conflict' '
131
134
test_must_fail git apply --index --3way P.diff &&
132
135
# ... and leave conflicts in the index and in the working tree
133
136
git ls-files -s >actual.ls &&
134
- git diff HEAD | sanitize_conflicted_diff >actual.diff &&
137
+ print_sanitized_conflicted_diff >actual.diff &&
135
138
136
139
# The result should resemble the corresponding merge
137
140
test_cmp expect.ls actual.ls &&
0 commit comments