Merge branch 'mg/status-in-progress-info' into pu
[git] / t / t7512-status-help.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2012 Valentin Duperray, Lucien Kong, Franck Jonas,
4 #                    Thomas Nguy, Khoi Nguyen
5 #                    Grenoble INP Ensimag
6 #
7
8 test_description='git status advice'
9
10 . ./test-lib.sh
11
12 . "$TEST_DIRECTORY"/lib-rebase.sh
13
14 set_fake_editor
15
16 test_expect_success 'prepare for conflicts' '
17         git config --global advice.statusuoption false &&
18         test_commit init main.txt init &&
19         git branch conflicts &&
20         test_commit on_master main.txt on_master &&
21         git checkout conflicts &&
22         test_commit on_conflicts main.txt on_conflicts
23 '
24
25
26 test_expect_success 'status when conflicts unresolved' '
27         test_must_fail git merge master &&
28         cat >expected <<\EOF &&
29 On branch conflicts
30 You have unmerged paths.
31   (fix conflicts and run "git commit")
32   (use "git merge --abort" to abort the merge)
33
34 Unmerged paths:
35   (use "git add <file>..." to mark resolution)
36
37         both modified:   main.txt
38
39 no changes added to commit (use "git add" and/or "git commit -a")
40 EOF
41         git status --untracked-files=no >actual &&
42         test_i18ncmp expected actual
43 '
44
45
46 test_expect_success 'status when conflicts resolved before commit' '
47         git reset --hard conflicts &&
48         test_must_fail git merge master &&
49         echo one >main.txt &&
50         git add main.txt &&
51         cat >expected <<\EOF &&
52 On branch conflicts
53 All conflicts fixed but you are still merging.
54   (use "git commit" to conclude merge)
55
56 Changes to be committed:
57
58         modified:   main.txt
59
60 Untracked files not listed (use -u option to show untracked files)
61 EOF
62         git status --untracked-files=no >actual &&
63         test_i18ncmp expected actual
64 '
65
66
67 test_expect_success 'prepare for rebase conflicts' '
68         git reset --hard master &&
69         git checkout -b rebase_conflicts &&
70         test_commit one_rebase main.txt one &&
71         test_commit two_rebase main.txt two &&
72         test_commit three_rebase main.txt three
73 '
74
75
76 test_expect_success 'status when rebase in progress before resolving conflicts' '
77         ONTO=$(git rev-parse --short HEAD^^) &&
78         test_must_fail git rebase HEAD^ --onto HEAD^^ &&
79         cat >expected <<EOF &&
80 rebase in progress; onto $ONTO
81 You are currently rebasing branch '\''rebase_conflicts'\'' on '\''$ONTO'\''.
82   (fix conflicts and then run "git rebase --continue")
83   (use "git rebase --skip" to skip this patch)
84   (use "git rebase --abort" to check out the original branch)
85
86 Unmerged paths:
87   (use "git reset HEAD <file>..." to unstage)
88   (use "git add <file>..." to mark resolution)
89
90         both modified:   main.txt
91
92 no changes added to commit (use "git add" and/or "git commit -a")
93 EOF
94         git status --untracked-files=no >actual &&
95         test_i18ncmp expected actual
96 '
97
98 test_expect_success 'short status when rebase in progress' '
99         test_when_finished "git rebase --abort" &&
100         cat >expected <<EOF &&
101 ## HEAD (no branch); REBASE-m
102 UU main.txt
103 EOF
104         git status --untracked-files=no --short --branch --in-progress >actual &&
105         test_i18ncmp expected actual
106 '
107
108 test_expect_success 'status when rebase in progress before rebase --continue' '
109         git reset --hard rebase_conflicts &&
110         test_when_finished "git rebase --abort" &&
111         ONTO=$(git rev-parse --short HEAD^^) &&
112         test_must_fail git rebase HEAD^ --onto HEAD^^ &&
113         echo three >main.txt &&
114         git add main.txt &&
115         cat >expected <<EOF &&
116 rebase in progress; onto $ONTO
117 You are currently rebasing branch '\''rebase_conflicts'\'' on '\''$ONTO'\''.
118   (all conflicts fixed: run "git rebase --continue")
119
120 Changes to be committed:
121   (use "git reset HEAD <file>..." to unstage)
122
123         modified:   main.txt
124
125 Untracked files not listed (use -u option to show untracked files)
126 EOF
127         git status --untracked-files=no >actual &&
128         test_i18ncmp expected actual
129 '
130
131
132 test_expect_success 'prepare for rebase_i_conflicts' '
133         git reset --hard master &&
134         git checkout -b rebase_i_conflicts &&
135         test_commit one_unmerge main.txt one_unmerge &&
136         git branch rebase_i_conflicts_second &&
137         test_commit one_master main.txt one_master &&
138         git checkout rebase_i_conflicts_second &&
139         test_commit one_second main.txt one_second
140 '
141
142
143 test_expect_success 'status during rebase -i when conflicts unresolved' '
144         ONTO=$(git rev-parse --short rebase_i_conflicts) &&
145         LAST_COMMIT=$(git rev-parse --short rebase_i_conflicts_second) &&
146         test_must_fail git rebase -i rebase_i_conflicts &&
147         cat >expected <<EOF &&
148 interactive rebase in progress; onto $ONTO
149 Last command done (1 command done):
150    pick $LAST_COMMIT one_second
151 No commands remaining.
152 You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
153   (fix conflicts and then run "git rebase --continue")
154   (use "git rebase --skip" to skip this patch)
155   (use "git rebase --abort" to check out the original branch)
156
157 Unmerged paths:
158   (use "git reset HEAD <file>..." to unstage)
159   (use "git add <file>..." to mark resolution)
160
161         both modified:   main.txt
162
163 no changes added to commit (use "git add" and/or "git commit -a")
164 EOF
165         git status --untracked-files=no >actual &&
166         test_i18ncmp expected actual
167 '
168
169 test_expect_success 'short status during rebase -i when conflicts unresolved' '
170         test_when_finished "git rebase --abort" &&
171         cat >expected <<EOF &&
172 ## HEAD (no branch); REBASE-i
173 UU main.txt
174 EOF
175         git status --untracked-files=no --short --branch --in-progress >actual &&
176         test_i18ncmp expected actual
177 '
178
179
180 test_expect_success 'status during rebase -i after resolving conflicts' '
181         git reset --hard rebase_i_conflicts_second &&
182         test_when_finished "git rebase --abort" &&
183         ONTO=$(git rev-parse --short rebase_i_conflicts) &&
184         LAST_COMMIT=$(git rev-parse --short rebase_i_conflicts_second) &&
185         test_must_fail git rebase -i rebase_i_conflicts &&
186         git add main.txt &&
187         cat >expected <<EOF &&
188 interactive rebase in progress; onto $ONTO
189 Last command done (1 command done):
190    pick $LAST_COMMIT one_second
191 No commands remaining.
192 You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
193   (all conflicts fixed: run "git rebase --continue")
194
195 Changes to be committed:
196   (use "git reset HEAD <file>..." to unstage)
197
198         modified:   main.txt
199
200 Untracked files not listed (use -u option to show untracked files)
201 EOF
202         git status --untracked-files=no >actual &&
203         test_i18ncmp expected actual
204 '
205
206
207 test_expect_success 'status when rebasing -i in edit mode' '
208         git reset --hard master &&
209         git checkout -b rebase_i_edit &&
210         test_commit one_rebase_i main.txt one &&
211         test_commit two_rebase_i main.txt two &&
212         COMMIT2=$(git rev-parse --short rebase_i_edit) &&
213         test_commit three_rebase_i main.txt three &&
214         COMMIT3=$(git rev-parse --short rebase_i_edit) &&
215         FAKE_LINES="1 edit 2" &&
216         export FAKE_LINES &&
217         test_when_finished "git rebase --abort" &&
218         ONTO=$(git rev-parse --short HEAD~2) &&
219         git rebase -i HEAD~2 &&
220         cat >expected <<EOF &&
221 interactive rebase in progress; onto $ONTO
222 Last commands done (2 commands done):
223    pick $COMMIT2 two_rebase_i
224    edit $COMMIT3 three_rebase_i
225 No commands remaining.
226 You are currently editing a commit while rebasing branch '\''rebase_i_edit'\'' on '\''$ONTO'\''.
227   (use "git commit --amend" to amend the current commit)
228   (use "git rebase --continue" once you are satisfied with your changes)
229
230 nothing to commit (use -u to show untracked files)
231 EOF
232         git status --untracked-files=no >actual &&
233         test_i18ncmp expected actual
234 '
235
236
237 test_expect_success 'status when splitting a commit' '
238         git reset --hard master &&
239         git checkout -b split_commit &&
240         test_commit one_split main.txt one &&
241         test_commit two_split main.txt two &&
242         COMMIT2=$(git rev-parse --short split_commit) &&
243         test_commit three_split main.txt three &&
244         COMMIT3=$(git rev-parse --short split_commit) &&
245         test_commit four_split main.txt four &&
246         COMMIT4=$(git rev-parse --short split_commit) &&
247         FAKE_LINES="1 edit 2 3" &&
248         export FAKE_LINES &&
249         test_when_finished "git rebase --abort" &&
250         ONTO=$(git rev-parse --short HEAD~3) &&
251         git rebase -i HEAD~3 &&
252         git reset HEAD^ &&
253         cat >expected <<EOF &&
254 interactive rebase in progress; onto $ONTO
255 Last commands done (2 commands done):
256    pick $COMMIT2 two_split
257    edit $COMMIT3 three_split
258 Next command to do (1 remaining command):
259    pick $COMMIT4 four_split
260   (use "git rebase --edit-todo" to view and edit)
261 You are currently splitting a commit while rebasing branch '\''split_commit'\'' on '\''$ONTO'\''.
262   (Once your working directory is clean, run "git rebase --continue")
263
264 Changes not staged for commit:
265   (use "git add <file>..." to update what will be committed)
266   (use "git checkout -- <file>..." to discard changes in working directory)
267
268         modified:   main.txt
269
270 no changes added to commit (use "git add" and/or "git commit -a")
271 EOF
272         git status --untracked-files=no >actual &&
273         test_i18ncmp expected actual
274 '
275
276
277 test_expect_success 'status after editing the last commit with --amend during a rebase -i' '
278         git reset --hard master &&
279         git checkout -b amend_last &&
280         test_commit one_amend main.txt one &&
281         test_commit two_amend main.txt two &&
282         test_commit three_amend main.txt three &&
283         COMMIT3=$(git rev-parse --short amend_last) &&
284         test_commit four_amend main.txt four &&
285         COMMIT4=$(git rev-parse --short amend_last) &&
286         FAKE_LINES="1 2 edit 3" &&
287         export FAKE_LINES &&
288         test_when_finished "git rebase --abort" &&
289         ONTO=$(git rev-parse --short HEAD~3) &&
290         git rebase -i HEAD~3 &&
291         git commit --amend -m "foo" &&
292         cat >expected <<EOF &&
293 interactive rebase in progress; onto $ONTO
294 Last commands done (3 commands done):
295    pick $COMMIT3 three_amend
296    edit $COMMIT4 four_amend
297   (see more in file .git/rebase-merge/done)
298 No commands remaining.
299 You are currently editing a commit while rebasing branch '\''amend_last'\'' on '\''$ONTO'\''.
300   (use "git commit --amend" to amend the current commit)
301   (use "git rebase --continue" once you are satisfied with your changes)
302
303 nothing to commit (use -u to show untracked files)
304 EOF
305         git status --untracked-files=no >actual &&
306         test_i18ncmp expected actual
307 '
308
309
310 test_expect_success 'prepare for several edits' '
311         git reset --hard master &&
312         git checkout -b several_edits &&
313         test_commit one_edits main.txt one &&
314         test_commit two_edits main.txt two &&
315         test_commit three_edits main.txt three &&
316         test_commit four_edits main.txt four
317 '
318
319
320 test_expect_success 'status: (continue first edit) second edit' '
321         FAKE_LINES="edit 1 edit 2 3" &&
322         export FAKE_LINES &&
323         test_when_finished "git rebase --abort" &&
324         COMMIT2=$(git rev-parse --short several_edits^^) &&
325         COMMIT3=$(git rev-parse --short several_edits^) &&
326         COMMIT4=$(git rev-parse --short several_edits) &&
327         ONTO=$(git rev-parse --short HEAD~3) &&
328         git rebase -i HEAD~3 &&
329         git rebase --continue &&
330         cat >expected <<EOF &&
331 interactive rebase in progress; onto $ONTO
332 Last commands done (2 commands done):
333    edit $COMMIT2 two_edits
334    edit $COMMIT3 three_edits
335 Next command to do (1 remaining command):
336    pick $COMMIT4 four_edits
337   (use "git rebase --edit-todo" to view and edit)
338 You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
339   (use "git commit --amend" to amend the current commit)
340   (use "git rebase --continue" once you are satisfied with your changes)
341
342 nothing to commit (use -u to show untracked files)
343 EOF
344         git status --untracked-files=no >actual &&
345         test_i18ncmp expected actual
346 '
347
348
349 test_expect_success 'status: (continue first edit) second edit and split' '
350         git reset --hard several_edits &&
351         FAKE_LINES="edit 1 edit 2 3" &&
352         export FAKE_LINES &&
353         test_when_finished "git rebase --abort" &&
354         COMMIT2=$(git rev-parse --short several_edits^^) &&
355         COMMIT3=$(git rev-parse --short several_edits^) &&
356         COMMIT4=$(git rev-parse --short several_edits) &&
357         ONTO=$(git rev-parse --short HEAD~3) &&
358         git rebase -i HEAD~3 &&
359         git rebase --continue &&
360         git reset HEAD^ &&
361         cat >expected <<EOF &&
362 interactive rebase in progress; onto $ONTO
363 Last commands done (2 commands done):
364    edit $COMMIT2 two_edits
365    edit $COMMIT3 three_edits
366 Next command to do (1 remaining command):
367    pick $COMMIT4 four_edits
368   (use "git rebase --edit-todo" to view and edit)
369 You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
370   (Once your working directory is clean, run "git rebase --continue")
371
372 Changes not staged for commit:
373   (use "git add <file>..." to update what will be committed)
374   (use "git checkout -- <file>..." to discard changes in working directory)
375
376         modified:   main.txt
377
378 no changes added to commit (use "git add" and/or "git commit -a")
379 EOF
380         git status --untracked-files=no >actual &&
381         test_i18ncmp expected actual
382 '
383
384
385 test_expect_success 'status: (continue first edit) second edit and amend' '
386         git reset --hard several_edits &&
387         FAKE_LINES="edit 1 edit 2 3" &&
388         export FAKE_LINES &&
389         test_when_finished "git rebase --abort" &&
390         COMMIT2=$(git rev-parse --short several_edits^^) &&
391         COMMIT3=$(git rev-parse --short several_edits^) &&
392         COMMIT4=$(git rev-parse --short several_edits) &&
393         ONTO=$(git rev-parse --short HEAD~3) &&
394         git rebase -i HEAD~3 &&
395         git rebase --continue &&
396         git commit --amend -m "foo" &&
397         cat >expected <<EOF &&
398 interactive rebase in progress; onto $ONTO
399 Last commands done (2 commands done):
400    edit $COMMIT2 two_edits
401    edit $COMMIT3 three_edits
402 Next command to do (1 remaining command):
403    pick $COMMIT4 four_edits
404   (use "git rebase --edit-todo" to view and edit)
405 You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
406   (use "git commit --amend" to amend the current commit)
407   (use "git rebase --continue" once you are satisfied with your changes)
408
409 nothing to commit (use -u to show untracked files)
410 EOF
411         git status --untracked-files=no >actual &&
412         test_i18ncmp expected actual
413 '
414
415
416 test_expect_success 'status: (amend first edit) second edit' '
417         git reset --hard several_edits &&
418         FAKE_LINES="edit 1 edit 2 3" &&
419         export FAKE_LINES &&
420         test_when_finished "git rebase --abort" &&
421         COMMIT2=$(git rev-parse --short several_edits^^) &&
422         COMMIT3=$(git rev-parse --short several_edits^) &&
423         COMMIT4=$(git rev-parse --short several_edits) &&
424         ONTO=$(git rev-parse --short HEAD~3) &&
425         git rebase -i HEAD~3 &&
426         git commit --amend -m "a" &&
427         git rebase --continue &&
428         cat >expected <<EOF &&
429 interactive rebase in progress; onto $ONTO
430 Last commands done (2 commands done):
431    edit $COMMIT2 two_edits
432    edit $COMMIT3 three_edits
433 Next command to do (1 remaining command):
434    pick $COMMIT4 four_edits
435   (use "git rebase --edit-todo" to view and edit)
436 You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
437   (use "git commit --amend" to amend the current commit)
438   (use "git rebase --continue" once you are satisfied with your changes)
439
440 nothing to commit (use -u to show untracked files)
441 EOF
442         git status --untracked-files=no >actual &&
443         test_i18ncmp expected actual
444 '
445
446
447 test_expect_success 'status: (amend first edit) second edit and split' '
448         git reset --hard several_edits &&
449         FAKE_LINES="edit 1 edit 2 3" &&
450         export FAKE_LINES &&
451         test_when_finished "git rebase --abort" &&
452         ONTO=$(git rev-parse --short HEAD~3) &&
453         COMMIT2=$(git rev-parse --short several_edits^^) &&
454         COMMIT3=$(git rev-parse --short several_edits^) &&
455         COMMIT4=$(git rev-parse --short several_edits) &&
456         git rebase -i HEAD~3 &&
457         git commit --amend -m "b" &&
458         git rebase --continue &&
459         git reset HEAD^ &&
460         cat >expected <<EOF &&
461 interactive rebase in progress; onto $ONTO
462 Last commands done (2 commands done):
463    edit $COMMIT2 two_edits
464    edit $COMMIT3 three_edits
465 Next command to do (1 remaining command):
466    pick $COMMIT4 four_edits
467   (use "git rebase --edit-todo" to view and edit)
468 You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
469   (Once your working directory is clean, run "git rebase --continue")
470
471 Changes not staged for commit:
472   (use "git add <file>..." to update what will be committed)
473   (use "git checkout -- <file>..." to discard changes in working directory)
474
475         modified:   main.txt
476
477 no changes added to commit (use "git add" and/or "git commit -a")
478 EOF
479         git status --untracked-files=no >actual &&
480         test_i18ncmp expected actual
481 '
482
483
484 test_expect_success 'status: (amend first edit) second edit and amend' '
485         git reset --hard several_edits &&
486         FAKE_LINES="edit 1 edit 2 3" &&
487         export FAKE_LINES &&
488         test_when_finished "git rebase --abort" &&
489         COMMIT2=$(git rev-parse --short several_edits^^) &&
490         COMMIT3=$(git rev-parse --short several_edits^) &&
491         COMMIT4=$(git rev-parse --short several_edits) &&
492         ONTO=$(git rev-parse --short HEAD~3) &&
493         git rebase -i HEAD~3 &&
494         git commit --amend -m "c" &&
495         git rebase --continue &&
496         git commit --amend -m "d" &&
497         cat >expected <<EOF &&
498 interactive rebase in progress; onto $ONTO
499 Last commands done (2 commands done):
500    edit $COMMIT2 two_edits
501    edit $COMMIT3 three_edits
502 Next command to do (1 remaining command):
503    pick $COMMIT4 four_edits
504   (use "git rebase --edit-todo" to view and edit)
505 You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
506   (use "git commit --amend" to amend the current commit)
507   (use "git rebase --continue" once you are satisfied with your changes)
508
509 nothing to commit (use -u to show untracked files)
510 EOF
511         git status --untracked-files=no >actual &&
512         test_i18ncmp expected actual
513 '
514
515
516 test_expect_success 'status: (split first edit) second edit' '
517         git reset --hard several_edits &&
518         FAKE_LINES="edit 1 edit 2 3" &&
519         export FAKE_LINES &&
520         test_when_finished "git rebase --abort" &&
521         COMMIT2=$(git rev-parse --short several_edits^^) &&
522         COMMIT3=$(git rev-parse --short several_edits^) &&
523         COMMIT4=$(git rev-parse --short several_edits) &&
524         ONTO=$(git rev-parse --short HEAD~3) &&
525         git rebase -i HEAD~3 &&
526         git reset HEAD^ &&
527         git add main.txt &&
528         git commit -m "e" &&
529         git rebase --continue &&
530         cat >expected <<EOF &&
531 interactive rebase in progress; onto $ONTO
532 Last commands done (2 commands done):
533    edit $COMMIT2 two_edits
534    edit $COMMIT3 three_edits
535 Next command to do (1 remaining command):
536    pick $COMMIT4 four_edits
537   (use "git rebase --edit-todo" to view and edit)
538 You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
539   (use "git commit --amend" to amend the current commit)
540   (use "git rebase --continue" once you are satisfied with your changes)
541
542 nothing to commit (use -u to show untracked files)
543 EOF
544         git status --untracked-files=no >actual &&
545         test_i18ncmp expected actual
546 '
547
548
549 test_expect_success 'status: (split first edit) second edit and split' '
550         git reset --hard several_edits &&
551         FAKE_LINES="edit 1 edit 2 3" &&
552         export FAKE_LINES &&
553         test_when_finished "git rebase --abort" &&
554         COMMIT2=$(git rev-parse --short several_edits^^) &&
555         COMMIT3=$(git rev-parse --short several_edits^) &&
556         COMMIT4=$(git rev-parse --short several_edits) &&
557         ONTO=$(git rev-parse --short HEAD~3) &&
558         git rebase -i HEAD~3 &&
559         git reset HEAD^ &&
560         git add main.txt &&
561         git commit --amend -m "f" &&
562         git rebase --continue &&
563         git reset HEAD^ &&
564         cat >expected <<EOF &&
565 interactive rebase in progress; onto $ONTO
566 Last commands done (2 commands done):
567    edit $COMMIT2 two_edits
568    edit $COMMIT3 three_edits
569 Next command to do (1 remaining command):
570    pick $COMMIT4 four_edits
571   (use "git rebase --edit-todo" to view and edit)
572 You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
573   (Once your working directory is clean, run "git rebase --continue")
574
575 Changes not staged for commit:
576   (use "git add <file>..." to update what will be committed)
577   (use "git checkout -- <file>..." to discard changes in working directory)
578
579         modified:   main.txt
580
581 no changes added to commit (use "git add" and/or "git commit -a")
582 EOF
583         git status --untracked-files=no >actual &&
584         test_i18ncmp expected actual
585 '
586
587
588 test_expect_success 'status: (split first edit) second edit and amend' '
589         git reset --hard several_edits &&
590         FAKE_LINES="edit 1 edit 2 3" &&
591         export FAKE_LINES &&
592         test_when_finished "git rebase --abort" &&
593         COMMIT2=$(git rev-parse --short several_edits^^) &&
594         COMMIT3=$(git rev-parse --short several_edits^) &&
595         COMMIT4=$(git rev-parse --short several_edits) &&
596         ONTO=$(git rev-parse --short HEAD~3) &&
597         git rebase -i HEAD~3 &&
598         git reset HEAD^ &&
599         git add main.txt &&
600         git commit --amend -m "g" &&
601         git rebase --continue &&
602         git commit --amend -m "h" &&
603         cat >expected <<EOF &&
604 interactive rebase in progress; onto $ONTO
605 Last commands done (2 commands done):
606    edit $COMMIT2 two_edits
607    edit $COMMIT3 three_edits
608 Next command to do (1 remaining command):
609    pick $COMMIT4 four_edits
610   (use "git rebase --edit-todo" to view and edit)
611 You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
612   (use "git commit --amend" to amend the current commit)
613   (use "git rebase --continue" once you are satisfied with your changes)
614
615 nothing to commit (use -u to show untracked files)
616 EOF
617         git status --untracked-files=no >actual &&
618         test_i18ncmp expected actual
619 '
620
621
622 test_expect_success 'prepare am_session' '
623         git reset --hard master &&
624         git checkout -b am_session &&
625         test_commit one_am one.txt "one" &&
626         test_commit two_am two.txt "two" &&
627         test_commit three_am three.txt "three"
628 '
629
630
631 test_expect_success 'status in an am session: file already exists' '
632         git checkout -b am_already_exists &&
633         git format-patch -1 -oMaildir &&
634         test_must_fail git am Maildir/*.patch &&
635         cat >expected <<\EOF &&
636 On branch am_already_exists
637 You are in the middle of an am session.
638   (fix conflicts and then run "git am --continue")
639   (use "git am --skip" to skip this patch)
640   (use "git am --abort" to restore the original branch)
641
642 nothing to commit (use -u to show untracked files)
643 EOF
644         git status --untracked-files=no >actual &&
645         test_i18ncmp expected actual
646 '
647
648 test_expect_success 'short status in an am session: file already exists' '
649         test_when_finished "rm Maildir/* && git am --abort" &&
650         cat >expected <<\EOF &&
651 ## am_already_exists; AM
652 EOF
653         git status --untracked-files=no --short --branch --in-progress >actual &&
654         test_i18ncmp expected actual
655 '
656
657 test_expect_success 'status in an am session: file does not exist' '
658         git reset --hard am_session &&
659         git checkout -b am_not_exists &&
660         git rm three.txt &&
661         git commit -m "delete three.txt" &&
662         test_when_finished "rm Maildir/* && git am --abort" &&
663         git format-patch -1 -oMaildir &&
664         test_must_fail git am Maildir/*.patch &&
665         cat >expected <<\EOF &&
666 On branch am_not_exists
667 You are in the middle of an am session.
668   (fix conflicts and then run "git am --continue")
669   (use "git am --skip" to skip this patch)
670   (use "git am --abort" to restore the original branch)
671
672 nothing to commit (use -u to show untracked files)
673 EOF
674         git status --untracked-files=no >actual &&
675         test_i18ncmp expected actual
676 '
677
678
679 test_expect_success 'status in an am session: empty patch' '
680         git reset --hard am_session &&
681         git checkout -b am_empty &&
682         test_when_finished "rm Maildir/* && git am --abort" &&
683         git format-patch -3 -oMaildir &&
684         git rm one.txt two.txt three.txt &&
685         git commit -m "delete all am_empty" &&
686         echo error >Maildir/0002-two_am.patch &&
687         test_must_fail git am Maildir/*.patch &&
688         cat >expected <<\EOF &&
689 On branch am_empty
690 You are in the middle of an am session.
691 The current patch is empty.
692   (use "git am --skip" to skip this patch)
693   (use "git am --abort" to restore the original branch)
694
695 nothing to commit (use -u to show untracked files)
696 EOF
697         git status --untracked-files=no >actual &&
698         test_i18ncmp expected actual
699 '
700
701
702 test_expect_success 'status when bisecting' '
703         git reset --hard master &&
704         git checkout -b bisect &&
705         test_commit one_bisect main.txt one &&
706         test_commit two_bisect main.txt two &&
707         test_commit three_bisect main.txt three &&
708         git bisect start &&
709         git bisect bad &&
710         git bisect good one_bisect &&
711         TGT=$(git rev-parse --short two_bisect) &&
712         cat >expected <<EOF &&
713 HEAD detached at $TGT
714 You are currently bisecting, started from branch '\''bisect'\''.
715   (use "git bisect reset" to get back to the original branch)
716
717 nothing to commit (use -u to show untracked files)
718 EOF
719         git status --untracked-files=no >actual &&
720         test_i18ncmp expected actual
721 '
722
723 test_expect_success 'short status when bisecting' '
724         test_when_finished "git bisect reset" &&
725         cat >expected <<EOF &&
726 ## HEAD (no branch); BISECTING
727 EOF
728         git status --untracked-files=no --short --branch --in-progress >actual &&
729         test_i18ncmp expected actual
730 '
731
732 test_expect_success 'status when rebase conflicts with statushints disabled' '
733         git reset --hard master &&
734         git checkout -b statushints_disabled &&
735         test_when_finished "git config --local advice.statushints true" &&
736         git config --local advice.statushints false &&
737         test_commit one_statushints main.txt one &&
738         test_commit two_statushints main.txt two &&
739         test_commit three_statushints main.txt three &&
740         test_when_finished "git rebase --abort" &&
741         ONTO=$(git rev-parse --short HEAD^^) &&
742         test_must_fail git rebase HEAD^ --onto HEAD^^ &&
743         cat >expected <<EOF &&
744 rebase in progress; onto $ONTO
745 You are currently rebasing branch '\''statushints_disabled'\'' on '\''$ONTO'\''.
746
747 Unmerged paths:
748         both modified:   main.txt
749
750 no changes added to commit
751 EOF
752         git status --untracked-files=no >actual &&
753         test_i18ncmp expected actual
754 '
755
756
757 test_expect_success 'prepare for cherry-pick conflicts' '
758         git reset --hard master &&
759         git checkout -b cherry_branch &&
760         test_commit one_cherry main.txt one &&
761         test_commit two_cherries main.txt two &&
762         git checkout -b cherry_branch_second &&
763         test_commit second_cherry main.txt second &&
764         git checkout cherry_branch &&
765         test_commit three_cherries main.txt three
766 '
767
768
769 test_expect_success 'status when cherry-picking before resolving conflicts' '
770         test_must_fail git cherry-pick cherry_branch_second &&
771         TO_CHERRY_PICK=$(git rev-parse --short CHERRY_PICK_HEAD) &&
772         cat >expected <<EOF &&
773 On branch cherry_branch
774 You are currently cherry-picking commit $TO_CHERRY_PICK.
775   (fix conflicts and run "git cherry-pick --continue")
776   (use "git cherry-pick --abort" to cancel the cherry-pick operation)
777
778 Unmerged paths:
779   (use "git add <file>..." to mark resolution)
780
781         both modified:   main.txt
782
783 no changes added to commit (use "git add" and/or "git commit -a")
784 EOF
785         git status --untracked-files=no >actual &&
786         test_i18ncmp expected actual
787 '
788
789 test_expect_success 'short status when cherry-picking before resolving conflicts' '
790         test_when_finished "git cherry-pick --abort" &&
791         cat >expected <<EOF &&
792 ## cherry_branch; CHERRY-PICKING
793 UU main.txt
794 EOF
795         git status --untracked-files=no --short --branch --in-progress >actual &&
796         test_i18ncmp expected actual
797 '
798
799 test_expect_success 'status when cherry-picking after resolving conflicts' '
800         git reset --hard cherry_branch &&
801         test_when_finished "git cherry-pick --abort" &&
802         test_must_fail git cherry-pick cherry_branch_second &&
803         TO_CHERRY_PICK=$(git rev-parse --short CHERRY_PICK_HEAD) &&
804         echo end >main.txt &&
805         git add main.txt &&
806         cat >expected <<EOF &&
807 On branch cherry_branch
808 You are currently cherry-picking commit $TO_CHERRY_PICK.
809   (all conflicts fixed: run "git cherry-pick --continue")
810   (use "git cherry-pick --abort" to cancel the cherry-pick operation)
811
812 Changes to be committed:
813
814         modified:   main.txt
815
816 Untracked files not listed (use -u option to show untracked files)
817 EOF
818         git status --untracked-files=no >actual &&
819         test_i18ncmp expected actual
820 '
821
822 test_expect_success 'status showing detached at and from a tag' '
823         test_commit atag tagging &&
824         git checkout atag &&
825         cat >expected <<\EOF &&
826 HEAD detached at atag
827 nothing to commit (use -u to show untracked files)
828 EOF
829         git status --untracked-files=no >actual &&
830         test_i18ncmp expected actual &&
831
832         git reset --hard HEAD^ &&
833         cat >expected <<\EOF &&
834 HEAD detached from atag
835 nothing to commit (use -u to show untracked files)
836 EOF
837         git status --untracked-files=no >actual &&
838         test_i18ncmp expected actual
839 '
840
841 test_expect_success 'status while reverting commit (conflicts)' '
842         git checkout master &&
843         echo before >to-revert.txt &&
844         test_commit before to-revert.txt &&
845         echo old >to-revert.txt &&
846         test_commit old to-revert.txt &&
847         echo new >to-revert.txt &&
848         test_commit new to-revert.txt &&
849         TO_REVERT=$(git rev-parse --short HEAD^) &&
850         test_must_fail git revert $TO_REVERT &&
851         cat >expected <<EOF &&
852 On branch master
853 You are currently reverting commit $TO_REVERT.
854   (fix conflicts and run "git revert --continue")
855   (use "git revert --abort" to cancel the revert operation)
856
857 Unmerged paths:
858   (use "git reset HEAD <file>..." to unstage)
859   (use "git add <file>..." to mark resolution)
860
861         both modified:   to-revert.txt
862
863 no changes added to commit (use "git add" and/or "git commit -a")
864 EOF
865         git status --untracked-files=no >actual &&
866         test_i18ncmp expected actual
867 '
868
869 test_expect_success 'short status while reverting commit (conflicts)' '
870         cat >expected <<EOF &&
871 ## master; REVERTING
872 UU to-revert.txt
873 EOF
874         git status --untracked-files=no --short --branch --in-progress >actual &&
875         test_i18ncmp expected actual
876 '
877
878 test_expect_success 'status while reverting commit (conflicts resolved)' '
879         echo reverted >to-revert.txt &&
880         git add to-revert.txt &&
881         cat >expected <<EOF &&
882 On branch master
883 You are currently reverting commit $TO_REVERT.
884   (all conflicts fixed: run "git revert --continue")
885   (use "git revert --abort" to cancel the revert operation)
886
887 Changes to be committed:
888   (use "git reset HEAD <file>..." to unstage)
889
890         modified:   to-revert.txt
891
892 Untracked files not listed (use -u option to show untracked files)
893 EOF
894         git status --untracked-files=no >actual &&
895         test_i18ncmp expected actual
896 '
897
898 test_expect_success 'status after reverting commit' '
899         git revert --continue &&
900         cat >expected <<\EOF &&
901 On branch master
902 nothing to commit (use -u to show untracked files)
903 EOF
904         git status --untracked-files=no >actual &&
905         test_i18ncmp expected actual
906 '
907
908 test_expect_success 'prepare for different number of commits rebased' '
909         git reset --hard master &&
910         git checkout -b several_commits &&
911         test_commit one_commit main.txt one &&
912         test_commit two_commit main.txt two &&
913         test_commit three_commit main.txt three &&
914         test_commit four_commit main.txt four
915 '
916
917 test_expect_success 'status: one command done nothing remaining' '
918         FAKE_LINES="exec_exit_15" &&
919         export FAKE_LINES &&
920         test_when_finished "git rebase --abort" &&
921         ONTO=$(git rev-parse --short HEAD~3) &&
922         test_must_fail git rebase -i HEAD~3 &&
923         cat >expected <<EOF &&
924 interactive rebase in progress; onto $ONTO
925 Last command done (1 command done):
926    exec exit 15
927 No commands remaining.
928 You are currently editing a commit while rebasing branch '\''several_commits'\'' on '\''$ONTO'\''.
929   (use "git commit --amend" to amend the current commit)
930   (use "git rebase --continue" once you are satisfied with your changes)
931
932 nothing to commit (use -u to show untracked files)
933 EOF
934         git status --untracked-files=no >actual &&
935         test_i18ncmp expected actual
936 '
937
938 test_expect_success 'status: two commands done with some white lines in done file' '
939         FAKE_LINES="1 > exec_exit_15  2 3" &&
940         export FAKE_LINES &&
941         test_when_finished "git rebase --abort" &&
942         ONTO=$(git rev-parse --short HEAD~3) &&
943         COMMIT4=$(git rev-parse --short HEAD) &&
944         COMMIT3=$(git rev-parse --short HEAD^) &&
945         COMMIT2=$(git rev-parse --short HEAD^^) &&
946         test_must_fail git rebase -i HEAD~3 &&
947         cat >expected <<EOF &&
948 interactive rebase in progress; onto $ONTO
949 Last commands done (2 commands done):
950    pick $COMMIT2 two_commit
951    exec exit 15
952 Next commands to do (2 remaining commands):
953    pick $COMMIT3 three_commit
954    pick $COMMIT4 four_commit
955   (use "git rebase --edit-todo" to view and edit)
956 You are currently editing a commit while rebasing branch '\''several_commits'\'' on '\''$ONTO'\''.
957   (use "git commit --amend" to amend the current commit)
958   (use "git rebase --continue" once you are satisfied with your changes)
959
960 nothing to commit (use -u to show untracked files)
961 EOF
962         git status --untracked-files=no >actual &&
963         test_i18ncmp expected actual
964 '
965
966 test_expect_success 'status: two remaining commands with some white lines in todo file' '
967         FAKE_LINES="1 2 exec_exit_15 3 > 4" &&
968         export FAKE_LINES &&
969         test_when_finished "git rebase --abort" &&
970         ONTO=$(git rev-parse --short HEAD~4) &&
971         COMMIT4=$(git rev-parse --short HEAD) &&
972         COMMIT3=$(git rev-parse --short HEAD^) &&
973         COMMIT2=$(git rev-parse --short HEAD^^) &&
974         test_must_fail git rebase -i HEAD~4 &&
975         cat >expected <<EOF &&
976 interactive rebase in progress; onto $ONTO
977 Last commands done (3 commands done):
978    pick $COMMIT2 two_commit
979    exec exit 15
980   (see more in file .git/rebase-merge/done)
981 Next commands to do (2 remaining commands):
982    pick $COMMIT3 three_commit
983    pick $COMMIT4 four_commit
984   (use "git rebase --edit-todo" to view and edit)
985 You are currently editing a commit while rebasing branch '\''several_commits'\'' on '\''$ONTO'\''.
986   (use "git commit --amend" to amend the current commit)
987   (use "git rebase --continue" once you are satisfied with your changes)
988
989 nothing to commit (use -u to show untracked files)
990 EOF
991         git status --untracked-files=no >actual &&
992         test_i18ncmp expected actual
993 '
994
995 test_expect_success 'status: handle not-yet-started rebase -i gracefully' '
996         ONTO=$(git rev-parse --short HEAD^) &&
997         COMMIT=$(git rev-parse --short HEAD) &&
998         EDITOR="git status --untracked-files=no >actual" git rebase -i HEAD^ &&
999         cat >expected <<EOF &&
1000 On branch several_commits
1001 No commands done.
1002 Next command to do (1 remaining command):
1003    pick $COMMIT four_commit
1004   (use "git rebase --edit-todo" to view and edit)
1005 You are currently editing a commit while rebasing branch '\''several_commits'\'' on '\''$ONTO'\''.
1006   (use "git commit --amend" to amend the current commit)
1007   (use "git rebase --continue" once you are satisfied with your changes)
1008
1009 nothing to commit (use -u to show untracked files)
1010 EOF
1011         test_i18ncmp expected actual
1012 '
1013
1014 test_done