3 # Copyright (c) 2013 Ramkumar Ramachandra
6 test_description='git rebase --autostash tests'
9 test_expect_success setup '
10 echo hello-world >file0 &&
13 git commit -m "initial commit" &&
14 git checkout -b feature-branch &&
15 echo another-hello >file1 &&
16 echo goodbye >file2 &&
19 git commit -m "second commit" &&
20 echo final-goodbye >file3 &&
23 git commit -m "third commit" &&
24 git checkout -b unrelated-onto-branch master &&
25 echo unrelated >file4 &&
28 git commit -m "unrelated commit" &&
29 git checkout -b related-onto-branch master &&
30 echo conflicting-change >file2 &&
33 git commit -m "related commit"
36 create_expected_success_am () {
38 $(grep "^Created autostash: [0-9a-f][0-9a-f]*\$" actual)
39 HEAD is now at $(git rev-parse --short feature-branch) third commit
40 First, rewinding head to replay your work on top of it...
41 Applying: second commit
42 Applying: third commit
47 create_expected_success_interactive () {
48 q_to_cr >expected <<-EOF
49 $(grep "^Created autostash: [0-9a-f][0-9a-f]*\$" actual)
50 HEAD is now at $(git rev-parse --short feature-branch) third commit
51 Rebasing (1/2)QRebasing (2/2)QApplied autostash.
52 Successfully rebased and updated refs/heads/rebased-feature-branch.
56 create_expected_failure_am () {
58 $(grep "^Created autostash: [0-9a-f][0-9a-f]*\$" actual)
59 HEAD is now at $(git rev-parse --short feature-branch) third commit
60 First, rewinding head to replay your work on top of it...
61 Applying: second commit
62 Applying: third commit
63 Applying autostash resulted in conflicts.
64 Your changes are safe in the stash.
65 You can run "git stash pop" or "git stash drop" at any time.
69 create_expected_failure_interactive () {
70 q_to_cr >expected <<-EOF
71 $(grep "^Created autostash: [0-9a-f][0-9a-f]*\$" actual)
72 HEAD is now at $(git rev-parse --short feature-branch) third commit
73 Rebasing (1/2)QRebasing (2/2)QApplying autostash resulted in conflicts.
74 Your changes are safe in the stash.
75 You can run "git stash pop" or "git stash drop" at any time.
76 Successfully rebased and updated refs/heads/rebased-feature-branch.
84 test_expect_success "rebase$type: dirty worktree, --no-autostash" '
85 test_config rebase.autostash true &&
87 git checkout -b rebased-feature-branch feature-branch &&
88 test_when_finished git branch -D rebased-feature-branch &&
89 test_when_finished git checkout feature-branch &&
91 test_must_fail git rebase$type --no-autostash unrelated-onto-branch
94 test_expect_success "rebase$type: dirty worktree, non-conflicting rebase" '
95 test_config rebase.autostash true &&
97 git checkout -b rebased-feature-branch feature-branch &&
99 git rebase$type unrelated-onto-branch >actual 2>&1 &&
100 grep unrelated file4 &&
102 git checkout feature-branch
105 test_expect_success "rebase$type --autostash: check output" '
106 test_when_finished git branch -D rebased-feature-branch &&
107 suffix=${type#\ --} && suffix=${suffix:-am} &&
108 if test ${suffix} = "merge"; then
111 create_expected_success_$suffix &&
112 test_i18ncmp expected actual
115 test_expect_success "rebase$type: dirty index, non-conflicting rebase" '
116 test_config rebase.autostash true &&
118 git checkout -b rebased-feature-branch feature-branch &&
119 test_when_finished git branch -D rebased-feature-branch &&
120 echo dirty >>file3 &&
122 git rebase$type unrelated-onto-branch &&
123 grep unrelated file4 &&
125 git checkout feature-branch
128 test_expect_success "rebase$type: conflicting rebase" '
129 test_config rebase.autostash true &&
131 git checkout -b rebased-feature-branch feature-branch &&
132 test_when_finished git branch -D rebased-feature-branch &&
133 echo dirty >>file3 &&
134 test_must_fail git rebase$type related-onto-branch &&
135 test_path_is_file $dotest/autostash &&
136 test_path_is_missing file3 &&
139 git checkout feature-branch
142 test_expect_success "rebase$type: --continue" '
143 test_config rebase.autostash true &&
145 git checkout -b rebased-feature-branch feature-branch &&
146 test_when_finished git branch -D rebased-feature-branch &&
147 echo dirty >>file3 &&
148 test_must_fail git rebase$type related-onto-branch &&
149 test_path_is_file $dotest/autostash &&
150 test_path_is_missing file3 &&
151 echo "conflicting-plus-goodbye" >file2 &&
153 git rebase --continue &&
154 test_path_is_missing $dotest/autostash &&
156 git checkout feature-branch
159 test_expect_success "rebase$type: --skip" '
160 test_config rebase.autostash true &&
162 git checkout -b rebased-feature-branch feature-branch &&
163 test_when_finished git branch -D rebased-feature-branch &&
164 echo dirty >>file3 &&
165 test_must_fail git rebase$type related-onto-branch &&
166 test_path_is_file $dotest/autostash &&
167 test_path_is_missing file3 &&
169 test_path_is_missing $dotest/autostash &&
171 git checkout feature-branch
174 test_expect_success "rebase$type: --abort" '
175 test_config rebase.autostash true &&
177 git checkout -b rebased-feature-branch feature-branch &&
178 test_when_finished git branch -D rebased-feature-branch &&
179 echo dirty >>file3 &&
180 test_must_fail git rebase$type related-onto-branch &&
181 test_path_is_file $dotest/autostash &&
182 test_path_is_missing file3 &&
183 git rebase --abort &&
184 test_path_is_missing $dotest/autostash &&
186 git checkout feature-branch
189 test_expect_success "rebase$type: non-conflicting rebase, conflicting stash" '
190 test_config rebase.autostash true &&
192 git checkout -b rebased-feature-branch feature-branch &&
195 git rebase$type unrelated-onto-branch >actual 2>&1 &&
196 test_path_is_missing $dotest &&
198 grep unrelated file4 &&
199 ! grep dirty file4 &&
200 git checkout feature-branch &&
205 test_expect_success "rebase$type: check output with conflicting stash" '
206 test_when_finished git branch -D rebased-feature-branch &&
207 suffix=${type#\ --} && suffix=${suffix:-am} &&
208 if test ${suffix} = "merge"; then
211 create_expected_failure_$suffix &&
212 test_i18ncmp expected actual
216 test_expect_success "rebase: fast-forward rebase" '
217 test_config rebase.autostash true &&
219 git checkout -b behind-feature-branch feature-branch~1 &&
220 test_when_finished git branch -D behind-feature-branch &&
221 echo dirty >>file1 &&
222 git rebase feature-branch &&
224 git checkout feature-branch
227 test_expect_success "rebase: noop rebase" '
228 test_config rebase.autostash true &&
230 git checkout -b same-feature-branch feature-branch &&
231 test_when_finished git branch -D same-feature-branch &&
232 echo dirty >>file1 &&
233 git rebase feature-branch &&
235 git checkout feature-branch
238 testrebase "" .git/rebase-apply
239 testrebase " --merge" .git/rebase-merge
240 testrebase " --interactive" .git/rebase-merge
242 test_expect_success 'abort rebase -i with --autostash' '
243 test_when_finished "git reset --hard" &&
244 echo uncommitted-content >file0 &&
246 write_script abort-editor.sh <<-\EOF &&
249 test_set_editor "$(pwd)/abort-editor.sh" &&
250 test_must_fail git rebase -i --autostash HEAD^ &&
251 rm -f abort-editor.sh
253 echo uncommitted-content >expected &&
254 test_cmp expected file0
257 test_expect_success 'restore autostash on editor failure' '
258 test_when_finished "git reset --hard" &&
259 echo uncommitted-content >file0 &&
261 test_set_editor "false" &&
262 test_must_fail git rebase -i --autostash HEAD^
264 echo uncommitted-content >expected &&
265 test_cmp expected file0
268 test_expect_success 'autostash is saved on editor failure with conflict' '
269 test_when_finished "git reset --hard" &&
270 echo uncommitted-content >file0 &&
272 write_script abort-editor.sh <<-\EOF &&
273 echo conflicting-content >file0
276 test_set_editor "$(pwd)/abort-editor.sh" &&
277 test_must_fail git rebase -i --autostash HEAD^ &&
278 rm -f abort-editor.sh
280 echo conflicting-content >expected &&
281 test_cmp expected file0 &&
282 git checkout file0 &&
284 echo uncommitted-content >expected &&
285 test_cmp expected file0
288 test_expect_success 'autostash with dirty submodules' '
289 test_when_finished "git reset --hard && git checkout master" &&
290 git checkout -b with-submodule &&
291 git submodule add ./ sub &&
293 git commit -m add-submodule &&
294 echo changed >sub/file0 &&
295 git rebase -i --autostash HEAD
298 test_expect_success 'branch is left alone when possible' '
299 git checkout -b unchanged-branch &&
300 echo changed >file0 &&
301 git rebase --autostash unchanged-branch &&
302 test changed = "$(cat file0)" &&
303 test unchanged-branch = "$(git rev-parse --abbrev-ref HEAD)"