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
8test_description='git status advice'
9
10. ./test-lib.sh
11
12. "$TEST_DIRECTORY"/lib-rebase.sh
13
14set_fake_editor
15
16test_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
26test_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 #
33 # Unmerged paths:
34 # (use "git add <file>..." to mark resolution)
35 #
36 # both modified: main.txt
37 #
38 no changes added to commit (use "git add" and/or "git commit -a")
39 EOF
40 git status --untracked-files=no >actual &&
41 test_i18ncmp expected actual
42'
43
44
45test_expect_success 'status when conflicts resolved before commit' '
46 git reset --hard conflicts &&
47 test_must_fail git merge master &&
48 echo one >main.txt &&
49 git add main.txt &&
50 cat >expected <<-\EOF &&
51 # On branch conflicts
52 # All conflicts fixed but you are still merging.
53 # (use "git commit" to conclude merge)
54 #
55 # Changes to be committed:
56 #
57 # modified: main.txt
58 #
59 # Untracked files not listed (use -u option to show untracked files)
60 EOF
61 git status --untracked-files=no >actual &&
62 test_i18ncmp expected actual
63'
64
65
66test_expect_success 'prepare for rebase conflicts' '
67 git reset --hard master &&
68 git checkout -b rebase_conflicts &&
69 test_commit one_rebase main.txt one &&
70 test_commit two_rebase main.txt two &&
71 test_commit three_rebase main.txt three
72'
73
74
75test_expect_success 'status when rebase in progress before resolving conflicts' '
76 test_when_finished "git rebase --abort" &&
77 ONTO=$(git rev-parse --short HEAD^^) &&
78 test_must_fail git rebase HEAD^ --onto HEAD^^ &&
79 cat >expected <<-EOF &&
80 # Not currently on any branch.
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
99test_expect_success 'status when rebase in progress before rebase --continue' '
100 git reset --hard rebase_conflicts &&
101 test_when_finished "git rebase --abort" &&
102 ONTO=$(git rev-parse --short HEAD^^) &&
103 test_must_fail git rebase HEAD^ --onto HEAD^^ &&
104 echo three >main.txt &&
105 git add main.txt &&
106 cat >expected <<-EOF &&
107 # Not currently on any branch.
108 # You are currently rebasing branch '\''rebase_conflicts'\'' on '\''$ONTO'\''.
109 # (all conflicts fixed: run "git rebase --continue")
110 #
111 # Changes to be committed:
112 # (use "git reset HEAD <file>..." to unstage)
113 #
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_i18ncmp expected actual
120'
121
122
123test_expect_success 'prepare for rebase_i_conflicts' '
124 git reset --hard master &&
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_master main.txt one_master &&
129 git checkout rebase_i_conflicts_second &&
130 test_commit one_second main.txt one_second
131'
132
133
134test_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 test_must_fail git rebase -i rebase_i_conflicts &&
138 cat >expected <<-EOF &&
139 # Not currently on any branch.
140 # You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
141 # (fix conflicts and then run "git rebase --continue")
142 # (use "git rebase --skip" to skip this patch)
143 # (use "git rebase --abort" to check out the original branch)
144 #
145 # Unmerged paths:
146 # (use "git reset HEAD <file>..." to unstage)
147 # (use "git add <file>..." to mark resolution)
148 #
149 # both modified: main.txt
150 #
151 no changes added to commit (use "git add" and/or "git commit -a")
152 EOF
153 git status --untracked-files=no >actual &&
154 test_i18ncmp expected actual
155'
156
157
158test_expect_success 'status during rebase -i after resolving conflicts' '
159 git reset --hard rebase_i_conflicts_second &&
160 test_when_finished "git rebase --abort" &&
161 ONTO=$(git rev-parse --short rebase_i_conflicts) &&
162 test_must_fail git rebase -i rebase_i_conflicts &&
163 git add main.txt &&
164 cat >expected <<-EOF &&
165 # Not currently on any branch.
166 # You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
167 # (all conflicts fixed: run "git rebase --continue")
168 #
169 # Changes to be committed:
170 # (use "git reset HEAD <file>..." to unstage)
171 #
172 # modified: main.txt
173 #
174 # Untracked files not listed (use -u option to show untracked files)
175 EOF
176 git status --untracked-files=no >actual &&
177 test_i18ncmp expected actual
178'
179
180
181test_expect_success 'status when rebasing -i in edit mode' '
182 git reset --hard master &&
183 git checkout -b rebase_i_edit &&
184 test_commit one_rebase_i main.txt one &&
185 test_commit two_rebase_i main.txt two &&
186 test_commit three_rebase_i main.txt three &&
187 FAKE_LINES="1 edit 2" &&
188 export FAKE_LINES &&
189 test_when_finished "git rebase --abort" &&
190 ONTO=$(git rev-parse --short HEAD~2) &&
191 git rebase -i HEAD~2 &&
192 cat >expected <<-EOF &&
193 # Not currently on any branch.
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)
197 #
198 nothing to commit (use -u to show untracked files)
199 EOF
200 git status --untracked-files=no >actual &&
201 test_i18ncmp expected actual
202'
203
204
205test_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" &&
213 export FAKE_LINES &&
214 test_when_finished "git rebase --abort" &&
215 ONTO=$(git rev-parse --short HEAD~3) &&
216 git rebase -i HEAD~3 &&
217 git reset HEAD^ &&
218 cat >expected <<-EOF &&
219 # Not currently on any branch.
220 # You are currently splitting a commit while rebasing branch '\''split_commit'\'' on '\''$ONTO'\''.
221 # (Once your working directory is clean, run "git rebase --continue")
222 #
223 # Changes not staged for commit:
224 # (use "git add <file>..." to update what will be committed)
225 # (use "git checkout -- <file>..." to discard changes in working directory)
226 #
227 # modified: main.txt
228 #
229 no changes added to commit (use "git add" and/or "git commit -a")
230 EOF
231 git status --untracked-files=no >actual &&
232 test_i18ncmp expected actual
233'
234
235
236test_expect_success 'status after editing the last commit with --amend during a rebase -i' '
237 git reset --hard master &&
238 git checkout -b amend_last &&
239 test_commit one_amend main.txt one &&
240 test_commit two_amend main.txt two &&
241 test_commit three_amend main.txt three &&
242 test_commit four_amend main.txt four &&
243 FAKE_LINES="1 2 edit 3" &&
244 export FAKE_LINES &&
245 test_when_finished "git rebase --abort" &&
246 ONTO=$(git rev-parse --short HEAD~3) &&
247 git rebase -i HEAD~3 &&
248 git commit --amend -m "foo" &&
249 cat >expected <<-EOF &&
250 # Not currently on any branch.
251 # You are currently editing a commit while rebasing branch '\''amend_last'\'' on '\''$ONTO'\''.
252 # (use "git commit --amend" to amend the current commit)
253 # (use "git rebase --continue" once you are satisfied with your changes)
254 #
255 nothing to commit (use -u to show untracked files)
256 EOF
257 git status --untracked-files=no >actual &&
258 test_i18ncmp expected actual
259'
260
261
262test_expect_success 'prepare for several edits' '
263 git reset --hard master &&
264 git checkout -b several_edits &&
265 test_commit one_edits main.txt one &&
266 test_commit two_edits main.txt two &&
267 test_commit three_edits main.txt three &&
268 test_commit four_edits main.txt four
269'
270
271
272test_expect_success 'status: (continue first edit) second edit' '
273 FAKE_LINES="edit 1 edit 2 3" &&
274 export FAKE_LINES &&
275 test_when_finished "git rebase --abort" &&
276 ONTO=$(git rev-parse --short HEAD~3) &&
277 git rebase -i HEAD~3 &&
278 git rebase --continue &&
279 cat >expected <<-EOF &&
280 # Not currently on any branch.
281 # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
282 # (use "git commit --amend" to amend the current commit)
283 # (use "git rebase --continue" once you are satisfied with your changes)
284 #
285 nothing to commit (use -u to show untracked files)
286 EOF
287 git status --untracked-files=no >actual &&
288 test_i18ncmp expected actual
289'
290
291
292test_expect_success 'status: (continue first edit) second edit and split' '
293 git reset --hard several_edits &&
294 FAKE_LINES="edit 1 edit 2 3" &&
295 export FAKE_LINES &&
296 test_when_finished "git rebase --abort" &&
297 ONTO=$(git rev-parse --short HEAD~3) &&
298 git rebase -i HEAD~3 &&
299 git rebase --continue &&
300 git reset HEAD^ &&
301 cat >expected <<-EOF &&
302 # Not currently on any branch.
303 # You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
304 # (Once your working directory is clean, run "git rebase --continue")
305 #
306 # Changes not staged for commit:
307 # (use "git add <file>..." to update what will be committed)
308 # (use "git checkout -- <file>..." to discard changes in working directory)
309 #
310 # modified: main.txt
311 #
312 no changes added to commit (use "git add" and/or "git commit -a")
313 EOF
314 git status --untracked-files=no >actual &&
315 test_i18ncmp expected actual
316'
317
318
319test_expect_success 'status: (continue first edit) second edit and amend' '
320 git reset --hard several_edits &&
321 FAKE_LINES="edit 1 edit 2 3" &&
322 export FAKE_LINES &&
323 test_when_finished "git rebase --abort" &&
324 ONTO=$(git rev-parse --short HEAD~3) &&
325 git rebase -i HEAD~3 &&
326 git rebase --continue &&
327 git commit --amend -m "foo" &&
328 cat >expected <<-EOF &&
329 # Not currently on any branch.
330 # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
331 # (use "git commit --amend" to amend the current commit)
332 # (use "git rebase --continue" once you are satisfied with your changes)
333 #
334 nothing to commit (use -u to show untracked files)
335 EOF
336 git status --untracked-files=no >actual &&
337 test_i18ncmp expected actual
338'
339
340
341test_expect_success 'status: (amend first edit) second edit' '
342 git reset --hard several_edits &&
343 FAKE_LINES="edit 1 edit 2 3" &&
344 export FAKE_LINES &&
345 test_when_finished "git rebase --abort" &&
346 ONTO=$(git rev-parse --short HEAD~3) &&
347 git rebase -i HEAD~3 &&
348 git commit --amend -m "a" &&
349 git rebase --continue &&
350 cat >expected <<-EOF &&
351 # Not currently on any branch.
352 # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
353 # (use "git commit --amend" to amend the current commit)
354 # (use "git rebase --continue" once you are satisfied with your changes)
355 #
356 nothing to commit (use -u to show untracked files)
357 EOF
358 git status --untracked-files=no >actual &&
359 test_i18ncmp expected actual
360'
361
362
363test_expect_success 'status: (amend first edit) second edit and split' '
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 ONTO=$(git rev-parse --short HEAD~3) &&
369 git rebase -i HEAD~3 &&
370 git commit --amend -m "b" &&
371 git rebase --continue &&
372 git reset HEAD^ &&
373 cat >expected <<-EOF &&
374 # Not currently on any branch.
375 # You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
376 # (Once your working directory is clean, run "git rebase --continue")
377 #
378 # Changes not staged for commit:
379 # (use "git add <file>..." to update what will be committed)
380 # (use "git checkout -- <file>..." to discard changes in working directory)
381 #
382 # modified: main.txt
383 #
384 no changes added to commit (use "git add" and/or "git commit -a")
385 EOF
386 git status --untracked-files=no >actual &&
387 test_i18ncmp expected actual
388'
389
390
391test_expect_success 'status: (amend first edit) second edit and amend' '
392 git reset --hard several_edits &&
393 FAKE_LINES="edit 1 edit 2 3" &&
394 export FAKE_LINES &&
395 test_when_finished "git rebase --abort" &&
396 ONTO=$(git rev-parse --short HEAD~3) &&
397 git rebase -i HEAD~3 &&
398 git commit --amend -m "c" &&
399 git rebase --continue &&
400 git commit --amend -m "d" &&
401 cat >expected <<-EOF &&
402 # Not currently on any branch.
403 # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
404 # (use "git commit --amend" to amend the current commit)
405 # (use "git rebase --continue" once you are satisfied with your changes)
406 #
407 nothing to commit (use -u to show untracked files)
408 EOF
409 git status --untracked-files=no >actual &&
410 test_i18ncmp expected actual
411'
412
413
414test_expect_success 'status: (split first edit) second edit' '
415 git reset --hard several_edits &&
416 FAKE_LINES="edit 1 edit 2 3" &&
417 export FAKE_LINES &&
418 test_when_finished "git rebase --abort" &&
419 ONTO=$(git rev-parse --short HEAD~3) &&
420 git rebase -i HEAD~3 &&
421 git reset HEAD^ &&
422 git add main.txt &&
423 git commit -m "e" &&
424 git rebase --continue &&
425 cat >expected <<-EOF &&
426 # Not currently on any branch.
427 # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
428 # (use "git commit --amend" to amend the current commit)
429 # (use "git rebase --continue" once you are satisfied with your changes)
430 #
431 nothing to commit (use -u to show untracked files)
432 EOF
433 git status --untracked-files=no >actual &&
434 test_i18ncmp expected actual
435'
436
437
438test_expect_success 'status: (split first edit) second edit and split' '
439 git reset --hard several_edits &&
440 FAKE_LINES="edit 1 edit 2 3" &&
441 export FAKE_LINES &&
442 test_when_finished "git rebase --abort" &&
443 ONTO=$(git rev-parse --short HEAD~3) &&
444 git rebase -i HEAD~3 &&
445 git reset HEAD^ &&
446 git add main.txt &&
447 git commit --amend -m "f" &&
448 git rebase --continue &&
449 git reset HEAD^ &&
450 cat >expected <<-EOF &&
451 # Not currently on any branch.
452 # You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
453 # (Once your working directory is clean, run "git rebase --continue")
454 #
455 # Changes not staged for commit:
456 # (use "git add <file>..." to update what will be committed)
457 # (use "git checkout -- <file>..." to discard changes in working directory)
458 #
459 # modified: main.txt
460 #
461 no changes added to commit (use "git add" and/or "git commit -a")
462 EOF
463 git status --untracked-files=no >actual &&
464 test_i18ncmp expected actual
465'
466
467
468test_expect_success 'status: (split first edit) second edit and amend' '
469 git reset --hard several_edits &&
470 FAKE_LINES="edit 1 edit 2 3" &&
471 export FAKE_LINES &&
472 test_when_finished "git rebase --abort" &&
473 ONTO=$(git rev-parse --short HEAD~3) &&
474 git rebase -i HEAD~3 &&
475 git reset HEAD^ &&
476 git add main.txt &&
477 git commit --amend -m "g" &&
478 git rebase --continue &&
479 git commit --amend -m "h" &&
480 cat >expected <<-EOF &&
481 # Not currently on any branch.
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_i18ncmp expected actual
490'
491
492
493test_expect_success 'prepare am_session' '
494 git reset --hard master &&
495 git checkout -b am_session &&
496 test_commit one_am one.txt "one" &&
497 test_commit two_am two.txt "two" &&
498 test_commit three_am three.txt "three"
499'
500
501
502test_expect_success 'status in an am session: file already exists' '
503 git checkout -b am_already_exists &&
504 test_when_finished "rm Maildir/* && git am --abort" &&
505 git format-patch -1 -oMaildir &&
506 test_must_fail git am Maildir/*.patch &&
507 cat >expected <<-\EOF &&
508 # On branch am_already_exists
509 # You are in the middle of an am session.
510 # (fix conflicts and then run "git am --resolved")
511 # (use "git am --skip" to skip this patch)
512 # (use "git am --abort" to restore the original branch)
513 #
514 nothing to commit (use -u to show untracked files)
515 EOF
516 git status --untracked-files=no >actual &&
517 test_i18ncmp expected actual
518'
519
520
521test_expect_success 'status in an am session: file does not exist' '
522 git reset --hard am_session &&
523 git checkout -b am_not_exists &&
524 git rm three.txt &&
525 git commit -m "delete three.txt" &&
526 test_when_finished "rm Maildir/* && git am --abort" &&
527 git format-patch -1 -oMaildir &&
528 test_must_fail git am Maildir/*.patch &&
529 cat >expected <<-\EOF &&
530 # On branch am_not_exists
531 # You are in the middle of an am session.
532 # (fix conflicts and then run "git am --resolved")
533 # (use "git am --skip" to skip this patch)
534 # (use "git am --abort" to restore the original branch)
535 #
536 nothing to commit (use -u to show untracked files)
537 EOF
538 git status --untracked-files=no >actual &&
539 test_i18ncmp expected actual
540'
541
542
543test_expect_success 'status in an am session: empty patch' '
544 git reset --hard am_session &&
545 git checkout -b am_empty &&
546 test_when_finished "rm Maildir/* && git am --abort" &&
547 git format-patch -3 -oMaildir &&
548 git rm one.txt two.txt three.txt &&
549 git commit -m "delete all am_empty" &&
550 echo error >Maildir/0002-two_am.patch &&
551 test_must_fail git am Maildir/*.patch &&
552 cat >expected <<-\EOF &&
553 # On branch am_empty
554 # You are in the middle of an am session.
555 # The current patch is empty.
556 # (use "git am --skip" to skip this patch)
557 # (use "git am --abort" to restore the original branch)
558 #
559 nothing to commit (use -u to show untracked files)
560 EOF
561 git status --untracked-files=no >actual &&
562 test_i18ncmp expected actual
563'
564
565
566test_expect_success 'status when bisecting' '
567 git reset --hard master &&
568 git checkout -b bisect &&
569 test_commit one_bisect main.txt one &&
570 test_commit two_bisect main.txt two &&
571 test_commit three_bisect main.txt three &&
572 test_when_finished "git bisect reset" &&
573 git bisect start &&
574 git bisect bad &&
575 git bisect good one_bisect &&
576 cat >expected <<-\EOF &&
577 # Not currently on any branch.
578 # You are currently bisecting branch '\''bisect'\''.
579 # (use "git bisect reset" to get back to the original branch)
580 #
581 nothing to commit (use -u to show untracked files)
582 EOF
583 git status --untracked-files=no >actual &&
584 test_i18ncmp expected actual
585'
586
587
588test_expect_success 'status when rebase conflicts with statushints disabled' '
589 git reset --hard master &&
590 git checkout -b statushints_disabled &&
591 test_when_finished "git config --local advice.statushints true" &&
592 git config --local advice.statushints false &&
593 test_commit one_statushints main.txt one &&
594 test_commit two_statushints main.txt two &&
595 test_commit three_statushints main.txt three &&
596 test_when_finished "git rebase --abort" &&
597 ONTO=$(git rev-parse --short HEAD^^) &&
598 test_must_fail git rebase HEAD^ --onto HEAD^^ &&
599 cat >expected <<-EOF &&
600 # Not currently on any branch.
601 # You are currently rebasing branch '\''statushints_disabled'\'' on '\''$ONTO'\''.
602 #
603 # Unmerged paths:
604 # both modified: main.txt
605 #
606 no changes added to commit
607 EOF
608 git status --untracked-files=no >actual &&
609 test_i18ncmp expected actual
610'
611
612
613test_expect_success 'prepare for cherry-pick conflicts' '
614 git reset --hard master &&
615 git checkout -b cherry_branch &&
616 test_commit one_cherry main.txt one &&
617 test_commit two_cherries main.txt two &&
618 git checkout -b cherry_branch_second &&
619 test_commit second_cherry main.txt second &&
620 git checkout cherry_branch &&
621 test_commit three_cherries main.txt three
622'
623
624
625test_expect_success 'status when cherry-picking before resolving conflicts' '
626 test_when_finished "git cherry-pick --abort" &&
627 test_must_fail git cherry-pick cherry_branch_second &&
628 cat >expected <<-\EOF &&
629 # On branch cherry_branch
630 # You are currently cherry-picking.
631 # (fix conflicts and run "git commit")
632 #
633 # Unmerged paths:
634 # (use "git add <file>..." to mark resolution)
635 #
636 # both modified: main.txt
637 #
638 no changes added to commit (use "git add" and/or "git commit -a")
639 EOF
640 git status --untracked-files=no >actual &&
641 test_i18ncmp expected actual
642'
643
644
645test_expect_success 'status when cherry-picking after resolving conflicts' '
646 git reset --hard cherry_branch &&
647 test_when_finished "git cherry-pick --abort" &&
648 test_must_fail git cherry-pick cherry_branch_second &&
649 echo end >main.txt &&
650 git add main.txt &&
651 cat >expected <<-\EOF &&
652 # On branch cherry_branch
653 # You are currently cherry-picking.
654 # (all conflicts fixed: run "git commit")
655 #
656 # Changes to be committed:
657 #
658 # modified: main.txt
659 #
660 # Untracked files not listed (use -u option to show untracked files)
661 EOF
662 git status --untracked-files=no >actual &&
663 test_i18ncmp expected actual
664'
665
666
667test_done