Merge branch 'ps/reftable-stack-tempfile'
[alt-git.git] / t / t3650-replay-basics.sh
blob389670262e458eadb7029251aa44b52be8ae5350
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-lib.sh
10 GIT_AUTHOR_NAME=author@name
11 GIT_AUTHOR_EMAIL=bogus@email@address
12 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
14 test_expect_success 'setup' '
15 test_commit A &&
16 test_commit B &&
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 &&
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 &&
42 git switch main &&
43 test_commit L &&
44 test_commit M &&
46 git switch -c conflict B &&
47 test_commit C.conflict C.t conflict
50 test_expect_success 'setup bare' '
51 git clone --bare . bare
54 test_expect_success 'using replay to rebase two branches, one on top of other' '
55 git replay --onto main topic1..topic2 >result &&
57 test_line_count = 1 result &&
59 git log --format=%s $(cut -f 3 -d " " result) >actual &&
60 test_write_lines E D M L B A >expect &&
61 test_cmp expect actual &&
63 printf "update refs/heads/topic2 " >expect &&
64 printf "%s " $(cut -f 3 -d " " result) >>expect &&
65 git rev-parse topic2 >>expect &&
67 test_cmp expect result
70 test_expect_success 'using replay on bare repo to rebase two branches, one on top of other' '
71 git -C bare replay --onto main topic1..topic2 >result-bare &&
72 test_cmp expect result-bare
75 test_expect_success 'using replay to rebase with a conflict' '
76 test_expect_code 1 git replay --onto topic1 B..conflict
79 test_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
83 test_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
89 git replay --advance main topic1..topic2 >result &&
91 test_line_count = 1 result &&
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 &&
97 printf "update refs/heads/main " >expect &&
98 printf "%s " $(cut -f 3 -d " " result) >>expect &&
99 git rev-parse main >>expect &&
101 test_cmp expect result
104 test_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
109 test_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
113 test_expect_success 'replay fails when both --advance and --onto are omitted' '
114 test_must_fail git replay topic1..topic2 >result
117 test_expect_success 'using replay to also rebase a contained branch' '
118 git replay --contained --onto main main..topic3 >result &&
120 test_line_count = 2 result &&
121 cut -f 3 -d " " result >new-branch-tips &&
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 &&
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 &&
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 &&
138 test_cmp expect result
141 test_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
146 test_expect_success 'using replay to rebase multiple divergent branches' '
147 git replay --onto main ^topic1 topic2 topic4 >result &&
149 test_line_count = 2 result &&
150 cut -f 3 -d " " result >new-branch-tips &&
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 &&
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 &&
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 &&
167 test_cmp expect result
170 test_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 &&
173 test_line_count = 4 result &&
174 cut -f 3 -d " " result >new-branch-tips &&
176 >expect &&
177 for i in 2 1 3 4
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 &&
184 test_cmp expect result &&
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 &&
191 for i in 1 2 3 4
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
198 test_done