1#!/bin/sh
23
test_description='test cherry-pick and revert with conflicts
45
-
6+ picked: rewrites foo to c
7+ base: rewrites foo to b
8+ initial: writes foo as a, unrelated as unrelated
910
'
1112
. ./test-lib.sh
1314
test_expect_success setup '
1516
echo unrelated >unrelated &&
17git add unrelated &&
18test_commit initial foo a &&
19test_commit base foo b &&
20test_commit picked foo c &&
21git config advice.detachedhead false
2223
'
2425
test_expect_success 'failed cherry-pick does not advance HEAD' '
2627
git checkout -f initial^0 &&
28git read-tree -u --reset HEAD &&
29git clean -d -f -f -q -x &&
3031
git update-index --refresh &&
32git diff-index --exit-code HEAD &&
3334
head=$(git rev-parse HEAD) &&
35test_must_fail git cherry-pick picked &&
36newhead=$(git rev-parse HEAD) &&
3738
test "$head" = "$newhead"
39'
4041
test_expect_success 'failed cherry-pick produces dirty index' '
4243
git checkout -f initial^0 &&
44git read-tree -u --reset HEAD &&
45git clean -d -f -f -q -x &&
4647
git update-index --refresh &&
48git diff-index --exit-code HEAD &&
4950
test_must_fail git cherry-pick picked &&
5152
test_must_fail git update-index --refresh -q &&
53test_must_fail git diff-index --exit-code HEAD
54'
5556
test_expect_success 'failed cherry-pick registers participants in index' '
5758
git read-tree -u --reset HEAD &&
59git clean -d -f -f -q -x &&
60{
61git checkout base -- foo &&
62git ls-files --stage foo &&
63git checkout initial -- foo &&
64git ls-files --stage foo &&
65git checkout picked -- foo &&
66git ls-files --stage foo
67} > stages &&
68sed "
691 s/ 0 / 1 /
702 s/ 0 / 2 /
713 s/ 0 / 3 /
72" < stages > expected &&
73git checkout -f initial^0 &&
7475
git update-index --refresh &&
76git diff-index --exit-code HEAD &&
7778
test_must_fail git cherry-pick picked &&
79git ls-files --stage --unmerged > actual &&
8081
test_cmp expected actual
82'
8384
test_expect_success 'failed cherry-pick describes conflict in work tree' '
8586
git checkout -f initial^0 &&
87git read-tree -u --reset HEAD &&
88git clean -d -f -f -q -x &&
89cat <<-EOF > expected &&
90<<<<<<< HEAD
91a
92=======
93c
94>>>>>>> objid picked
95EOF
9697
git update-index --refresh &&
98git diff-index --exit-code HEAD &&
99100
test_must_fail git cherry-pick picked &&
101102
sed "s/[a-f0-9]*\.\.\./objid/" foo > actual &&
103test_cmp expected actual
104'
105106
test_expect_success 'diff3 -m style' '
107108
git config merge.conflictstyle diff3 &&
109git checkout -f initial^0 &&
110git read-tree -u --reset HEAD &&
111git clean -d -f -f -q -x &&
112cat <<-EOF > expected &&
113<<<<<<< HEAD
114a
115||||||| parent of objid picked
116b
117=======
118c
119>>>>>>> objid picked
120EOF
121122
git update-index --refresh &&
123git diff-index --exit-code HEAD &&
124125
test_must_fail git cherry-pick picked &&
126127
sed "s/[a-f0-9]*\.\.\./objid/" foo > actual &&
128test_cmp expected actual
129'
130131
test_expect_success 'revert also handles conflicts sanely' '
132133
git config --unset merge.conflictstyle &&
134git read-tree -u --reset HEAD &&
135git clean -d -f -f -q -x &&
136cat <<-EOF > expected &&
137<<<<<<< HEAD
138a
139=======
140b
141>>>>>>> parent of objid picked
142EOF
143{
144git checkout picked -- foo &&
145git ls-files --stage foo &&
146git checkout initial -- foo &&
147git ls-files --stage foo &&
148git checkout base -- foo &&
149git ls-files --stage foo
150} > stages &&
151sed "
1521 s/ 0 / 1 /
1532 s/ 0 / 2 /
1543 s/ 0 / 3 /
155" < stages > expected-stages &&
156git checkout -f initial^0 &&
157158
git update-index --refresh &&
159git diff-index --exit-code HEAD &&
160161
head=$(git rev-parse HEAD) &&
162test_must_fail git revert picked &&
163newhead=$(git rev-parse HEAD) &&
164git ls-files --stage --unmerged > actual-stages &&
165166
test "$head" = "$newhead" &&
167test_must_fail git update-index --refresh -q &&
168test_must_fail git diff-index --exit-code HEAD &&
169test_cmp expected-stages actual-stages &&
170sed "s/[a-f0-9]*\.\.\./objid/" foo > actual &&
171test_cmp expected actual
172'
173174
test_expect_success 'revert conflict, diff3 -m style' '
175git config merge.conflictstyle diff3 &&
176git checkout -f initial^0 &&
177git read-tree -u --reset HEAD &&
178git clean -d -f -f -q -x &&
179cat <<-EOF > expected &&
180<<<<<<< HEAD
181a
182||||||| objid picked
183c
184=======
185b
186>>>>>>> parent of objid picked
187EOF
188189
git update-index --refresh &&
190git diff-index --exit-code HEAD &&
191192
test_must_fail git revert picked &&
193194
sed "s/[a-f0-9]*\.\.\./objid/" foo > actual &&
195test_cmp expected actual
196'
197198
test_done