pack-objects: simplify --filter handling
[git/debian.git] / t / t3502-cherry-pick-merge.sh
blob5495eacfec11a904ba24d69439cb1b98b5a353ec
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-lib.sh
16 test_expect_success setup '
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
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
46 test_expect_success 'cherry-pick explicit first parent of a non-merge' '
48 git reset --hard &&
49 git checkout a^0 &&
50 git cherry-pick -m 1 b &&
51 git diff --exit-code c --
55 test_expect_success 'cherry pick a merge without -m should fail' '
57 git reset --hard &&
58 git checkout a^0 &&
59 test_must_fail git cherry-pick c &&
60 git diff --exit-code a --
64 test_expect_success 'cherry pick a merge (1)' '
66 git reset --hard &&
67 git checkout a^0 &&
68 git cherry-pick -m 1 c &&
69 git diff --exit-code c
73 test_expect_success 'cherry pick a merge (2)' '
75 git reset --hard &&
76 git checkout b^0 &&
77 git cherry-pick -m 2 c &&
78 git diff --exit-code c
82 test_expect_success 'cherry pick a merge relative to nonexistent parent should fail' '
84 git reset --hard &&
85 git checkout b^0 &&
86 test_must_fail git cherry-pick -m 3 c
90 test_expect_success 'revert explicit first parent of a non-merge' '
92 git reset --hard &&
93 git checkout c^0 &&
94 git revert -m 1 b &&
95 git diff --exit-code a --
99 test_expect_success 'revert a merge without -m should fail' '
101 git reset --hard &&
102 git checkout c^0 &&
103 test_must_fail git revert c &&
104 git diff --exit-code c
108 test_expect_success 'revert a merge (1)' '
110 git reset --hard &&
111 git checkout c^0 &&
112 git revert -m 1 c &&
113 git diff --exit-code a --
117 test_expect_success 'revert a merge (2)' '
119 git reset --hard &&
120 git checkout c^0 &&
121 git revert -m 2 c &&
122 git diff --exit-code b --
126 test_expect_success 'revert a merge relative to nonexistent parent should fail' '
128 git reset --hard &&
129 git checkout c^0 &&
130 test_must_fail git revert -m 3 c &&
131 git diff --exit-code c
135 test_done