Merge branch 'bw/transport-protocol-policy'
[git/debian.git] / t / t3420-rebase-autostash.sh
blobab8a63e8d6dc643b28eb0c74ba3f032b7532226f
1 #!/bin/sh
3 # Copyright (c) 2013 Ramkumar Ramachandra
6 test_description='git rebase --autostash tests'
7 . ./test-lib.sh
9 test_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"
36 testrebase() {
37 type=$1
38 dotest=$2
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
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
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
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
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
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
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
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
154 test_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
165 test_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
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 uncommitted-content >file0 &&
184 write_script abort-editor.sh <<-\EOF &&
185 echo >"$1"
187 test_set_editor "$(pwd)/abort-editor.sh" &&
188 test_must_fail git rebase -i --autostash HEAD^ &&
189 rm -f abort-editor.sh
190 ) &&
191 echo uncommitted-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^
201 ) &&
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
212 exit 1
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
226 test_done