rebase -i: fix numbering in squash message
[git] / t / t3418-rebase-continue.sh
1 #!/bin/sh
2
3 test_description='git rebase --continue tests'
4
5 . ./test-lib.sh
6
7 . "$TEST_DIRECTORY"/lib-rebase.sh
8
9 set_fake_editor
10
11 test_expect_success 'setup' '
12         test_commit "commit-new-file-F1" F1 1 &&
13         test_commit "commit-new-file-F2" F2 2 &&
14
15         git checkout -b topic HEAD^ &&
16         test_commit "commit-new-file-F2-on-topic-branch" F2 22 &&
17
18         git checkout master
19 '
20
21 test_expect_success 'interactive rebase --continue works with touched file' '
22         rm -fr .git/rebase-* &&
23         git reset --hard &&
24         git checkout master &&
25
26         FAKE_LINES="edit 1" git rebase -i HEAD^ &&
27         test-chmtime =-60 F1 &&
28         git rebase --continue
29 '
30
31 test_expect_success 'non-interactive rebase --continue works with touched file' '
32         rm -fr .git/rebase-* &&
33         git reset --hard &&
34         git checkout master &&
35
36         test_must_fail git rebase --onto master master topic &&
37         echo "Resolved" >F2 &&
38         git add F2 &&
39         test-chmtime =-60 F1 &&
40         git rebase --continue
41 '
42
43 test_expect_success 'rebase --continue can not be used with other options' '
44         test_must_fail git rebase -v --continue &&
45         test_must_fail git rebase --continue -v
46 '
47
48 test_expect_success 'rebase --continue remembers merge strategy and options' '
49         rm -fr .git/rebase-* &&
50         git reset --hard commit-new-file-F2-on-topic-branch &&
51         test_commit "commit-new-file-F3-on-topic-branch" F3 32 &&
52         test_when_finished "rm -fr test-bin funny.was.run" &&
53         mkdir test-bin &&
54         cat >test-bin/git-merge-funny <<-EOF &&
55         #!$SHELL_PATH
56         case "\$1" in --opt) ;; *) exit 2 ;; esac
57         shift &&
58         >funny.was.run &&
59         exec git merge-recursive "\$@"
60         EOF
61         chmod +x test-bin/git-merge-funny &&
62         (
63                 PATH=./test-bin:$PATH
64                 test_must_fail git rebase -s funny -Xopt master topic
65         ) &&
66         test -f funny.was.run &&
67         rm funny.was.run &&
68         echo "Resolved" >F2 &&
69         git add F2 &&
70         (
71                 PATH=./test-bin:$PATH
72                 git rebase --continue
73         ) &&
74         test -f funny.was.run
75 '
76
77 test_expect_success 'rebase passes merge strategy options correctly' '
78         rm -fr .git/rebase-* &&
79         git reset --hard commit-new-file-F3-on-topic-branch &&
80         test_commit theirs-to-merge &&
81         git reset --hard HEAD^ &&
82         test_commit some-commit &&
83         test_tick &&
84         git merge --no-ff theirs-to-merge &&
85         FAKE_LINES="1 edit 2 3" git rebase -i -f -p -m \
86                 -s recursive --strategy-option=theirs HEAD~2 &&
87         test_commit force-change &&
88         git rebase --continue
89 '
90
91 test_expect_success '--skip after failed fixup cleans commit message' '
92         test_when_finished "test_might_fail git rebase --abort" &&
93         git checkout -b with-conflicting-fixup &&
94         test_commit wants-fixup &&
95         test_commit "fixup! wants-fixup" wants-fixup.t 1 wants-fixup-1 &&
96         test_commit "fixup! wants-fixup" wants-fixup.t 2 wants-fixup-2 &&
97         test_commit "fixup! wants-fixup" wants-fixup.t 3 wants-fixup-3 &&
98         test_must_fail env FAKE_LINES="1 fixup 2 squash 4" \
99                 git rebase -i HEAD~4 &&
100
101         : now there is a conflict, and comments in the commit message &&
102         git show HEAD >out &&
103         grep "fixup! wants-fixup" out &&
104
105         : skip and continue &&
106         echo "cp \"\$1\" .git/copy.txt" | write_script copy-editor.sh &&
107         (test_set_editor "$PWD/copy-editor.sh" && git rebase --skip) &&
108
109         : the user should not have had to edit the commit message &&
110         test_path_is_missing .git/copy.txt &&
111
112         : now the comments in the commit message should have been cleaned up &&
113         git show HEAD >out &&
114         ! grep "fixup! wants-fixup" out &&
115
116         : now, let us ensure that "squash" is handled correctly &&
117         git reset --hard wants-fixup-3 &&
118         test_must_fail env FAKE_LINES="1 squash 4 squash 2 squash 4" \
119                 git rebase -i HEAD~4 &&
120
121         : the first squash failed, but there are two more in the chain &&
122         (test_set_editor "$PWD/copy-editor.sh" &&
123          test_must_fail git rebase --skip) &&
124
125         : not the final squash, no need to edit the commit message &&
126         test_path_is_missing .git/copy.txt &&
127
128         : The first squash was skipped, therefore: &&
129         git show HEAD >out &&
130         test_i18ngrep "# This is a combination of 2 commits" out &&
131         test_i18ngrep "# This is the commit message #2:" out &&
132
133         (test_set_editor "$PWD/copy-editor.sh" && git rebase --skip) &&
134         git show HEAD >out &&
135         test_i18ngrep ! "# This is a combination" out &&
136
137         : Final squash failed, but there was still a squash &&
138         test_i18ngrep "# This is a combination of 2 commits" .git/copy.txt &&
139         test_i18ngrep "# This is the commit message #2:" .git/copy.txt
140 '
141
142 test_expect_success 'setup rerere database' '
143         rm -fr .git/rebase-* &&
144         git reset --hard commit-new-file-F3-on-topic-branch &&
145         git checkout master &&
146         test_commit "commit-new-file-F3" F3 3 &&
147         test_config rerere.enabled true &&
148         test_must_fail git rebase -m master topic &&
149         echo "Resolved" >F2 &&
150         cp F2 expected-F2 &&
151         git add F2 &&
152         test_must_fail git rebase --continue &&
153         echo "Resolved" >F3 &&
154         cp F3 expected-F3 &&
155         git add F3 &&
156         git rebase --continue &&
157         git reset --hard topic@{1}
158 '
159
160 prepare () {
161         rm -fr .git/rebase-* &&
162         git reset --hard commit-new-file-F3-on-topic-branch &&
163         git checkout master &&
164         test_config rerere.enabled true
165 }
166
167 test_rerere_autoupdate () {
168         action=$1 &&
169         test_expect_success "rebase $action --continue remembers --rerere-autoupdate" '
170                 prepare &&
171                 test_must_fail git rebase $action --rerere-autoupdate master topic &&
172                 test_cmp expected-F2 F2 &&
173                 git diff-files --quiet &&
174                 test_must_fail git rebase --continue &&
175                 test_cmp expected-F3 F3 &&
176                 git diff-files --quiet &&
177                 git rebase --continue
178         '
179
180         test_expect_success "rebase $action --continue honors rerere.autoUpdate" '
181                 prepare &&
182                 test_config rerere.autoupdate true &&
183                 test_must_fail git rebase $action master topic &&
184                 test_cmp expected-F2 F2 &&
185                 git diff-files --quiet &&
186                 test_must_fail git rebase --continue &&
187                 test_cmp expected-F3 F3 &&
188                 git diff-files --quiet &&
189                 git rebase --continue
190         '
191
192         test_expect_success "rebase $action --continue remembers --no-rerere-autoupdate" '
193                 prepare &&
194                 test_config rerere.autoupdate true &&
195                 test_must_fail git rebase $action --no-rerere-autoupdate master topic &&
196                 test_cmp expected-F2 F2 &&
197                 test_must_fail git diff-files --quiet &&
198                 git add F2 &&
199                 test_must_fail git rebase --continue &&
200                 test_cmp expected-F3 F3 &&
201                 test_must_fail git diff-files --quiet &&
202                 git add F3 &&
203                 git rebase --continue
204         '
205 }
206
207 test_rerere_autoupdate
208 test_rerere_autoupdate -m
209 GIT_SEQUENCE_EDITOR=: && export GIT_SEQUENCE_EDITOR
210 test_rerere_autoupdate -i
211 test_rerere_autoupdate --preserve-merges
212
213 test_done