rebase -i: add test for reflog message
[git/git.git] / t / t3420-rebase-autostash.sh
CommitLineData
58794775
RR
1#!/bin/sh
2#
3# Copyright (c) 2013 Ramkumar Ramachandra
4#
5
6test_description='git rebase --autostash tests'
7. ./test-lib.sh
8
9test_expect_success setup '
10 echo hello-world >file0 &&
11 git add . &&
12 test_tick &&
13 git commit -m "initial commit" &&
14 git checkout -b feature-branch &&
15 echo another-hello >file1 &&
16 echo goodbye >file2 &&
17 git add . &&
18 test_tick &&
19 git commit -m "second commit" &&
20 echo final-goodbye >file3 &&
21 git add . &&
22 test_tick &&
23 git commit -m "third commit" &&
24 git checkout -b unrelated-onto-branch master &&
25 echo unrelated >file4 &&
26 git add . &&
27 test_tick &&
28 git commit -m "unrelated commit" &&
29 git checkout -b related-onto-branch master &&
30 echo conflicting-change >file2 &&
31 git add . &&
32 test_tick &&
33 git commit -m "related commit"
34'
35
36testrebase() {
37 type=$1
38 dotest=$2
39
619e3604
JK
40 test_expect_success "rebase$type: dirty worktree, --no-autostash" '
41 test_config rebase.autostash true &&
42 git reset --hard &&
43 git checkout -b rebased-feature-branch feature-branch &&
44 test_when_finished git branch -D rebased-feature-branch &&
45 test_when_finished git checkout feature-branch &&
46 echo dirty >>file3 &&
47 test_must_fail git rebase$type --no-autostash unrelated-onto-branch
48 '
49
58794775
RR
50 test_expect_success "rebase$type: dirty worktree, non-conflicting rebase" '
51 test_config rebase.autostash true &&
52 git reset --hard &&
53 git checkout -b rebased-feature-branch feature-branch &&
54 test_when_finished git branch -D rebased-feature-branch &&
55 echo dirty >>file3 &&
56 git rebase$type unrelated-onto-branch &&
57 grep unrelated file4 &&
58 grep dirty file3 &&
59 git checkout feature-branch
60 '
61
62 test_expect_success "rebase$type: dirty index, non-conflicting rebase" '
63 test_config rebase.autostash true &&
64 git reset --hard &&
65 git checkout -b rebased-feature-branch feature-branch &&
66 test_when_finished git branch -D rebased-feature-branch &&
67 echo dirty >>file3 &&
68 git add file3 &&
69 git rebase$type unrelated-onto-branch &&
70 grep unrelated file4 &&
71 grep dirty file3 &&
72 git checkout feature-branch
73 '
74
75 test_expect_success "rebase$type: conflicting rebase" '
76 test_config rebase.autostash true &&
77 git reset --hard &&
78 git checkout -b rebased-feature-branch feature-branch &&
79 test_when_finished git branch -D rebased-feature-branch &&
80 echo dirty >>file3 &&
81 test_must_fail git rebase$type related-onto-branch &&
82 test_path_is_file $dotest/autostash &&
83 ! grep dirty file3 &&
84 rm -rf $dotest &&
85 git reset --hard &&
86 git checkout feature-branch
87 '
88
89 test_expect_success "rebase$type: --continue" '
90 test_config rebase.autostash true &&
91 git reset --hard &&
92 git checkout -b rebased-feature-branch feature-branch &&
93 test_when_finished git branch -D rebased-feature-branch &&
94 echo dirty >>file3 &&
95 test_must_fail git rebase$type related-onto-branch &&
96 test_path_is_file $dotest/autostash &&
97 ! grep dirty file3 &&
98 echo "conflicting-plus-goodbye" >file2 &&
99 git add file2 &&
100 git rebase --continue &&
101 test_path_is_missing $dotest/autostash &&
102 grep dirty file3 &&
103 git checkout feature-branch
104 '
105
106 test_expect_success "rebase$type: --skip" '
107 test_config rebase.autostash true &&
108 git reset --hard &&
109 git checkout -b rebased-feature-branch feature-branch &&
110 test_when_finished git branch -D rebased-feature-branch &&
111 echo dirty >>file3 &&
112 test_must_fail git rebase$type related-onto-branch &&
113 test_path_is_file $dotest/autostash &&
114 ! grep dirty file3 &&
115 git rebase --skip &&
116 test_path_is_missing $dotest/autostash &&
117 grep dirty file3 &&
118 git checkout feature-branch
119 '
120
121 test_expect_success "rebase$type: --abort" '
122 test_config rebase.autostash true &&
123 git reset --hard &&
124 git checkout -b rebased-feature-branch feature-branch &&
125 test_when_finished git branch -D rebased-feature-branch &&
126 echo dirty >>file3 &&
127 test_must_fail git rebase$type related-onto-branch &&
128 test_path_is_file $dotest/autostash &&
129 ! grep dirty file3 &&
130 git rebase --abort &&
131 test_path_is_missing $dotest/autostash &&
132 grep dirty file3 &&
133 git checkout feature-branch
134 '
135
136 test_expect_success "rebase$type: non-conflicting rebase, conflicting stash" '
137 test_config rebase.autostash true &&
138 git reset --hard &&
139 git checkout -b rebased-feature-branch feature-branch &&
140 test_when_finished git branch -D rebased-feature-branch &&
141 echo dirty >file4 &&
142 git add file4 &&
143 git rebase$type unrelated-onto-branch &&
144 test_path_is_missing $dotest &&
145 git reset --hard &&
146 grep unrelated file4 &&
147 ! grep dirty file4 &&
148 git checkout feature-branch &&
149 git stash pop &&
150 grep dirty file4
151 '
152}
153
af2f0ebc
RR
154test_expect_success "rebase: fast-forward rebase" '
155 test_config rebase.autostash true &&
156 git reset --hard &&
157 git checkout -b behind-feature-branch feature-branch~1 &&
158 test_when_finished git branch -D behind-feature-branch &&
159 echo dirty >>file1 &&
160 git rebase feature-branch &&
161 grep dirty file1 &&
162 git checkout feature-branch
163'
164
96e2b99e
RR
165test_expect_success "rebase: noop rebase" '
166 test_config rebase.autostash true &&
167 git reset --hard &&
168 git checkout -b same-feature-branch feature-branch &&
169 test_when_finished git branch -D same-feature-branch &&
170 echo dirty >>file1 &&
171 git rebase feature-branch &&
172 grep dirty file1 &&
173 git checkout feature-branch
174'
175
58794775
RR
176testrebase "" .git/rebase-apply
177testrebase " --merge" .git/rebase-merge
178testrebase " --interactive" .git/rebase-merge
179
ddb5432d
MM
180test_expect_success 'abort rebase -i with --autostash' '
181 test_when_finished "git reset --hard" &&
2e3a16b2 182 echo uncommitted-content >file0 &&
ddb5432d
MM
183 (
184 write_script abort-editor.sh <<-\EOF &&
185 echo >"$1"
186 EOF
187 test_set_editor "$(pwd)/abort-editor.sh" &&
188 test_must_fail git rebase -i --autostash HEAD^ &&
189 rm -f abort-editor.sh
190 ) &&
2e3a16b2 191 echo uncommitted-content >expected &&
ddb5432d
MM
192 test_cmp expected file0
193'
194
33ba9c64
PS
195test_expect_success 'restore autostash on editor failure' '
196 test_when_finished "git reset --hard" &&
197 echo uncommitted-content >file0 &&
198 (
199 test_set_editor "false" &&
200 test_must_fail git rebase -i --autostash HEAD^
201 ) &&
202 echo uncommitted-content >expected &&
203 test_cmp expected file0
204'
205
206test_expect_success 'autostash is saved on editor failure with conflict' '
207 test_when_finished "git reset --hard" &&
208 echo uncommitted-content >file0 &&
209 (
210 write_script abort-editor.sh <<-\EOF &&
211 echo conflicting-content >file0
212 exit 1
213 EOF
214 test_set_editor "$(pwd)/abort-editor.sh" &&
215 test_must_fail git rebase -i --autostash HEAD^ &&
216 rm -f abort-editor.sh
217 ) &&
218 echo conflicting-content >expected &&
219 test_cmp expected file0 &&
220 git checkout file0 &&
221 git stash pop &&
222 echo uncommitted-content >expected &&
223 test_cmp expected file0
224'
225
58794775 226test_done