3 # Copyright (c) 2012 Valentin Duperray, Lucien Kong, Franck Jonas,
4 # Thomas Nguy, Khoi Nguyen
8 test_description='git status advices'
12 . "$TEST_DIRECTORY"/lib-rebase.sh
16 test_expect_success 'prepare for conflicts' '
17 test_commit init main.txt init &&
18 git branch conflicts &&
19 test_commit on_master main.txt on_master &&
20 git checkout conflicts &&
21 test_commit on_conflicts main.txt on_conflicts
25 test_expect_success 'status when conflicts unresolved' '
26 test_must_fail git merge master &&
27 cat >expected <<-\EOF &&
29 # You have unmerged paths.
30 # (fix conflicts and run "git commit")
33 # (use "git add <file>..." to mark resolution)
35 # both modified: main.txt
37 no changes added to commit (use "git add" and/or "git commit -a")
39 git status --untracked-files=no >actual &&
40 test_i18ncmp expected actual
44 test_expect_success 'status when conflicts resolved before commit' '
45 git reset --hard conflicts &&
46 test_must_fail git merge master &&
49 cat >expected <<-\EOF &&
51 # All conflicts fixed but you are still merging.
52 # (use "git commit" to conclude merge)
54 # Changes to be committed:
58 # Untracked files not listed (use -u option to show untracked files)
60 git status --untracked-files=no >actual &&
61 test_i18ncmp expected actual
65 test_expect_success 'prepare for rebase conflicts' '
66 git reset --hard master &&
67 git checkout -b rebase_conflicts &&
68 test_commit one_rebase main.txt one &&
69 test_commit two_rebase main.txt two &&
70 test_commit three_rebase main.txt three
74 test_expect_success 'status when rebase in progress before resolving conflicts' '
75 test_when_finished "git rebase --abort" &&
76 ONTO=$(git rev-parse --short HEAD^^) &&
77 test_must_fail git rebase HEAD^ --onto HEAD^^ &&
78 cat >expected <<-EOF &&
79 # HEAD detached at $ONTO
80 # You are currently rebasing branch '\''rebase_conflicts'\'' on '\''$ONTO'\''.
81 # (fix conflicts and then run "git rebase --continue")
82 # (use "git rebase --skip" to skip this patch)
83 # (use "git rebase --abort" to check out the original branch)
86 # (use "git reset HEAD <file>..." to unstage)
87 # (use "git add <file>..." to mark resolution)
89 # both modified: main.txt
91 no changes added to commit (use "git add" and/or "git commit -a")
93 git status --untracked-files=no >actual &&
94 test_i18ncmp expected actual
98 test_expect_success 'status when rebase in progress before rebase --continue' '
99 git reset --hard rebase_conflicts &&
100 test_when_finished "git rebase --abort" &&
101 ONTO=$(git rev-parse --short HEAD^^) &&
102 test_must_fail git rebase HEAD^ --onto HEAD^^ &&
103 echo three >main.txt &&
105 cat >expected <<-EOF &&
106 # HEAD detached at $ONTO
107 # You are currently rebasing branch '\''rebase_conflicts'\'' on '\''$ONTO'\''.
108 # (all conflicts fixed: run "git rebase --continue")
110 # Changes to be committed:
111 # (use "git reset HEAD <file>..." to unstage)
115 # Untracked files not listed (use -u option to show untracked files)
117 git status --untracked-files=no >actual &&
118 test_i18ncmp expected actual
122 test_expect_success 'prepare for rebase_i_conflicts' '
123 git reset --hard master &&
124 git checkout -b rebase_i_conflicts &&
125 test_commit one_unmerge main.txt one_unmerge &&
126 git branch rebase_i_conflicts_second &&
127 test_commit one_master main.txt one_master &&
128 git checkout rebase_i_conflicts_second &&
129 test_commit one_second main.txt one_second
133 test_expect_success 'status during rebase -i when conflicts unresolved' '
134 test_when_finished "git rebase --abort" &&
135 ONTO=$(git rev-parse --short rebase_i_conflicts) &&
136 test_must_fail git rebase -i rebase_i_conflicts &&
137 cat >expected <<-EOF &&
138 # HEAD detached at $ONTO
139 # You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
140 # (fix conflicts and then run "git rebase --continue")
141 # (use "git rebase --skip" to skip this patch)
142 # (use "git rebase --abort" to check out the original branch)
145 # (use "git reset HEAD <file>..." to unstage)
146 # (use "git add <file>..." to mark resolution)
148 # both modified: main.txt
150 no changes added to commit (use "git add" and/or "git commit -a")
152 git status --untracked-files=no >actual &&
153 test_i18ncmp expected actual
157 test_expect_success 'status during rebase -i after resolving conflicts' '
158 git reset --hard rebase_i_conflicts_second &&
159 test_when_finished "git rebase --abort" &&
160 ONTO=$(git rev-parse --short rebase_i_conflicts) &&
161 test_must_fail git rebase -i rebase_i_conflicts &&
163 cat >expected <<-EOF &&
164 # HEAD detached at $ONTO
165 # You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
166 # (all conflicts fixed: run "git rebase --continue")
168 # Changes to be committed:
169 # (use "git reset HEAD <file>..." to unstage)
173 # Untracked files not listed (use -u option to show untracked files)
175 git status --untracked-files=no >actual &&
176 test_i18ncmp expected actual
180 test_expect_success 'status when rebasing -i in edit mode' '
181 git reset --hard master &&
182 git checkout -b rebase_i_edit &&
183 test_commit one_rebase_i main.txt one &&
184 test_commit two_rebase_i main.txt two &&
185 test_commit three_rebase_i main.txt three &&
186 FAKE_LINES="1 edit 2" &&
188 test_when_finished "git rebase --abort" &&
189 ONTO=$(git rev-parse --short HEAD~2) &&
190 TGT=$(git rev-parse --short two_rebase_i) &&
191 git rebase -i HEAD~2 &&
192 cat >expected <<-EOF &&
193 # HEAD detached from $TGT
194 # You are currently editing a commit while rebasing branch '\''rebase_i_edit'\'' on '\''$ONTO'\''.
195 # (use "git commit --amend" to amend the current commit)
196 # (use "git rebase --continue" once you are satisfied with your changes)
198 nothing to commit (use -u to show untracked files)
200 git status --untracked-files=no >actual &&
201 test_i18ncmp expected actual
205 test_expect_success 'status when splitting a commit' '
206 git reset --hard master &&
207 git checkout -b split_commit &&
208 test_commit one_split main.txt one &&
209 test_commit two_split main.txt two &&
210 test_commit three_split main.txt three &&
211 test_commit four_split main.txt four &&
212 FAKE_LINES="1 edit 2 3" &&
214 test_when_finished "git rebase --abort" &&
215 ONTO=$(git rev-parse --short HEAD~3) &&
216 git rebase -i HEAD~3 &&
218 TGT=$(git rev-parse --short HEAD) &&
219 cat >expected <<-EOF &&
220 # HEAD detached at $TGT
221 # You are currently splitting a commit while rebasing branch '\''split_commit'\'' on '\''$ONTO'\''.
222 # (Once your working directory is clean, run "git rebase --continue")
224 # Changes not staged for commit:
225 # (use "git add <file>..." to update what will be committed)
226 # (use "git checkout -- <file>..." to discard changes in working directory)
230 no changes added to commit (use "git add" and/or "git commit -a")
232 git status --untracked-files=no >actual &&
233 test_i18ncmp expected actual
237 test_expect_success 'status after editing the last commit with --amend during a rebase -i' '
238 git reset --hard master &&
239 git checkout -b amend_last &&
240 test_commit one_amend main.txt one &&
241 test_commit two_amend main.txt two &&
242 test_commit three_amend main.txt three &&
243 test_commit four_amend main.txt four &&
244 FAKE_LINES="1 2 edit 3" &&
246 test_when_finished "git rebase --abort" &&
247 ONTO=$(git rev-parse --short HEAD~3) &&
248 TGT=$(git rev-parse --short three_amend) &&
249 git rebase -i HEAD~3 &&
250 git commit --amend -m "foo" &&
251 cat >expected <<-EOF &&
252 # HEAD detached from $TGT
253 # You are currently editing a commit while rebasing branch '\''amend_last'\'' on '\''$ONTO'\''.
254 # (use "git commit --amend" to amend the current commit)
255 # (use "git rebase --continue" once you are satisfied with your changes)
257 nothing to commit (use -u to show untracked files)
259 git status --untracked-files=no >actual &&
260 test_i18ncmp expected actual
264 test_expect_success 'prepare for several edits' '
265 git reset --hard master &&
266 git checkout -b several_edits &&
267 test_commit one_edits main.txt one &&
268 test_commit two_edits main.txt two &&
269 test_commit three_edits main.txt three &&
270 test_commit four_edits main.txt four
274 test_expect_success 'status: (continue first edit) second edit' '
275 FAKE_LINES="edit 1 edit 2 3" &&
277 test_when_finished "git rebase --abort" &&
278 ONTO=$(git rev-parse --short HEAD~3) &&
279 git rebase -i HEAD~3 &&
280 git rebase --continue &&
281 cat >expected <<-EOF &&
282 # HEAD detached from $ONTO
283 # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
284 # (use "git commit --amend" to amend the current commit)
285 # (use "git rebase --continue" once you are satisfied with your changes)
287 nothing to commit (use -u to show untracked files)
289 git status --untracked-files=no >actual &&
290 test_i18ncmp expected actual
294 test_expect_success 'status: (continue first edit) second edit and split' '
295 git reset --hard several_edits &&
296 FAKE_LINES="edit 1 edit 2 3" &&
298 test_when_finished "git rebase --abort" &&
299 ONTO=$(git rev-parse --short HEAD~3) &&
300 git rebase -i HEAD~3 &&
301 git rebase --continue &&
303 cat >expected <<-EOF &&
304 # HEAD detached from $ONTO
305 # You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
306 # (Once your working directory is clean, run "git rebase --continue")
308 # Changes not staged for commit:
309 # (use "git add <file>..." to update what will be committed)
310 # (use "git checkout -- <file>..." to discard changes in working directory)
314 no changes added to commit (use "git add" and/or "git commit -a")
316 git status --untracked-files=no >actual &&
317 test_i18ncmp expected actual
321 test_expect_success 'status: (continue first edit) second edit and amend' '
322 git reset --hard several_edits &&
323 FAKE_LINES="edit 1 edit 2 3" &&
325 test_when_finished "git rebase --abort" &&
326 ONTO=$(git rev-parse --short HEAD~3) &&
327 git rebase -i HEAD~3 &&
328 git rebase --continue &&
329 git commit --amend -m "foo" &&
330 cat >expected <<-EOF &&
331 # HEAD detached from $ONTO
332 # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
333 # (use "git commit --amend" to amend the current commit)
334 # (use "git rebase --continue" once you are satisfied with your changes)
336 nothing to commit (use -u to show untracked files)
338 git status --untracked-files=no >actual &&
339 test_i18ncmp expected actual
343 test_expect_success 'status: (amend first edit) second edit' '
344 git reset --hard several_edits &&
345 FAKE_LINES="edit 1 edit 2 3" &&
347 test_when_finished "git rebase --abort" &&
348 ONTO=$(git rev-parse --short HEAD~3) &&
349 git rebase -i HEAD~3 &&
350 git commit --amend -m "a" &&
351 git rebase --continue &&
352 cat >expected <<-EOF &&
353 # HEAD detached from $ONTO
354 # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
355 # (use "git commit --amend" to amend the current commit)
356 # (use "git rebase --continue" once you are satisfied with your changes)
358 nothing to commit (use -u to show untracked files)
360 git status --untracked-files=no >actual &&
361 test_i18ncmp expected actual
365 test_expect_success 'status: (amend first edit) second edit and split' '
366 git reset --hard several_edits &&
367 FAKE_LINES="edit 1 edit 2 3" &&
369 test_when_finished "git rebase --abort" &&
370 ONTO=$(git rev-parse --short HEAD~3) &&
371 git rebase -i HEAD~3 &&
372 git commit --amend -m "b" &&
373 git rebase --continue &&
375 cat >expected <<-EOF &&
376 # HEAD detached from $ONTO
377 # You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
378 # (Once your working directory is clean, run "git rebase --continue")
380 # Changes not staged for commit:
381 # (use "git add <file>..." to update what will be committed)
382 # (use "git checkout -- <file>..." to discard changes in working directory)
386 no changes added to commit (use "git add" and/or "git commit -a")
388 git status --untracked-files=no >actual &&
389 test_i18ncmp expected actual
393 test_expect_success 'status: (amend first edit) second edit and amend' '
394 git reset --hard several_edits &&
395 FAKE_LINES="edit 1 edit 2 3" &&
397 test_when_finished "git rebase --abort" &&
398 ONTO=$(git rev-parse --short HEAD~3) &&
399 git rebase -i HEAD~3 &&
400 git commit --amend -m "c" &&
401 git rebase --continue &&
402 git commit --amend -m "d" &&
403 cat >expected <<-EOF &&
404 # HEAD detached from $ONTO
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)
409 nothing to commit (use -u to show untracked files)
411 git status --untracked-files=no >actual &&
412 test_i18ncmp expected actual
416 test_expect_success 'status: (split first edit) second edit' '
417 git reset --hard several_edits &&
418 FAKE_LINES="edit 1 edit 2 3" &&
420 test_when_finished "git rebase --abort" &&
421 ONTO=$(git rev-parse --short HEAD~3) &&
422 git rebase -i HEAD~3 &&
426 git rebase --continue &&
427 cat >expected <<-EOF &&
428 # HEAD detached from $ONTO
429 # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
430 # (use "git commit --amend" to amend the current commit)
431 # (use "git rebase --continue" once you are satisfied with your changes)
433 nothing to commit (use -u to show untracked files)
435 git status --untracked-files=no >actual &&
436 test_i18ncmp expected actual
440 test_expect_success 'status: (split first edit) second edit and split' '
441 git reset --hard several_edits &&
442 FAKE_LINES="edit 1 edit 2 3" &&
444 test_when_finished "git rebase --abort" &&
445 ONTO=$(git rev-parse --short HEAD~3) &&
446 git rebase -i HEAD~3 &&
449 git commit --amend -m "f" &&
450 git rebase --continue &&
452 cat >expected <<-EOF &&
453 # HEAD detached from $ONTO
454 # You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
455 # (Once your working directory is clean, run "git rebase --continue")
457 # Changes not staged for commit:
458 # (use "git add <file>..." to update what will be committed)
459 # (use "git checkout -- <file>..." to discard changes in working directory)
463 no changes added to commit (use "git add" and/or "git commit -a")
465 git status --untracked-files=no >actual &&
466 test_i18ncmp expected actual
470 test_expect_success 'status: (split first edit) second edit and amend' '
471 git reset --hard several_edits &&
472 FAKE_LINES="edit 1 edit 2 3" &&
474 test_when_finished "git rebase --abort" &&
475 ONTO=$(git rev-parse --short HEAD~3) &&
476 git rebase -i HEAD~3 &&
479 git commit --amend -m "g" &&
480 git rebase --continue &&
481 git commit --amend -m "h" &&
482 cat >expected <<-EOF &&
483 # HEAD detached from $ONTO
484 # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
485 # (use "git commit --amend" to amend the current commit)
486 # (use "git rebase --continue" once you are satisfied with your changes)
488 nothing to commit (use -u to show untracked files)
490 git status --untracked-files=no >actual &&
491 test_i18ncmp expected actual
495 test_expect_success 'prepare am_session' '
496 git reset --hard master &&
497 git checkout -b am_session &&
498 test_commit one_am one.txt "one" &&
499 test_commit two_am two.txt "two" &&
500 test_commit three_am three.txt "three"
504 test_expect_success 'status in an am session: file already exists' '
505 git checkout -b am_already_exists &&
506 test_when_finished "rm Maildir/* && git am --abort" &&
507 git format-patch -1 -oMaildir &&
508 test_must_fail git am Maildir/*.patch &&
509 cat >expected <<-\EOF &&
510 # On branch am_already_exists
511 # You are in the middle of an am session.
512 # (fix conflicts and then run "git am --resolved")
513 # (use "git am --skip" to skip this patch)
514 # (use "git am --abort" to restore the original branch)
516 nothing to commit (use -u to show untracked files)
518 git status --untracked-files=no >actual &&
519 test_i18ncmp expected actual
523 test_expect_success 'status in an am session: file does not exist' '
524 git reset --hard am_session &&
525 git checkout -b am_not_exists &&
527 git commit -m "delete three.txt" &&
528 test_when_finished "rm Maildir/* && git am --abort" &&
529 git format-patch -1 -oMaildir &&
530 test_must_fail git am Maildir/*.patch &&
531 cat >expected <<-\EOF &&
532 # On branch am_not_exists
533 # You are in the middle of an am session.
534 # (fix conflicts and then run "git am --resolved")
535 # (use "git am --skip" to skip this patch)
536 # (use "git am --abort" to restore the original branch)
538 nothing to commit (use -u to show untracked files)
540 git status --untracked-files=no >actual &&
541 test_i18ncmp expected actual
545 test_expect_success 'status in an am session: empty patch' '
546 git reset --hard am_session &&
547 git checkout -b am_empty &&
548 test_when_finished "rm Maildir/* && git am --abort" &&
549 git format-patch -3 -oMaildir &&
550 git rm one.txt two.txt three.txt &&
551 git commit -m "delete all am_empty" &&
552 echo error >Maildir/0002-two_am.patch &&
553 test_must_fail git am Maildir/*.patch &&
554 cat >expected <<-\EOF &&
556 # You are in the middle of an am session.
557 # The current patch is empty.
558 # (use "git am --skip" to skip this patch)
559 # (use "git am --abort" to restore the original branch)
561 nothing to commit (use -u to show untracked files)
563 git status --untracked-files=no >actual &&
564 test_i18ncmp expected actual
568 test_expect_success 'status when bisecting' '
569 git reset --hard master &&
570 git checkout -b bisect &&
571 test_commit one_bisect main.txt one &&
572 test_commit two_bisect main.txt two &&
573 test_commit three_bisect main.txt three &&
574 test_when_finished "git bisect reset" &&
577 git bisect good one_bisect &&
578 TGT=$(git rev-parse --short two_bisect) &&
579 cat >expected <<-EOF &&
580 # HEAD detached at $TGT
581 # You are currently bisecting branch '\''bisect'\''.
582 # (use "git bisect reset" to get back to the original branch)
584 nothing to commit (use -u to show untracked files)
586 git status --untracked-files=no >actual &&
587 test_i18ncmp expected actual
591 test_expect_success 'status when rebase conflicts with statushints disabled' '
592 git reset --hard master &&
593 git checkout -b statushints_disabled &&
594 test_when_finished "git config --local advice.statushints true" &&
595 git config --local advice.statushints false &&
596 test_commit one_statushints main.txt one &&
597 test_commit two_statushints main.txt two &&
598 test_commit three_statushints main.txt three &&
599 test_when_finished "git rebase --abort" &&
600 ONTO=$(git rev-parse --short HEAD^^) &&
601 test_must_fail git rebase HEAD^ --onto HEAD^^ &&
602 cat >expected <<-EOF &&
603 # HEAD detached at $ONTO
604 # You are currently rebasing branch '\''statushints_disabled'\'' on '\''$ONTO'\''.
607 # both modified: main.txt
609 no changes added to commit
611 git status --untracked-files=no >actual &&
612 test_i18ncmp expected actual
616 test_expect_success 'prepare for cherry-pick conflicts' '
617 git reset --hard master &&
618 git checkout -b cherry_branch &&
619 test_commit one_cherry main.txt one &&
620 test_commit two_cherries main.txt two &&
621 git checkout -b cherry_branch_second &&
622 test_commit second_cherry main.txt second &&
623 git checkout cherry_branch &&
624 test_commit three_cherries main.txt three
628 test_expect_success 'status when cherry-picking before resolving conflicts' '
629 test_when_finished "git cherry-pick --abort" &&
630 test_must_fail git cherry-pick cherry_branch_second &&
631 cat >expected <<-\EOF &&
632 # On branch cherry_branch
633 # You are currently cherry-picking.
634 # (fix conflicts and run "git commit")
637 # (use "git add <file>..." to mark resolution)
639 # both modified: main.txt
641 no changes added to commit (use "git add" and/or "git commit -a")
643 git status --untracked-files=no >actual &&
644 test_i18ncmp expected actual
648 test_expect_success 'status when cherry-picking after resolving conflicts' '
649 git reset --hard cherry_branch &&
650 test_when_finished "git cherry-pick --abort" &&
651 test_must_fail git cherry-pick cherry_branch_second &&
652 echo end >main.txt &&
654 cat >expected <<-\EOF &&
655 # On branch cherry_branch
656 # You are currently cherry-picking.
657 # (all conflicts fixed: run "git commit")
659 # Changes to be committed:
663 # Untracked files not listed (use -u option to show untracked files)
665 git status --untracked-files=no >actual &&
666 test_i18ncmp expected actual
669 test_expect_success 'status showing detached from a tag' '
670 test_commit atag tagging &&
672 cat >expected <<-\EOF
673 # HEAD detached at atag
674 nothing to commit (use -u to show untracked files)
676 git status --untracked-files=no >actual &&
677 test_i18ncmp expected actual