blob: 475dfb57eee051f13c75bbf810938b54c752bad5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
#!/bin/sh
test_description='git apply --3way'
. ./test-lib.sh
create_file () {
for i
do
echo "$i"
done
}
sanitize_conflicted_diff () {
sed -e '
/^index /d
s/^\(+[<>][<>][<>][<>]*\) .*/\1/
'
}
test_expect_success setup '
test_tick &&
create_file >one 1 2 3 4 5 6 7 &&
cat one >two &&
git add one two &&
git commit -m initial &&
git branch side &&
test_tick &&
create_file >one 1 two 3 4 5 six 7 &&
create_file >two 1 two 3 4 5 6 7 &&
git commit -a -m master &&
git checkout side &&
create_file >one 1 2 3 4 five 6 7 &&
create_file >two 1 2 3 4 five 6 7 &&
git commit -a -m side &&
git checkout master
'
test_expect_success 'apply without --3way' '
git diff side^ side >P.diff &&
# should fail to apply
git reset --hard &&
git checkout master^0 &&
test_must_fail git apply --index P.diff &&
# should leave things intact
git diff-files --exit-code &&
git diff-index --exit-code --cached HEAD
'
test_expect_success 'apply with --3way' '
# Merging side should be similar to applying this patch
git diff ...side >P.diff &&
# The corresponding conflicted merge
git reset --hard &&
git checkout master^0 &&
test_must_fail git merge --no-commit side &&
git ls-files -s >expect.ls &&
git diff HEAD | sanitize_conflicted_diff >expect.diff &&
# should fail to apply
git reset --hard &&
git checkout master^0 &&
test_must_fail git apply --index --3way P.diff &&
git ls-files -s >actual.ls &&
git diff HEAD | sanitize_conflicted_diff >actual.diff &&
# The result should resemble the corresponding merge
test_cmp expect.ls actual.ls &&
test_cmp expect.diff actual.diff
'
test_done
|