| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='cherry picking and reverting a merge |
| 4 | |
| 5 | b---c |
| 6 | / / |
| 7 | initial---a |
| 8 | |
| 9 | ' |
| 10 | |
| 11 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
| 12 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 13 | |
| 14 | . ./test-lib.sh |
| 15 | |
| 16 | test_expect_success setup ' |
| 17 | |
| 18 | >A && |
| 19 | >B && |
| 20 | git add A B && |
| 21 | git commit -m "Initial" && |
| 22 | git tag initial && |
| 23 | git branch side && |
| 24 | echo new line >A && |
| 25 | git commit -m "add line to A" A && |
| 26 | git tag a && |
| 27 | git checkout side && |
| 28 | echo new line >B && |
| 29 | git commit -m "add line to B" B && |
| 30 | git tag b && |
| 31 | git checkout main && |
| 32 | git merge side && |
| 33 | git tag c |
| 34 | |
| 35 | ' |
| 36 | |
| 37 | test_expect_success 'cherry-pick -m complains of bogus numbers' ' |
| 38 | # expect 129 here to distinguish between cases where |
| 39 | # there was nothing to cherry-pick |
| 40 | test_expect_code 129 git cherry-pick -m && |
| 41 | test_expect_code 129 git cherry-pick -m foo b && |
| 42 | test_expect_code 129 git cherry-pick -m -1 b && |
| 43 | test_expect_code 129 git cherry-pick -m 0 b |
| 44 | ' |
| 45 | |
| 46 | test_expect_success 'cherry-pick explicit first parent of a non-merge' ' |
| 47 | |
| 48 | git reset --hard && |
| 49 | git checkout a^0 && |
| 50 | git cherry-pick -m 1 b && |
| 51 | git diff --exit-code c -- |
| 52 | |
| 53 | ' |
| 54 | |
| 55 | test_expect_success 'cherry pick a merge without -m should fail' ' |
| 56 | |
| 57 | git reset --hard && |
| 58 | git checkout a^0 && |
| 59 | test_must_fail git cherry-pick c && |
| 60 | git diff --exit-code a -- |
| 61 | |
| 62 | ' |
| 63 | |
| 64 | test_expect_success 'cherry pick a merge (1)' ' |
| 65 | |
| 66 | git reset --hard && |
| 67 | git checkout a^0 && |
| 68 | git cherry-pick -m 1 c && |
| 69 | git diff --exit-code c |
| 70 | |
| 71 | ' |
| 72 | |
| 73 | test_expect_success 'cherry pick a merge (2)' ' |
| 74 | |
| 75 | git reset --hard && |
| 76 | git checkout b^0 && |
| 77 | git cherry-pick -m 2 c && |
| 78 | git diff --exit-code c |
| 79 | |
| 80 | ' |
| 81 | |
| 82 | test_expect_success 'cherry pick a merge relative to nonexistent parent should fail' ' |
| 83 | |
| 84 | git reset --hard && |
| 85 | git checkout b^0 && |
| 86 | test_must_fail git cherry-pick -m 3 c |
| 87 | |
| 88 | ' |
| 89 | |
| 90 | test_expect_success 'revert explicit first parent of a non-merge' ' |
| 91 | |
| 92 | git reset --hard && |
| 93 | git checkout c^0 && |
| 94 | git revert -m 1 b && |
| 95 | git diff --exit-code a -- |
| 96 | |
| 97 | ' |
| 98 | |
| 99 | test_expect_success 'revert a merge without -m should fail' ' |
| 100 | |
| 101 | git reset --hard && |
| 102 | git checkout c^0 && |
| 103 | test_must_fail git revert c && |
| 104 | git diff --exit-code c |
| 105 | |
| 106 | ' |
| 107 | |
| 108 | test_expect_success 'revert a merge (1)' ' |
| 109 | |
| 110 | git reset --hard && |
| 111 | git checkout c^0 && |
| 112 | git revert -m 1 c && |
| 113 | git diff --exit-code a -- |
| 114 | |
| 115 | ' |
| 116 | |
| 117 | test_expect_success 'revert a merge (2)' ' |
| 118 | |
| 119 | git reset --hard && |
| 120 | git checkout c^0 && |
| 121 | git revert -m 2 c && |
| 122 | git diff --exit-code b -- |
| 123 | |
| 124 | ' |
| 125 | |
| 126 | test_expect_success 'revert a merge relative to nonexistent parent should fail' ' |
| 127 | |
| 128 | git reset --hard && |
| 129 | git checkout c^0 && |
| 130 | test_must_fail git revert -m 3 c && |
| 131 | git diff --exit-code c |
| 132 | |
| 133 | ' |
| 134 | |
| 135 | test_done |