]> git.ipfire.org Git - thirdparty/git.git/blob - t/t3502-cherry-pick-merge.sh
Merge branch 'jk/redact-h2h3-headers-fix'
[thirdparty/git.git] / t / t3502-cherry-pick-merge.sh
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_PASSES_SANITIZE_LEAK=true
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 &&
32 git checkout main &&
33 git merge side &&
34 git tag c
35
36 '
37
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
47 test_expect_success 'cherry-pick explicit first parent of a non-merge' '
48
49 git reset --hard &&
50 git checkout a^0 &&
51 git cherry-pick -m 1 b &&
52 git diff --exit-code c --
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 &&
60 test_must_fail git cherry-pick c &&
61 git diff --exit-code a --
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 &&
87 test_must_fail git cherry-pick -m 3 c
88
89 '
90
91 test_expect_success 'revert explicit first parent of a non-merge' '
92
93 git reset --hard &&
94 git checkout c^0 &&
95 git revert -m 1 b &&
96 git diff --exit-code a --
97
98 '
99
100 test_expect_success 'revert a merge without -m should fail' '
101
102 git reset --hard &&
103 git checkout c^0 &&
104 test_must_fail git revert c &&
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 &&
114 git diff --exit-code a --
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 &&
123 git diff --exit-code b --
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 &&
131 test_must_fail git revert -m 3 c &&
132 git diff --exit-code c
133
134 '
135
136 test_done