Skip to content

Commit 6a84334

Browse files
jrngitster
authored andcommitted
tests: document cherry-pick behavior in face of conflicts
We are about to change the format of the conflict hunks that cherry-pick and revert write. Add tests checking the current behavior first. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 47349a8 commit 6a84334

File tree

1 file changed

+198
-0
lines changed

1 file changed

+198
-0
lines changed

t/t3507-cherry-pick-conflict.sh

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
#!/bin/sh
2+
3+
test_description='test cherry-pick and revert with conflicts
4+
5+
-
6+
+ picked: rewrites foo to c
7+
+ base: rewrites foo to b
8+
+ initial: writes foo as a, unrelated as unrelated
9+
10+
'
11+
12+
. ./test-lib.sh
13+
14+
test_expect_success setup '
15+
16+
echo unrelated >unrelated &&
17+
git add unrelated &&
18+
test_commit initial foo a &&
19+
test_commit base foo b &&
20+
test_commit picked foo c &&
21+
git config advice.detachedhead false
22+
23+
'
24+
25+
test_expect_success 'failed cherry-pick does not advance HEAD' '
26+
27+
git checkout -f initial^0 &&
28+
git read-tree -u --reset HEAD &&
29+
git clean -d -f -f -q -x &&
30+
31+
git update-index --refresh &&
32+
git diff-index --exit-code HEAD &&
33+
34+
head=$(git rev-parse HEAD) &&
35+
test_must_fail git cherry-pick picked &&
36+
newhead=$(git rev-parse HEAD) &&
37+
38+
test "$head" = "$newhead"
39+
'
40+
41+
test_expect_success 'failed cherry-pick produces dirty index' '
42+
43+
git checkout -f initial^0 &&
44+
git read-tree -u --reset HEAD &&
45+
git clean -d -f -f -q -x &&
46+
47+
git update-index --refresh &&
48+
git diff-index --exit-code HEAD &&
49+
50+
test_must_fail git cherry-pick picked &&
51+
52+
test_must_fail git update-index --refresh -q &&
53+
test_must_fail git diff-index --exit-code HEAD
54+
'
55+
56+
test_expect_success 'failed cherry-pick registers participants in index' '
57+
58+
git read-tree -u --reset HEAD &&
59+
git clean -d -f -f -q -x &&
60+
{
61+
git checkout base -- foo &&
62+
git ls-files --stage foo &&
63+
git checkout initial -- foo &&
64+
git ls-files --stage foo &&
65+
git checkout picked -- foo &&
66+
git ls-files --stage foo
67+
} > stages &&
68+
sed "
69+
1 s/ 0 / 1 /
70+
2 s/ 0 / 2 /
71+
3 s/ 0 / 3 /
72+
" < stages > expected &&
73+
git checkout -f initial^0 &&
74+
75+
git update-index --refresh &&
76+
git diff-index --exit-code HEAD &&
77+
78+
test_must_fail git cherry-pick picked &&
79+
git ls-files --stage --unmerged > actual &&
80+
81+
test_cmp expected actual
82+
'
83+
84+
test_expect_success 'failed cherry-pick describes conflict in work tree' '
85+
86+
git checkout -f initial^0 &&
87+
git read-tree -u --reset HEAD &&
88+
git clean -d -f -f -q -x &&
89+
cat <<-EOF > expected &&
90+
<<<<<<< HEAD
91+
a
92+
=======
93+
c
94+
>>>>>>> objid picked
95+
EOF
96+
97+
git update-index --refresh &&
98+
git diff-index --exit-code HEAD &&
99+
100+
test_must_fail git cherry-pick picked &&
101+
102+
sed "s/[a-f0-9]*\.\.\./objid/" foo > actual &&
103+
test_cmp expected actual
104+
'
105+
106+
test_expect_success 'diff3 -m style' '
107+
108+
git config merge.conflictstyle diff3 &&
109+
git checkout -f initial^0 &&
110+
git read-tree -u --reset HEAD &&
111+
git clean -d -f -f -q -x &&
112+
cat <<-EOF > expected &&
113+
<<<<<<< HEAD
114+
a
115+
|||||||
116+
b
117+
=======
118+
c
119+
>>>>>>> objid picked
120+
EOF
121+
122+
git update-index --refresh &&
123+
git diff-index --exit-code HEAD &&
124+
125+
test_must_fail git cherry-pick picked &&
126+
127+
sed "s/[a-f0-9]*\.\.\./objid/" foo > actual &&
128+
test_cmp expected actual
129+
'
130+
131+
test_expect_success 'revert also handles conflicts sanely' '
132+
133+
git config --unset merge.conflictstyle &&
134+
git read-tree -u --reset HEAD &&
135+
git clean -d -f -f -q -x &&
136+
cat <<-EOF > expected &&
137+
<<<<<<< HEAD
138+
a
139+
=======
140+
b
141+
>>>>>>> objid picked
142+
EOF
143+
{
144+
git checkout picked -- foo &&
145+
git ls-files --stage foo &&
146+
git checkout initial -- foo &&
147+
git ls-files --stage foo &&
148+
git checkout base -- foo &&
149+
git ls-files --stage foo
150+
} > stages &&
151+
sed "
152+
1 s/ 0 / 1 /
153+
2 s/ 0 / 2 /
154+
3 s/ 0 / 3 /
155+
" < stages > expected-stages &&
156+
git checkout -f initial^0 &&
157+
158+
git update-index --refresh &&
159+
git diff-index --exit-code HEAD &&
160+
161+
head=$(git rev-parse HEAD) &&
162+
test_must_fail git revert picked &&
163+
newhead=$(git rev-parse HEAD) &&
164+
git ls-files --stage --unmerged > actual-stages &&
165+
166+
test "$head" = "$newhead" &&
167+
test_must_fail git update-index --refresh -q &&
168+
test_must_fail git diff-index --exit-code HEAD &&
169+
test_cmp expected-stages actual-stages &&
170+
sed "s/[a-f0-9]*\.\.\./objid/" foo > actual &&
171+
test_cmp expected actual
172+
'
173+
174+
test_expect_success 'revert conflict, diff3 -m style' '
175+
git config merge.conflictstyle diff3 &&
176+
git checkout -f initial^0 &&
177+
git read-tree -u --reset HEAD &&
178+
git clean -d -f -f -q -x &&
179+
cat <<-EOF > expected &&
180+
<<<<<<< HEAD
181+
a
182+
|||||||
183+
c
184+
=======
185+
b
186+
>>>>>>> objid picked
187+
EOF
188+
189+
git update-index --refresh &&
190+
git diff-index --exit-code HEAD &&
191+
192+
test_must_fail git revert picked &&
193+
194+
sed "s/[a-f0-9]*\.\.\./objid/" foo > actual &&
195+
test_cmp expected actual
196+
'
197+
198+
test_done

0 commit comments

Comments
 (0)