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