Add --src/dst-prefix to git-formt-patch in git-rebase.sh
[git/jnareb-git.git] / t / t3507-cherry-pick-conflict.sh
blobe25cf8039a310e325c23e85ce5fc845a0f681200
1 #!/bin/sh
3 test_description='test cherry-pick and revert with conflicts
6 + picked: rewrites foo to c
7 + base: rewrites foo to b
8 + initial: writes foo as a, unrelated as unrelated
12 . ./test-lib.sh
14 test_expect_success setup '
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
25 test_expect_success 'failed cherry-pick does not advance HEAD' '
27 git checkout -f initial^0 &&
28 git read-tree -u --reset HEAD &&
29 git clean -d -f -f -q -x &&
31 git update-index --refresh &&
32 git diff-index --exit-code HEAD &&
34 head=$(git rev-parse HEAD) &&
35 test_must_fail git cherry-pick picked &&
36 newhead=$(git rev-parse HEAD) &&
38 test "$head" = "$newhead"
41 test_expect_success 'failed cherry-pick produces dirty index' '
43 git checkout -f initial^0 &&
44 git read-tree -u --reset HEAD &&
45 git clean -d -f -f -q -x &&
47 git update-index --refresh &&
48 git diff-index --exit-code HEAD &&
50 test_must_fail git cherry-pick picked &&
52 test_must_fail git update-index --refresh -q &&
53 test_must_fail git diff-index --exit-code HEAD
56 test_expect_success 'failed cherry-pick registers participants in index' '
58 git read-tree -u --reset HEAD &&
59 git clean -d -f -f -q -x &&
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 &&
75 git update-index --refresh &&
76 git diff-index --exit-code HEAD &&
78 test_must_fail git cherry-pick picked &&
79 git ls-files --stage --unmerged > actual &&
81 test_cmp expected actual
84 test_expect_success 'failed cherry-pick describes conflict in work tree' '
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
92 =======
94 >>>>>>> objid picked
95 EOF
97 git update-index --refresh &&
98 git diff-index --exit-code HEAD &&
100 test_must_fail git cherry-pick picked &&
102 sed "s/[a-f0-9]*\.\.\./objid/" foo > actual &&
103 test_cmp expected actual
106 test_expect_success 'diff3 -m style' '
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
115 ||||||| parent of objid picked
117 =======
119 >>>>>>> objid picked
122 git update-index --refresh &&
123 git diff-index --exit-code HEAD &&
125 test_must_fail git cherry-pick picked &&
127 sed "s/[a-f0-9]*\.\.\./objid/" foo > actual &&
128 test_cmp expected actual
131 test_expect_success 'revert also handles conflicts sanely' '
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
139 =======
141 >>>>>>> parent of objid picked
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 &&
158 git update-index --refresh &&
159 git diff-index --exit-code HEAD &&
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 &&
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
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
182 ||||||| objid picked
184 =======
186 >>>>>>> parent of objid picked
189 git update-index --refresh &&
190 git diff-index --exit-code HEAD &&
192 test_must_fail git revert picked &&
194 sed "s/[a-f0-9]*\.\.\./objid/" foo > actual &&
195 test_cmp expected actual
198 test_done