3 test_description
='git apply --3way'
14 sanitize_conflicted_diff
() {
17 s/^\(+[<>][<>][<>][<>]*\) .*/\1/
21 test_expect_success setup
'
23 create_file >one 1 2 3 4 5 6 7 &&
26 git commit -m initial &&
31 create_file >one 1 two 3 4 5 six 7 &&
32 create_file >two 1 two 3 4 5 6 7 &&
33 git commit -a -m master &&
36 create_file >one 1 2 3 4 five 6 7 &&
37 create_file >two 1 2 3 4 five 6 7 &&
38 git commit -a -m side &&
43 test_expect_success
'apply without --3way' '
44 git diff side^ side >P.diff &&
46 # should fail to apply
48 git checkout master^0 &&
49 test_must_fail git apply --index P.diff &&
50 # should leave things intact
51 git diff-files --exit-code &&
52 git diff-index --exit-code --cached HEAD
55 test_expect_success
'apply with --3way' '
56 # Merging side should be similar to applying this patch
57 git diff ...side >P.diff &&
59 # The corresponding conflicted merge
61 git checkout master^0 &&
62 test_must_fail git merge --no-commit side &&
63 git ls-files -s >expect.ls &&
64 git diff HEAD | sanitize_conflicted_diff >expect.diff &&
66 # should fail to apply
68 git checkout master^0 &&
69 test_must_fail git apply --index --3way P.diff &&
70 git ls-files -s >actual.ls &&
71 git diff HEAD | sanitize_conflicted_diff >actual.diff &&
73 # The result should resemble the corresponding merge
74 test_cmp expect.ls actual.ls &&
75 test_cmp expect.diff actual.diff
78 test_expect_success
'apply with --3way with rerere enabled' '
79 git config rerere.enabled true &&
81 # Merging side should be similar to applying this patch
82 git diff ...side >P.diff &&
84 # The corresponding conflicted merge
86 git checkout master^0 &&
87 test_must_fail git merge --no-commit side &&
89 # Manually resolve and record the resolution
90 create_file 1 two 3 4 five six 7 >one &&
94 # should fail to apply
96 git checkout master^0 &&
97 test_must_fail git apply --index --3way P.diff &&
99 # but rerere should have replayed the recorded resolution