]>
Commit | Line | Data |
---|---|---|
6232b343 JH |
1 | #!/bin/sh |
2 | ||
3 | test_description='cherry picking and reverting a merge | |
4 | ||
5 | b---c | |
6 | / / | |
7 | initial---a | |
8 | ||
9 | ' | |
10 | ||
cbc75a12 | 11 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
12 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
13 | ||
9ff2f060 | 14 | TEST_PASSES_SANITIZE_LEAK=true |
6232b343 JH |
15 | . ./test-lib.sh |
16 | ||
17 | test_expect_success setup ' | |
18 | ||
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 && | |
cbc75a12 | 32 | git checkout main && |
6232b343 JH |
33 | git merge side && |
34 | git tag c | |
35 | ||
36 | ' | |
37 | ||
b16a991c JK |
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 | |
45 | ' | |
46 | ||
4d67b4e4 | 47 | test_expect_success 'cherry-pick explicit first parent of a non-merge' ' |
6232b343 JH |
48 | |
49 | git reset --hard && | |
50 | git checkout a^0 && | |
4d67b4e4 SO |
51 | git cherry-pick -m 1 b && |
52 | git diff --exit-code c -- | |
6232b343 JH |
53 | |
54 | ' | |
55 | ||
56 | test_expect_success 'cherry pick a merge without -m should fail' ' | |
57 | ||
58 | git reset --hard && | |
59 | git checkout a^0 && | |
d492b31c | 60 | test_must_fail git cherry-pick c && |
9f12bec4 | 61 | git diff --exit-code a -- |
6232b343 JH |
62 | |
63 | ' | |
64 | ||
65 | test_expect_success 'cherry pick a merge (1)' ' | |
66 | ||
67 | git reset --hard && | |
68 | git checkout a^0 && | |
69 | git cherry-pick -m 1 c && | |
70 | git diff --exit-code c | |
71 | ||
72 | ' | |
73 | ||
74 | test_expect_success 'cherry pick a merge (2)' ' | |
75 | ||
76 | git reset --hard && | |
77 | git checkout b^0 && | |
78 | git cherry-pick -m 2 c && | |
79 | git diff --exit-code c | |
80 | ||
81 | ' | |
82 | ||
83 | test_expect_success 'cherry pick a merge relative to nonexistent parent should fail' ' | |
84 | ||
85 | git reset --hard && | |
86 | git checkout b^0 && | |
d492b31c | 87 | test_must_fail git cherry-pick -m 3 c |
6232b343 JH |
88 | |
89 | ' | |
90 | ||
4d67b4e4 | 91 | test_expect_success 'revert explicit first parent of a non-merge' ' |
6232b343 JH |
92 | |
93 | git reset --hard && | |
94 | git checkout c^0 && | |
4d67b4e4 SO |
95 | git revert -m 1 b && |
96 | git diff --exit-code a -- | |
6232b343 JH |
97 | |
98 | ' | |
99 | ||
100 | test_expect_success 'revert a merge without -m should fail' ' | |
101 | ||
102 | git reset --hard && | |
103 | git checkout c^0 && | |
d492b31c | 104 | test_must_fail git revert c && |
6232b343 JH |
105 | git diff --exit-code c |
106 | ||
107 | ' | |
108 | ||
109 | test_expect_success 'revert a merge (1)' ' | |
110 | ||
111 | git reset --hard && | |
112 | git checkout c^0 && | |
113 | git revert -m 1 c && | |
9f12bec4 | 114 | git diff --exit-code a -- |
6232b343 JH |
115 | |
116 | ' | |
117 | ||
118 | test_expect_success 'revert a merge (2)' ' | |
119 | ||
120 | git reset --hard && | |
121 | git checkout c^0 && | |
122 | git revert -m 2 c && | |
9f12bec4 | 123 | git diff --exit-code b -- |
6232b343 JH |
124 | |
125 | ' | |
126 | ||
127 | test_expect_success 'revert a merge relative to nonexistent parent should fail' ' | |
128 | ||
129 | git reset --hard && | |
130 | git checkout c^0 && | |
d492b31c | 131 | test_must_fail git revert -m 3 c && |
6232b343 JH |
132 | git diff --exit-code c |
133 | ||
134 | ' | |
135 | ||
136 | test_done |