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"
40 test_expect_success
"rebase$type: dirty worktree, --no-autostash" '
41 test_config rebase.autostash true &&
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 &&
47 test_must_fail git rebase$type --no-autostash unrelated-onto-branch
50 test_expect_success
"rebase$type: dirty worktree, non-conflicting rebase" '
51 test_config rebase.autostash true &&
53 git checkout -b rebased-feature-branch feature-branch &&
54 test_when_finished git branch -D rebased-feature-branch &&
56 git rebase$type unrelated-onto-branch &&
57 grep unrelated file4 &&
59 git checkout feature-branch
62 test_expect_success
"rebase$type: dirty index, non-conflicting rebase" '
63 test_config rebase.autostash true &&
65 git checkout -b rebased-feature-branch feature-branch &&
66 test_when_finished git branch -D rebased-feature-branch &&
69 git rebase$type unrelated-onto-branch &&
70 grep unrelated file4 &&
72 git checkout feature-branch
75 test_expect_success
"rebase$type: conflicting rebase" '
76 test_config rebase.autostash true &&
78 git checkout -b rebased-feature-branch feature-branch &&
79 test_when_finished git branch -D rebased-feature-branch &&
81 test_must_fail git rebase$type related-onto-branch &&
82 test_path_is_file $dotest/autostash &&
86 git checkout feature-branch
89 test_expect_success
"rebase$type: --continue" '
90 test_config rebase.autostash true &&
92 git checkout -b rebased-feature-branch feature-branch &&
93 test_when_finished git branch -D rebased-feature-branch &&
95 test_must_fail git rebase$type related-onto-branch &&
96 test_path_is_file $dotest/autostash &&
98 echo "conflicting-plus-goodbye" >file2 &&
100 git rebase --continue &&
101 test_path_is_missing $dotest/autostash &&
103 git checkout feature-branch
106 test_expect_success
"rebase$type: --skip" '
107 test_config rebase.autostash true &&
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 &&
116 test_path_is_missing $dotest/autostash &&
118 git checkout feature-branch
121 test_expect_success
"rebase$type: --abort" '
122 test_config rebase.autostash true &&
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 &&
133 git checkout feature-branch
136 test_expect_success
"rebase$type: non-conflicting rebase, conflicting stash" '
137 test_config rebase.autostash true &&
139 git checkout -b rebased-feature-branch feature-branch &&
140 test_when_finished git branch -D rebased-feature-branch &&
143 git rebase$type unrelated-onto-branch &&
144 test_path_is_missing $dotest &&
146 grep unrelated file4 &&
147 ! grep dirty file4 &&
148 git checkout feature-branch &&
154 test_expect_success
"rebase: fast-forward rebase" '
155 test_config rebase.autostash true &&
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 &&
162 git checkout feature-branch
165 test_expect_success
"rebase: noop rebase" '
166 test_config rebase.autostash true &&
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 &&
173 git checkout feature-branch
176 testrebase
"" .git
/rebase-apply
177 testrebase
" --merge" .git
/rebase-merge
178 testrebase
" --interactive" .git
/rebase-merge
180 test_expect_success
'abort rebase -i with --autostash' '
181 test_when_finished "git reset --hard" &&
182 echo uncommited-content >file0 &&
184 write_script abort-editor.sh <<-\EOF &&
187 test_set_editor "$(pwd)/abort-editor.sh" &&
188 test_must_fail git rebase -i --autostash HEAD^ &&
189 rm -f abort-editor.sh
191 echo uncommited-content >expected &&
192 test_cmp expected file0
195 test_expect_success
'restore autostash on editor failure' '
196 test_when_finished "git reset --hard" &&
197 echo uncommitted-content >file0 &&
199 test_set_editor "false" &&
200 test_must_fail git rebase -i --autostash HEAD^
202 echo uncommitted-content >expected &&
203 test_cmp expected file0
206 test_expect_success
'autostash is saved on editor failure with conflict' '
207 test_when_finished "git reset --hard" &&
208 echo uncommitted-content >file0 &&
210 write_script abort-editor.sh <<-\EOF &&
211 echo conflicting-content >file0
214 test_set_editor "$(pwd)/abort-editor.sh" &&
215 test_must_fail git rebase -i --autostash HEAD^ &&
216 rm -f abort-editor.sh
218 echo conflicting-content >expected &&
219 test_cmp expected file0 &&
220 git checkout file0 &&
222 echo uncommitted-content >expected &&
223 test_cmp expected file0