Git 2.32
[git] / t / t3424-rebase-empty.sh
1 #!/bin/sh
2
3 test_description='git rebase of commits that start or become empty'
4
5 . ./test-lib.sh
6
7 test_expect_success 'setup test repository' '
8         test_write_lines 1 2 3 4 5 6 7 8 9 10 >numbers &&
9         test_write_lines A B C D E F G H I J >letters &&
10         git add numbers letters &&
11         git commit -m A &&
12
13         git branch upstream &&
14         git branch localmods &&
15
16         git checkout upstream &&
17         test_write_lines A B C D E >letters &&
18         git add letters &&
19         git commit -m B &&
20
21         test_write_lines 1 2 3 4 five 6 7 8 9 ten >numbers &&
22         git add numbers &&
23         git commit -m C &&
24
25         git checkout localmods &&
26         test_write_lines 1 2 3 4 five 6 7 8 9 10 >numbers &&
27         git add numbers &&
28         git commit -m C2 &&
29
30         git commit --allow-empty -m D &&
31
32         test_write_lines A B C D E >letters &&
33         git add letters &&
34         git commit -m "Five letters ought to be enough for anybody"
35 '
36
37 test_expect_failure 'rebase (apply-backend)' '
38         test_when_finished "git rebase --abort" &&
39         git checkout -B testing localmods &&
40         # rebase (--apply) should not drop commits that start empty
41         git rebase --apply upstream &&
42
43         test_write_lines D C B A >expect &&
44         git log --format=%s >actual &&
45         test_cmp expect actual
46 '
47
48 test_expect_success 'rebase --merge --empty=drop' '
49         git checkout -B testing localmods &&
50         git rebase --merge --empty=drop upstream &&
51
52         test_write_lines D C B A >expect &&
53         git log --format=%s >actual &&
54         test_cmp expect actual
55 '
56
57 test_expect_success 'rebase --merge uses default of --empty=drop' '
58         git checkout -B testing localmods &&
59         git rebase --merge upstream &&
60
61         test_write_lines D C B A >expect &&
62         git log --format=%s >actual &&
63         test_cmp expect actual
64 '
65
66 test_expect_success 'rebase --merge --empty=keep' '
67         git checkout -B testing localmods &&
68         git rebase --merge --empty=keep upstream &&
69
70         test_write_lines D C2 C B A >expect &&
71         git log --format=%s >actual &&
72         test_cmp expect actual
73 '
74
75 test_expect_success 'rebase --merge --empty=ask' '
76         git checkout -B testing localmods &&
77         test_must_fail git rebase --merge --empty=ask upstream &&
78
79         git rebase --skip &&
80
81         test_write_lines D C B A >expect &&
82         git log --format=%s >actual &&
83         test_cmp expect actual
84 '
85
86 test_expect_success 'rebase --interactive --empty=drop' '
87         git checkout -B testing localmods &&
88         git rebase --interactive --empty=drop upstream &&
89
90         test_write_lines D C B A >expect &&
91         git log --format=%s >actual &&
92         test_cmp expect actual
93 '
94
95 test_expect_success 'rebase --interactive --empty=keep' '
96         git checkout -B testing localmods &&
97         git rebase --interactive --empty=keep upstream &&
98
99         test_write_lines D C2 C B A >expect &&
100         git log --format=%s >actual &&
101         test_cmp expect actual
102 '
103
104 test_expect_success 'rebase --interactive --empty=ask' '
105         git checkout -B testing localmods &&
106         test_must_fail git rebase --interactive --empty=ask upstream &&
107
108         git rebase --skip &&
109
110         test_write_lines D C B A >expect &&
111         git log --format=%s >actual &&
112         test_cmp expect actual
113 '
114
115 test_expect_success 'rebase --interactive uses default of --empty=ask' '
116         git checkout -B testing localmods &&
117         test_must_fail git rebase --interactive upstream &&
118
119         git rebase --skip &&
120
121         test_write_lines D C B A >expect &&
122         git log --format=%s >actual &&
123         test_cmp expect actual
124 '
125
126 test_expect_success 'rebase --merge --empty=drop --keep-empty' '
127         git checkout -B testing localmods &&
128         git rebase --merge --empty=drop --keep-empty upstream &&
129
130         test_write_lines D C B A >expect &&
131         git log --format=%s >actual &&
132         test_cmp expect actual
133 '
134
135 test_expect_success 'rebase --merge --empty=drop --no-keep-empty' '
136         git checkout -B testing localmods &&
137         git rebase --merge --empty=drop --no-keep-empty upstream &&
138
139         test_write_lines C B A >expect &&
140         git log --format=%s >actual &&
141         test_cmp expect actual
142 '
143
144 test_expect_success 'rebase --merge --empty=keep --keep-empty' '
145         git checkout -B testing localmods &&
146         git rebase --merge --empty=keep --keep-empty upstream &&
147
148         test_write_lines D C2 C B A >expect &&
149         git log --format=%s >actual &&
150         test_cmp expect actual
151 '
152
153 test_expect_success 'rebase --merge --empty=keep --no-keep-empty' '
154         git checkout -B testing localmods &&
155         git rebase --merge --empty=keep --no-keep-empty upstream &&
156
157         test_write_lines C2 C B A >expect &&
158         git log --format=%s >actual &&
159         test_cmp expect actual
160 '
161
162 test_expect_success 'rebase --merge does not leave state laying around' '
163         git checkout -B testing localmods~2 &&
164         git rebase --merge upstream &&
165
166         test_path_is_missing .git/CHERRY_PICK_HEAD &&
167         test_path_is_missing .git/MERGE_MSG
168 '
169
170 test_done