Git 2.45
[git/gitster.git] / t / t3502-cherry-pick-merge.sh
blob1b2c0d6aca64e05a85ffd6568be17bb5897a297e
1 #!/bin/sh
3 test_description='cherry picking and reverting a merge
5 b---c
6 / /
7 initial---a
11 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
12 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
14 TEST_PASSES_SANITIZE_LEAK=true
15 . ./test-lib.sh
17 test_expect_success setup '
19 >A &&
20 >B &&
21 git add A B &&
22 git commit -m "Initial" &&
23 git tag initial &&
24 git branch side &&
25 echo new line >A &&
26 git commit -m "add line to A" A &&
27 git tag a &&
28 git checkout side &&
29 echo new line >B &&
30 git commit -m "add line to B" B &&
31 git tag b &&
32 git checkout main &&
33 git merge side &&
34 git tag c
38 test_expect_success 'cherry-pick -m complains of bogus numbers' '
39 # expect 129 here to distinguish between cases where
40 # there was nothing to cherry-pick
41 test_expect_code 129 git cherry-pick -m &&
42 test_expect_code 129 git cherry-pick -m foo b &&
43 test_expect_code 129 git cherry-pick -m -1 b &&
44 test_expect_code 129 git cherry-pick -m 0 b
47 test_expect_success 'cherry-pick explicit first parent of a non-merge' '
49 git reset --hard &&
50 git checkout a^0 &&
51 git cherry-pick -m 1 b &&
52 git diff --exit-code c --
56 test_expect_success 'cherry pick a merge without -m should fail' '
58 git reset --hard &&
59 git checkout a^0 &&
60 test_must_fail git cherry-pick c &&
61 git diff --exit-code a --
65 test_expect_success 'cherry pick a merge (1)' '
67 git reset --hard &&
68 git checkout a^0 &&
69 git cherry-pick -m 1 c &&
70 git diff --exit-code c
74 test_expect_success 'cherry pick a merge (2)' '
76 git reset --hard &&
77 git checkout b^0 &&
78 git cherry-pick -m 2 c &&
79 git diff --exit-code c
83 test_expect_success 'cherry pick a merge relative to nonexistent parent should fail' '
85 git reset --hard &&
86 git checkout b^0 &&
87 test_must_fail git cherry-pick -m 3 c
91 test_expect_success 'revert explicit first parent of a non-merge' '
93 git reset --hard &&
94 git checkout c^0 &&
95 git revert -m 1 b &&
96 git diff --exit-code a --
100 test_expect_success 'revert a merge without -m should fail' '
102 git reset --hard &&
103 git checkout c^0 &&
104 test_must_fail git revert c &&
105 git diff --exit-code c
109 test_expect_success 'revert a merge (1)' '
111 git reset --hard &&
112 git checkout c^0 &&
113 git revert -m 1 c &&
114 git diff --exit-code a --
118 test_expect_success 'revert a merge (2)' '
120 git reset --hard &&
121 git checkout c^0 &&
122 git revert -m 2 c &&
123 git diff --exit-code b --
127 test_expect_success 'revert a merge relative to nonexistent parent should fail' '
129 git reset --hard &&
130 git checkout c^0 &&
131 test_must_fail git revert -m 3 c &&
132 git diff --exit-code c
136 test_done