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