]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3650-replay-basics.sh
Sync with Git 2.45.1
[thirdparty/git.git] / t / t3650-replay-basics.sh
CommitLineData
f920b028
EN
1#!/bin/sh
2
3test_description='basic git replay tests'
4
5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8. ./test-lib.sh
9
10GIT_AUTHOR_NAME=author@name
11GIT_AUTHOR_EMAIL=bogus@email@address
12export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
13
14test_expect_success 'setup' '
15 test_commit A &&
16 test_commit B &&
17
18 git switch -c topic1 &&
19 test_commit C &&
20 git switch -c topic2 &&
21 test_commit D &&
22 test_commit E &&
23 git switch topic1 &&
24 test_commit F &&
25 git switch -c topic3 &&
26 test_commit G &&
27 test_commit H &&
28 git switch -c topic4 main &&
29 test_commit I &&
30 test_commit J &&
31
32 git switch -c next main &&
33 test_commit K &&
34 git merge -m "Merge topic1" topic1 &&
35 git merge -m "Merge topic2" topic2 &&
36 git merge -m "Merge topic3" topic3 &&
37 >evil &&
38 git add evil &&
39 git commit --amend &&
40 git merge -m "Merge topic4" topic4 &&
41
42 git switch main &&
43 test_commit L &&
44 test_commit M &&
45
46 git switch -c conflict B &&
47 test_commit C.conflict C.t conflict
48'
49
81613be3
EN
50test_expect_success 'setup bare' '
51 git clone --bare . bare
52'
53
f920b028 54test_expect_success 'using replay to rebase two branches, one on top of other' '
3916ec30 55 git replay --onto main topic1..topic2 >result &&
f920b028 56
81613be3
EN
57 test_line_count = 1 result &&
58
f920b028
EN
59 git log --format=%s $(cut -f 3 -d " " result) >actual &&
60 test_write_lines E D M L B A >expect &&
81613be3
EN
61 test_cmp expect actual &&
62
63 printf "update refs/heads/topic2 " >expect &&
64 printf "%s " $(cut -f 3 -d " " result) >>expect &&
65 git rev-parse topic2 >>expect &&
66
67 test_cmp expect result
68'
69
70test_expect_success 'using replay on bare repo to rebase two branches, one on top of other' '
3916ec30 71 git -C bare replay --onto main topic1..topic2 >result-bare &&
81613be3 72 test_cmp expect result-bare
f920b028
EN
73'
74
3916ec30
EN
75test_expect_success 'using replay to rebase with a conflict' '
76 test_expect_code 1 git replay --onto topic1 B..conflict
77'
78
79test_expect_success 'using replay on bare repo to rebase with a conflict' '
80 test_expect_code 1 git -C bare replay --onto topic1 B..conflict
81'
82
22d99f01
EN
83test_expect_success 'using replay to perform basic cherry-pick' '
84 # The differences between this test and previous ones are:
85 # --advance vs --onto
86 # 2nd field of result is refs/heads/main vs. refs/heads/topic2
87 # 4th field of result is hash for main instead of hash for topic2
88
89 git replay --advance main topic1..topic2 >result &&
90
91 test_line_count = 1 result &&
92
93 git log --format=%s $(cut -f 3 -d " " result) >actual &&
94 test_write_lines E D M L B A >expect &&
95 test_cmp expect actual &&
96
97 printf "update refs/heads/main " >expect &&
98 printf "%s " $(cut -f 3 -d " " result) >>expect &&
99 git rev-parse main >>expect &&
100
101 test_cmp expect result
102'
103
104test_expect_success 'using replay on bare repo to perform basic cherry-pick' '
105 git -C bare replay --advance main topic1..topic2 >result-bare &&
106 test_cmp expect result-bare
107'
108
109test_expect_success 'replay on bare repo fails with both --advance and --onto' '
110 test_must_fail git -C bare replay --advance main --onto main topic1..topic2 >result-bare
111'
112
113test_expect_success 'replay fails when both --advance and --onto are omitted' '
114 test_must_fail git replay topic1..topic2 >result
115'
116
c4611130
EN
117test_expect_success 'using replay to also rebase a contained branch' '
118 git replay --contained --onto main main..topic3 >result &&
119
120 test_line_count = 2 result &&
121 cut -f 3 -d " " result >new-branch-tips &&
122
123 git log --format=%s $(head -n 1 new-branch-tips) >actual &&
124 test_write_lines F C M L B A >expect &&
125 test_cmp expect actual &&
126
127 git log --format=%s $(tail -n 1 new-branch-tips) >actual &&
128 test_write_lines H G F C M L B A >expect &&
129 test_cmp expect actual &&
130
131 printf "update refs/heads/topic1 " >expect &&
132 printf "%s " $(head -n 1 new-branch-tips) >>expect &&
133 git rev-parse topic1 >>expect &&
134 printf "update refs/heads/topic3 " >>expect &&
135 printf "%s " $(tail -n 1 new-branch-tips) >>expect &&
136 git rev-parse topic3 >>expect &&
137
138 test_cmp expect result
139'
140
141test_expect_success 'using replay on bare repo to also rebase a contained branch' '
142 git -C bare replay --contained --onto main main..topic3 >result-bare &&
143 test_cmp expect result-bare
144'
145
e928c11e
EN
146test_expect_success 'using replay to rebase multiple divergent branches' '
147 git replay --onto main ^topic1 topic2 topic4 >result &&
148
149 test_line_count = 2 result &&
150 cut -f 3 -d " " result >new-branch-tips &&
151
152 git log --format=%s $(head -n 1 new-branch-tips) >actual &&
153 test_write_lines E D M L B A >expect &&
154 test_cmp expect actual &&
155
156 git log --format=%s $(tail -n 1 new-branch-tips) >actual &&
157 test_write_lines J I M L B A >expect &&
158 test_cmp expect actual &&
159
160 printf "update refs/heads/topic2 " >expect &&
161 printf "%s " $(head -n 1 new-branch-tips) >>expect &&
162 git rev-parse topic2 >>expect &&
163 printf "update refs/heads/topic4 " >>expect &&
164 printf "%s " $(tail -n 1 new-branch-tips) >>expect &&
165 git rev-parse topic4 >>expect &&
166
167 test_cmp expect result
168'
169
170test_expect_success 'using replay on bare repo to rebase multiple divergent branches, including contained ones' '
171 git -C bare replay --contained --onto main ^main topic2 topic3 topic4 >result &&
172
173 test_line_count = 4 result &&
174 cut -f 3 -d " " result >new-branch-tips &&
175
176 >expect &&
177 for i in 2 1 3 4
178 do
179 printf "update refs/heads/topic$i " >>expect &&
180 printf "%s " $(grep topic$i result | cut -f 3 -d " ") >>expect &&
181 git -C bare rev-parse topic$i >>expect || return 1
182 done &&
183
184 test_cmp expect result &&
185
186 test_write_lines F C M L B A >expect1 &&
187 test_write_lines E D C M L B A >expect2 &&
188 test_write_lines H G F C M L B A >expect3 &&
189 test_write_lines J I M L B A >expect4 &&
190
191 for i in 1 2 3 4
192 do
193 git -C bare log --format=%s $(grep topic$i result | cut -f 3 -d " ") >actual &&
194 test_cmp expect$i actual || return 1
195 done
196'
197
f920b028 198test_done