Jonathan Nieder | 6a84334 | 2010-03-20 19:28:14 -0500 | [diff] [blame] | 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 | |
Jonathan Nieder | 2161da1 | 2011-02-19 23:12:26 -0500 | [diff] [blame] | 14 | test_cmp_rev () { |
| 15 | git rev-parse --verify "$1" >expect.rev && |
| 16 | git rev-parse --verify "$2" >actual.rev && |
| 17 | test_cmp expect.rev actual.rev |
| 18 | } |
| 19 | |
| 20 | pristine_detach () { |
| 21 | git checkout -f "$1^0" && |
| 22 | git read-tree -u --reset HEAD && |
| 23 | git clean -d -f -f -q -x |
| 24 | } |
| 25 | |
Jonathan Nieder | 6a84334 | 2010-03-20 19:28:14 -0500 | [diff] [blame] | 26 | test_expect_success setup ' |
| 27 | |
| 28 | echo unrelated >unrelated && |
| 29 | git add unrelated && |
| 30 | test_commit initial foo a && |
| 31 | test_commit base foo b && |
| 32 | test_commit picked foo c && |
| 33 | git config advice.detachedhead false |
| 34 | |
| 35 | ' |
| 36 | |
| 37 | test_expect_success 'failed cherry-pick does not advance HEAD' ' |
Jonathan Nieder | 2161da1 | 2011-02-19 23:12:26 -0500 | [diff] [blame] | 38 | pristine_detach initial && |
Jonathan Nieder | 6a84334 | 2010-03-20 19:28:14 -0500 | [diff] [blame] | 39 | |
| 40 | head=$(git rev-parse HEAD) && |
| 41 | test_must_fail git cherry-pick picked && |
| 42 | newhead=$(git rev-parse HEAD) && |
| 43 | |
| 44 | test "$head" = "$newhead" |
| 45 | ' |
| 46 | |
Junio C Hamano | fff1bb3 | 2011-04-12 16:23:01 -0700 | [diff] [blame] | 47 | test_expect_success 'advice from failed cherry-pick' " |
Jonathan Nieder | 2161da1 | 2011-02-19 23:12:26 -0500 | [diff] [blame] | 48 | pristine_detach initial && |
Jonathan Nieder | 314eeb6 | 2010-08-11 03:37:51 -0500 | [diff] [blame] | 49 | |
Ævar Arnfjörð Bjarmason | 997b688 | 2010-08-18 14:36:44 +0000 | [diff] [blame] | 50 | picked=\$(git rev-parse --short picked) && |
Jonathan Nieder | 314eeb6 | 2010-08-11 03:37:51 -0500 | [diff] [blame] | 51 | cat <<-EOF >expected && |
Ævar Arnfjörð Bjarmason | 997b688 | 2010-08-18 14:36:44 +0000 | [diff] [blame] | 52 | error: could not apply \$picked... picked |
Jonathan Nieder | 314eeb6 | 2010-08-11 03:37:51 -0500 | [diff] [blame] | 53 | hint: after resolving the conflicts, mark the corrected paths |
| 54 | hint: with 'git add <paths>' or 'git rm <paths>' |
Jay Soffian | 37f7a85 | 2011-02-19 23:12:29 -0500 | [diff] [blame] | 55 | hint: and commit the result with 'git commit' |
Jonathan Nieder | 314eeb6 | 2010-08-11 03:37:51 -0500 | [diff] [blame] | 56 | EOF |
| 57 | test_must_fail git cherry-pick picked 2>actual && |
| 58 | |
Junio C Hamano | fff1bb3 | 2011-04-12 16:23:01 -0700 | [diff] [blame] | 59 | test_i18ncmp expected actual |
Ævar Arnfjörð Bjarmason | 997b688 | 2010-08-18 14:36:44 +0000 | [diff] [blame] | 60 | " |
Jonathan Nieder | 314eeb6 | 2010-08-11 03:37:51 -0500 | [diff] [blame] | 61 | |
Jay Soffian | d7e5c0c | 2011-02-19 23:12:27 -0500 | [diff] [blame] | 62 | test_expect_success 'failed cherry-pick sets CHERRY_PICK_HEAD' ' |
| 63 | pristine_detach initial && |
| 64 | test_must_fail git cherry-pick picked && |
| 65 | test_cmp_rev picked CHERRY_PICK_HEAD |
| 66 | ' |
| 67 | |
| 68 | test_expect_success 'successful cherry-pick does not set CHERRY_PICK_HEAD' ' |
| 69 | pristine_detach initial && |
| 70 | git cherry-pick base && |
| 71 | test_must_fail git rev-parse --verify CHERRY_PICK_HEAD |
| 72 | ' |
| 73 | |
| 74 | test_expect_success 'cherry-pick --no-commit does not set CHERRY_PICK_HEAD' ' |
| 75 | pristine_detach initial && |
| 76 | git cherry-pick --no-commit base && |
| 77 | test_must_fail git rev-parse --verify CHERRY_PICK_HEAD |
| 78 | ' |
| 79 | |
| 80 | test_expect_success 'GIT_CHERRY_PICK_HELP suppresses CHERRY_PICK_HEAD' ' |
| 81 | pristine_detach initial && |
| 82 | ( |
| 83 | GIT_CHERRY_PICK_HELP="and then do something else" && |
| 84 | export GIT_CHERRY_PICK_HELP && |
| 85 | test_must_fail git cherry-pick picked |
| 86 | ) && |
| 87 | test_must_fail git rev-parse --verify CHERRY_PICK_HEAD |
| 88 | ' |
| 89 | |
| 90 | test_expect_success 'git reset clears CHERRY_PICK_HEAD' ' |
| 91 | pristine_detach initial && |
| 92 | |
| 93 | test_must_fail git cherry-pick picked && |
| 94 | git reset && |
| 95 | |
| 96 | test_must_fail git rev-parse --verify CHERRY_PICK_HEAD |
| 97 | ' |
| 98 | |
| 99 | test_expect_success 'failed commit does not clear CHERRY_PICK_HEAD' ' |
| 100 | pristine_detach initial && |
| 101 | |
| 102 | test_must_fail git cherry-pick picked && |
| 103 | test_must_fail git commit && |
| 104 | |
| 105 | test_cmp_rev picked CHERRY_PICK_HEAD |
| 106 | ' |
| 107 | |
| 108 | test_expect_success 'cancelled commit does not clear CHERRY_PICK_HEAD' ' |
| 109 | pristine_detach initial && |
| 110 | |
| 111 | test_must_fail git cherry-pick picked && |
| 112 | echo resolved >foo && |
| 113 | git add foo && |
| 114 | git update-index --refresh -q && |
| 115 | test_must_fail git diff-index --exit-code HEAD && |
| 116 | ( |
| 117 | GIT_EDITOR=false && |
| 118 | export GIT_EDITOR && |
| 119 | test_must_fail git commit |
| 120 | ) && |
| 121 | |
| 122 | test_cmp_rev picked CHERRY_PICK_HEAD |
| 123 | ' |
| 124 | |
| 125 | test_expect_success 'successful commit clears CHERRY_PICK_HEAD' ' |
| 126 | pristine_detach initial && |
| 127 | |
| 128 | test_must_fail git cherry-pick picked && |
| 129 | echo resolved >foo && |
| 130 | git add foo && |
| 131 | git commit && |
| 132 | |
| 133 | test_must_fail git rev-parse --verify CHERRY_PICK_HEAD |
| 134 | ' |
| 135 | |
Jonathan Nieder | 6a84334 | 2010-03-20 19:28:14 -0500 | [diff] [blame] | 136 | test_expect_success 'failed cherry-pick produces dirty index' ' |
Jonathan Nieder | 2161da1 | 2011-02-19 23:12:26 -0500 | [diff] [blame] | 137 | pristine_detach initial && |
Jonathan Nieder | 6a84334 | 2010-03-20 19:28:14 -0500 | [diff] [blame] | 138 | |
| 139 | test_must_fail git cherry-pick picked && |
| 140 | |
| 141 | test_must_fail git update-index --refresh -q && |
| 142 | test_must_fail git diff-index --exit-code HEAD |
| 143 | ' |
| 144 | |
| 145 | test_expect_success 'failed cherry-pick registers participants in index' ' |
Jonathan Nieder | 2161da1 | 2011-02-19 23:12:26 -0500 | [diff] [blame] | 146 | pristine_detach initial && |
Jonathan Nieder | 6a84334 | 2010-03-20 19:28:14 -0500 | [diff] [blame] | 147 | { |
| 148 | git checkout base -- foo && |
| 149 | git ls-files --stage foo && |
| 150 | git checkout initial -- foo && |
| 151 | git ls-files --stage foo && |
| 152 | git checkout picked -- foo && |
| 153 | git ls-files --stage foo |
| 154 | } > stages && |
| 155 | sed " |
| 156 | 1 s/ 0 / 1 / |
| 157 | 2 s/ 0 / 2 / |
| 158 | 3 s/ 0 / 3 / |
| 159 | " < stages > expected && |
Jonathan Nieder | 2161da1 | 2011-02-19 23:12:26 -0500 | [diff] [blame] | 160 | git read-tree -u --reset HEAD && |
Jonathan Nieder | 6a84334 | 2010-03-20 19:28:14 -0500 | [diff] [blame] | 161 | |
| 162 | test_must_fail git cherry-pick picked && |
| 163 | git ls-files --stage --unmerged > actual && |
| 164 | |
| 165 | test_cmp expected actual |
| 166 | ' |
| 167 | |
| 168 | test_expect_success 'failed cherry-pick describes conflict in work tree' ' |
Jonathan Nieder | 2161da1 | 2011-02-19 23:12:26 -0500 | [diff] [blame] | 169 | pristine_detach initial && |
Jonathan Nieder | 6a84334 | 2010-03-20 19:28:14 -0500 | [diff] [blame] | 170 | cat <<-EOF > expected && |
| 171 | <<<<<<< HEAD |
| 172 | a |
| 173 | ======= |
| 174 | c |
| 175 | >>>>>>> objid picked |
| 176 | EOF |
| 177 | |
Jonathan Nieder | 6a84334 | 2010-03-20 19:28:14 -0500 | [diff] [blame] | 178 | test_must_fail git cherry-pick picked && |
| 179 | |
| 180 | sed "s/[a-f0-9]*\.\.\./objid/" foo > actual && |
| 181 | test_cmp expected actual |
| 182 | ' |
| 183 | |
| 184 | test_expect_success 'diff3 -m style' ' |
Jonathan Nieder | 2161da1 | 2011-02-19 23:12:26 -0500 | [diff] [blame] | 185 | pristine_detach initial && |
Jonathan Nieder | 6a84334 | 2010-03-20 19:28:14 -0500 | [diff] [blame] | 186 | git config merge.conflictstyle diff3 && |
Jonathan Nieder | 6a84334 | 2010-03-20 19:28:14 -0500 | [diff] [blame] | 187 | cat <<-EOF > expected && |
| 188 | <<<<<<< HEAD |
| 189 | a |
Jonathan Nieder | bf975d3 | 2010-03-20 19:46:07 -0500 | [diff] [blame] | 190 | ||||||| parent of objid picked |
Jonathan Nieder | 6a84334 | 2010-03-20 19:28:14 -0500 | [diff] [blame] | 191 | b |
| 192 | ======= |
| 193 | c |
| 194 | >>>>>>> objid picked |
| 195 | EOF |
| 196 | |
Jonathan Nieder | 6a84334 | 2010-03-20 19:28:14 -0500 | [diff] [blame] | 197 | test_must_fail git cherry-pick picked && |
| 198 | |
| 199 | sed "s/[a-f0-9]*\.\.\./objid/" foo > actual && |
| 200 | test_cmp expected actual |
| 201 | ' |
| 202 | |
| 203 | test_expect_success 'revert also handles conflicts sanely' ' |
Jonathan Nieder | 6a84334 | 2010-03-20 19:28:14 -0500 | [diff] [blame] | 204 | git config --unset merge.conflictstyle && |
Jonathan Nieder | 2161da1 | 2011-02-19 23:12:26 -0500 | [diff] [blame] | 205 | pristine_detach initial && |
Jonathan Nieder | 6a84334 | 2010-03-20 19:28:14 -0500 | [diff] [blame] | 206 | cat <<-EOF > expected && |
| 207 | <<<<<<< HEAD |
| 208 | a |
| 209 | ======= |
| 210 | b |
Jonathan Nieder | d685654 | 2010-03-20 19:45:21 -0500 | [diff] [blame] | 211 | >>>>>>> parent of objid picked |
Jonathan Nieder | 6a84334 | 2010-03-20 19:28:14 -0500 | [diff] [blame] | 212 | EOF |
| 213 | { |
| 214 | git checkout picked -- foo && |
| 215 | git ls-files --stage foo && |
| 216 | git checkout initial -- foo && |
| 217 | git ls-files --stage foo && |
| 218 | git checkout base -- foo && |
| 219 | git ls-files --stage foo |
| 220 | } > stages && |
| 221 | sed " |
| 222 | 1 s/ 0 / 1 / |
| 223 | 2 s/ 0 / 2 / |
| 224 | 3 s/ 0 / 3 / |
| 225 | " < stages > expected-stages && |
Jonathan Nieder | 2161da1 | 2011-02-19 23:12:26 -0500 | [diff] [blame] | 226 | git read-tree -u --reset HEAD && |
Jonathan Nieder | 6a84334 | 2010-03-20 19:28:14 -0500 | [diff] [blame] | 227 | |
| 228 | head=$(git rev-parse HEAD) && |
| 229 | test_must_fail git revert picked && |
| 230 | newhead=$(git rev-parse HEAD) && |
| 231 | git ls-files --stage --unmerged > actual-stages && |
| 232 | |
| 233 | test "$head" = "$newhead" && |
| 234 | test_must_fail git update-index --refresh -q && |
| 235 | test_must_fail git diff-index --exit-code HEAD && |
| 236 | test_cmp expected-stages actual-stages && |
| 237 | sed "s/[a-f0-9]*\.\.\./objid/" foo > actual && |
| 238 | test_cmp expected actual |
| 239 | ' |
| 240 | |
| 241 | test_expect_success 'revert conflict, diff3 -m style' ' |
Jonathan Nieder | 2161da1 | 2011-02-19 23:12:26 -0500 | [diff] [blame] | 242 | pristine_detach initial && |
Jonathan Nieder | 6a84334 | 2010-03-20 19:28:14 -0500 | [diff] [blame] | 243 | git config merge.conflictstyle diff3 && |
Jonathan Nieder | 6a84334 | 2010-03-20 19:28:14 -0500 | [diff] [blame] | 244 | cat <<-EOF > expected && |
| 245 | <<<<<<< HEAD |
| 246 | a |
Jonathan Nieder | bf975d3 | 2010-03-20 19:46:07 -0500 | [diff] [blame] | 247 | ||||||| objid picked |
Jonathan Nieder | 6a84334 | 2010-03-20 19:28:14 -0500 | [diff] [blame] | 248 | c |
| 249 | ======= |
| 250 | b |
Jonathan Nieder | d685654 | 2010-03-20 19:45:21 -0500 | [diff] [blame] | 251 | >>>>>>> parent of objid picked |
Jonathan Nieder | 6a84334 | 2010-03-20 19:28:14 -0500 | [diff] [blame] | 252 | EOF |
| 253 | |
Jonathan Nieder | 6a84334 | 2010-03-20 19:28:14 -0500 | [diff] [blame] | 254 | test_must_fail git revert picked && |
| 255 | |
| 256 | sed "s/[a-f0-9]*\.\.\./objid/" foo > actual && |
| 257 | test_cmp expected actual |
| 258 | ' |
| 259 | |
| 260 | test_done |