Merge branch 'jc/finalize-temp-file'
[git] / t / t3420-rebase-autostash.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2013 Ramkumar Ramachandra
4 #
5
6 test_description='git rebase --autostash tests'
7 . ./test-lib.sh
8
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"
34 '
35
36 testrebase() {
37         type=$1
38         dotest=$2
39
40         test_expect_success "rebase$type: dirty worktree, non-conflicting rebase" '
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                 echo dirty >>file3 &&
46                 git rebase$type unrelated-onto-branch &&
47                 grep unrelated file4 &&
48                 grep dirty file3 &&
49                 git checkout feature-branch
50         '
51
52         test_expect_success "rebase$type: dirty index, non-conflicting rebase" '
53                 test_config rebase.autostash true &&
54                 git reset --hard &&
55                 git checkout -b rebased-feature-branch feature-branch &&
56                 test_when_finished git branch -D rebased-feature-branch &&
57                 echo dirty >>file3 &&
58                 git add file3 &&
59                 git rebase$type unrelated-onto-branch &&
60                 grep unrelated file4 &&
61                 grep dirty file3 &&
62                 git checkout feature-branch
63         '
64
65         test_expect_success "rebase$type: conflicting rebase" '
66                 test_config rebase.autostash true &&
67                 git reset --hard &&
68                 git checkout -b rebased-feature-branch feature-branch &&
69                 test_when_finished git branch -D rebased-feature-branch &&
70                 echo dirty >>file3 &&
71                 test_must_fail git rebase$type related-onto-branch &&
72                 test_path_is_file $dotest/autostash &&
73                 ! grep dirty file3 &&
74                 rm -rf $dotest &&
75                 git reset --hard &&
76                 git checkout feature-branch
77         '
78
79         test_expect_success "rebase$type: --continue" '
80                 test_config rebase.autostash true &&
81                 git reset --hard &&
82                 git checkout -b rebased-feature-branch feature-branch &&
83                 test_when_finished git branch -D rebased-feature-branch &&
84                 echo dirty >>file3 &&
85                 test_must_fail git rebase$type related-onto-branch &&
86                 test_path_is_file $dotest/autostash &&
87                 ! grep dirty file3 &&
88                 echo "conflicting-plus-goodbye" >file2 &&
89                 git add file2 &&
90                 git rebase --continue &&
91                 test_path_is_missing $dotest/autostash &&
92                 grep dirty file3 &&
93                 git checkout feature-branch
94         '
95
96         test_expect_success "rebase$type: --skip" '
97                 test_config rebase.autostash true &&
98                 git reset --hard &&
99                 git checkout -b rebased-feature-branch feature-branch &&
100                 test_when_finished git branch -D rebased-feature-branch &&
101                 echo dirty >>file3 &&
102                 test_must_fail git rebase$type related-onto-branch &&
103                 test_path_is_file $dotest/autostash &&
104                 ! grep dirty file3 &&
105                 git rebase --skip &&
106                 test_path_is_missing $dotest/autostash &&
107                 grep dirty file3 &&
108                 git checkout feature-branch
109         '
110
111         test_expect_success "rebase$type: --abort" '
112                 test_config rebase.autostash true &&
113                 git reset --hard &&
114                 git checkout -b rebased-feature-branch feature-branch &&
115                 test_when_finished git branch -D rebased-feature-branch &&
116                 echo dirty >>file3 &&
117                 test_must_fail git rebase$type related-onto-branch &&
118                 test_path_is_file $dotest/autostash &&
119                 ! grep dirty file3 &&
120                 git rebase --abort &&
121                 test_path_is_missing $dotest/autostash &&
122                 grep dirty file3 &&
123                 git checkout feature-branch
124         '
125
126         test_expect_success "rebase$type: non-conflicting rebase, conflicting stash" '
127                 test_config rebase.autostash true &&
128                 git reset --hard &&
129                 git checkout -b rebased-feature-branch feature-branch &&
130                 test_when_finished git branch -D rebased-feature-branch &&
131                 echo dirty >file4 &&
132                 git add file4 &&
133                 git rebase$type unrelated-onto-branch &&
134                 test_path_is_missing $dotest &&
135                 git reset --hard &&
136                 grep unrelated file4 &&
137                 ! grep dirty file4 &&
138                 git checkout feature-branch &&
139                 git stash pop &&
140                 grep dirty file4
141         '
142 }
143
144 test_expect_success "rebase: fast-forward rebase" '
145         test_config rebase.autostash true &&
146         git reset --hard &&
147         git checkout -b behind-feature-branch feature-branch~1 &&
148         test_when_finished git branch -D behind-feature-branch &&
149         echo dirty >>file1 &&
150         git rebase feature-branch &&
151         grep dirty file1 &&
152         git checkout feature-branch
153 '
154
155 test_expect_success "rebase: noop rebase" '
156         test_config rebase.autostash true &&
157         git reset --hard &&
158         git checkout -b same-feature-branch feature-branch &&
159         test_when_finished git branch -D same-feature-branch &&
160         echo dirty >>file1 &&
161         git rebase feature-branch &&
162         grep dirty file1 &&
163         git checkout feature-branch
164 '
165
166 testrebase "" .git/rebase-apply
167 testrebase " --merge" .git/rebase-merge
168 testrebase " --interactive" .git/rebase-merge
169
170 test_expect_success 'abort rebase -i with --autostash' '
171         test_when_finished "git reset --hard" &&
172         echo uncommited-content >file0 &&
173         (
174                 write_script abort-editor.sh <<-\EOF &&
175                         echo >"$1"
176                 EOF
177                 test_set_editor "$(pwd)/abort-editor.sh" &&
178                 test_must_fail git rebase -i --autostash HEAD^ &&
179                 rm -f abort-editor.sh
180         ) &&
181         echo uncommited-content >expected &&
182         test_cmp expected file0
183 '
184
185 test_done