Clean up RelNotes for 2.48
[alt-git.git] / t / t3650-replay-basics.sh
blob12bd3db4cb74635ff1a939c80897e9fb98a208a7
1 #!/bin/sh
3 test_description='basic git replay tests'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 GIT_AUTHOR_NAME=author@name
12 GIT_AUTHOR_EMAIL=bogus@email@address
13 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
15 test_expect_success 'setup' '
16 test_commit A &&
17 test_commit B &&
19 git switch -c topic1 &&
20 test_commit C &&
21 git switch -c topic2 &&
22 test_commit D &&
23 test_commit E &&
24 git switch topic1 &&
25 test_commit F &&
26 git switch -c topic3 &&
27 test_commit G &&
28 test_commit H &&
29 git switch -c topic4 main &&
30 test_commit I &&
31 test_commit J &&
33 git switch -c next main &&
34 test_commit K &&
35 git merge -m "Merge topic1" topic1 &&
36 git merge -m "Merge topic2" topic2 &&
37 git merge -m "Merge topic3" topic3 &&
38 >evil &&
39 git add evil &&
40 git commit --amend &&
41 git merge -m "Merge topic4" topic4 &&
43 git switch main &&
44 test_commit L &&
45 test_commit M &&
47 git switch -c conflict B &&
48 test_commit C.conflict C.t conflict
51 test_expect_success 'setup bare' '
52 git clone --bare . bare
55 test_expect_success 'using replay to rebase two branches, one on top of other' '
56 git replay --onto main topic1..topic2 >result &&
58 test_line_count = 1 result &&
60 git log --format=%s $(cut -f 3 -d " " result) >actual &&
61 test_write_lines E D M L B A >expect &&
62 test_cmp expect actual &&
64 printf "update refs/heads/topic2 " >expect &&
65 printf "%s " $(cut -f 3 -d " " result) >>expect &&
66 git rev-parse topic2 >>expect &&
68 test_cmp expect result
71 test_expect_success 'using replay on bare repo to rebase two branches, one on top of other' '
72 git -C bare replay --onto main topic1..topic2 >result-bare &&
73 test_cmp expect result-bare
76 test_expect_success 'using replay to rebase with a conflict' '
77 test_expect_code 1 git replay --onto topic1 B..conflict
80 test_expect_success 'using replay on bare repo to rebase with a conflict' '
81 test_expect_code 1 git -C bare replay --onto topic1 B..conflict
84 test_expect_success 'using replay to perform basic cherry-pick' '
85 # The differences between this test and previous ones are:
86 # --advance vs --onto
87 # 2nd field of result is refs/heads/main vs. refs/heads/topic2
88 # 4th field of result is hash for main instead of hash for topic2
90 git replay --advance main topic1..topic2 >result &&
92 test_line_count = 1 result &&
94 git log --format=%s $(cut -f 3 -d " " result) >actual &&
95 test_write_lines E D M L B A >expect &&
96 test_cmp expect actual &&
98 printf "update refs/heads/main " >expect &&
99 printf "%s " $(cut -f 3 -d " " result) >>expect &&
100 git rev-parse main >>expect &&
102 test_cmp expect result
105 test_expect_success 'using replay on bare repo to perform basic cherry-pick' '
106 git -C bare replay --advance main topic1..topic2 >result-bare &&
107 test_cmp expect result-bare
110 test_expect_success 'replay on bare repo fails with both --advance and --onto' '
111 test_must_fail git -C bare replay --advance main --onto main topic1..topic2 >result-bare
114 test_expect_success 'replay fails when both --advance and --onto are omitted' '
115 test_must_fail git replay topic1..topic2 >result
118 test_expect_success 'using replay to also rebase a contained branch' '
119 git replay --contained --onto main main..topic3 >result &&
121 test_line_count = 2 result &&
122 cut -f 3 -d " " result >new-branch-tips &&
124 git log --format=%s $(head -n 1 new-branch-tips) >actual &&
125 test_write_lines F C M L B A >expect &&
126 test_cmp expect actual &&
128 git log --format=%s $(tail -n 1 new-branch-tips) >actual &&
129 test_write_lines H G F C M L B A >expect &&
130 test_cmp expect actual &&
132 printf "update refs/heads/topic1 " >expect &&
133 printf "%s " $(head -n 1 new-branch-tips) >>expect &&
134 git rev-parse topic1 >>expect &&
135 printf "update refs/heads/topic3 " >>expect &&
136 printf "%s " $(tail -n 1 new-branch-tips) >>expect &&
137 git rev-parse topic3 >>expect &&
139 test_cmp expect result
142 test_expect_success 'using replay on bare repo to also rebase a contained branch' '
143 git -C bare replay --contained --onto main main..topic3 >result-bare &&
144 test_cmp expect result-bare
147 test_expect_success 'using replay to rebase multiple divergent branches' '
148 git replay --onto main ^topic1 topic2 topic4 >result &&
150 test_line_count = 2 result &&
151 cut -f 3 -d " " result >new-branch-tips &&
153 git log --format=%s $(head -n 1 new-branch-tips) >actual &&
154 test_write_lines E D M L B A >expect &&
155 test_cmp expect actual &&
157 git log --format=%s $(tail -n 1 new-branch-tips) >actual &&
158 test_write_lines J I M L B A >expect &&
159 test_cmp expect actual &&
161 printf "update refs/heads/topic2 " >expect &&
162 printf "%s " $(head -n 1 new-branch-tips) >>expect &&
163 git rev-parse topic2 >>expect &&
164 printf "update refs/heads/topic4 " >>expect &&
165 printf "%s " $(tail -n 1 new-branch-tips) >>expect &&
166 git rev-parse topic4 >>expect &&
168 test_cmp expect result
171 test_expect_success 'using replay on bare repo to rebase multiple divergent branches, including contained ones' '
172 git -C bare replay --contained --onto main ^main topic2 topic3 topic4 >result &&
174 test_line_count = 4 result &&
175 cut -f 3 -d " " result >new-branch-tips &&
177 >expect &&
178 for i in 2 1 3 4
180 printf "update refs/heads/topic$i " >>expect &&
181 printf "%s " $(grep topic$i result | cut -f 3 -d " ") >>expect &&
182 git -C bare rev-parse topic$i >>expect || return 1
183 done &&
185 test_cmp expect result &&
187 test_write_lines F C M L B A >expect1 &&
188 test_write_lines E D C M L B A >expect2 &&
189 test_write_lines H G F C M L B A >expect3 &&
190 test_write_lines J I M L B A >expect4 &&
192 for i in 1 2 3 4
194 git -C bare log --format=%s $(grep topic$i result | cut -f 3 -d " ") >actual &&
195 test_cmp expect$i actual || return 1
196 done
199 test_done