t9903: add tests for git-prompt pcmode
[git.git] / t / t9903-bash-prompt.sh
blob6a88778fe64ec653a3d745c0237cd736feb4a795
1 #!/bin/sh
3 # Copyright (c) 2012 SZEDER Gábor
6 test_description='test git-specific bash prompt functions'
8 . ./lib-bash.sh
10 . "$GIT_BUILD_DIR/contrib/completion/git-prompt.sh"
12 actual="$TRASH_DIRECTORY/actual"
13 c_red='\\[\\e[31m\\]'
14 c_green='\\[\\e[32m\\]'
15 c_lblue='\\[\\e[1;34m\\]'
16 c_clear='\\[\\e[0m\\]'
18 test_expect_success 'setup for prompt tests' '
19 mkdir -p subdir/subsubdir &&
20 git init otherrepo &&
21 echo 1 > file &&
22 git add file &&
23 test_tick &&
24 git commit -m initial &&
25 git tag -a -m msg1 t1 &&
26 git checkout -b b1 &&
27 echo 2 > file &&
28 git commit -m "second b1" file &&
29 echo 3 > file &&
30 git commit -m "third b1" file &&
31 git tag -a -m msg2 t2 &&
32 git checkout -b b2 master &&
33 echo 0 > file &&
34 git commit -m "second b2" file &&
35 echo 00 > file &&
36 git commit -m "another b2" file &&
37 echo 000 > file &&
38 git commit -m "yet another b2" file &&
39 git checkout master
42 test_expect_success 'gitdir - from command line (through $__git_dir)' '
43 echo "$TRASH_DIRECTORY/otherrepo/.git" > expected &&
45 __git_dir="$TRASH_DIRECTORY/otherrepo/.git" &&
46 __gitdir > "$actual"
47 ) &&
48 test_cmp expected "$actual"
51 test_expect_success 'gitdir - repo as argument' '
52 echo "otherrepo/.git" > expected &&
53 __gitdir "otherrepo" > "$actual" &&
54 test_cmp expected "$actual"
57 test_expect_success 'gitdir - remote as argument' '
58 echo "remote" > expected &&
59 __gitdir "remote" > "$actual" &&
60 test_cmp expected "$actual"
63 test_expect_success 'gitdir - .git directory in cwd' '
64 echo ".git" > expected &&
65 __gitdir > "$actual" &&
66 test_cmp expected "$actual"
69 test_expect_success 'gitdir - .git directory in parent' '
70 echo "$(pwd -P)/.git" > expected &&
72 cd subdir/subsubdir &&
73 __gitdir > "$actual"
74 ) &&
75 test_cmp expected "$actual"
78 test_expect_success 'gitdir - cwd is a .git directory' '
79 echo "." > expected &&
81 cd .git &&
82 __gitdir > "$actual"
83 ) &&
84 test_cmp expected "$actual"
87 test_expect_success 'gitdir - parent is a .git directory' '
88 echo "$(pwd -P)/.git" > expected &&
90 cd .git/refs/heads &&
91 __gitdir > "$actual"
92 ) &&
93 test_cmp expected "$actual"
96 test_expect_success 'gitdir - $GIT_DIR set while .git directory in cwd' '
97 echo "$TRASH_DIRECTORY/otherrepo/.git" > expected &&
99 GIT_DIR="$TRASH_DIRECTORY/otherrepo/.git" &&
100 export GIT_DIR &&
101 __gitdir > "$actual"
102 ) &&
103 test_cmp expected "$actual"
106 test_expect_success 'gitdir - $GIT_DIR set while .git directory in parent' '
107 echo "$TRASH_DIRECTORY/otherrepo/.git" > expected &&
109 GIT_DIR="$TRASH_DIRECTORY/otherrepo/.git" &&
110 export GIT_DIR &&
111 cd subdir &&
112 __gitdir > "$actual"
113 ) &&
114 test_cmp expected "$actual"
117 test_expect_success 'gitdir - non-existing $GIT_DIR' '
119 GIT_DIR="$TRASH_DIRECTORY/non-existing" &&
120 export GIT_DIR &&
121 test_must_fail __gitdir
125 test_expect_success 'gitdir - gitfile in cwd' '
126 echo "$(pwd -P)/otherrepo/.git" > expected &&
127 echo "gitdir: $TRASH_DIRECTORY/otherrepo/.git" > subdir/.git &&
128 test_when_finished "rm -f subdir/.git" &&
130 cd subdir &&
131 __gitdir > "$actual"
132 ) &&
133 test_cmp expected "$actual"
136 test_expect_success 'gitdir - gitfile in parent' '
137 echo "$(pwd -P)/otherrepo/.git" > expected &&
138 echo "gitdir: $TRASH_DIRECTORY/otherrepo/.git" > subdir/.git &&
139 test_when_finished "rm -f subdir/.git" &&
141 cd subdir/subsubdir &&
142 __gitdir > "$actual"
143 ) &&
144 test_cmp expected "$actual"
147 test_expect_success SYMLINKS 'gitdir - resulting path avoids symlinks' '
148 echo "$(pwd -P)/otherrepo/.git" > expected &&
149 mkdir otherrepo/dir &&
150 test_when_finished "rm -rf otherrepo/dir" &&
151 ln -s otherrepo/dir link &&
152 test_when_finished "rm -f link" &&
154 cd link &&
155 __gitdir > "$actual"
156 ) &&
157 test_cmp expected "$actual"
160 test_expect_success 'gitdir - not a git repository' '
162 cd subdir/subsubdir &&
163 GIT_CEILING_DIRECTORIES="$TRASH_DIRECTORY" &&
164 export GIT_CEILING_DIRECTORIES &&
165 test_must_fail __gitdir
169 test_expect_success 'prompt - branch name' '
170 printf " (master)" > expected &&
171 __git_ps1 > "$actual" &&
172 test_cmp expected "$actual"
175 test_expect_success 'prompt - detached head' '
176 printf " ((%s...))" $(git log -1 --format="%h" b1^) > expected &&
177 git checkout b1^ &&
178 test_when_finished "git checkout master" &&
179 __git_ps1 > "$actual" &&
180 test_cmp expected "$actual"
183 test_expect_success 'prompt - describe detached head - contains' '
184 printf " ((t2~1))" > expected &&
185 git checkout b1^ &&
186 test_when_finished "git checkout master" &&
188 GIT_PS1_DESCRIBE_STYLE=contains &&
189 __git_ps1 > "$actual"
190 ) &&
191 test_cmp expected "$actual"
194 test_expect_success 'prompt - describe detached head - branch' '
195 printf " ((b1~1))" > expected &&
196 git checkout b1^ &&
197 test_when_finished "git checkout master" &&
199 GIT_PS1_DESCRIBE_STYLE=branch &&
200 __git_ps1 > "$actual"
201 ) &&
202 test_cmp expected "$actual"
205 test_expect_success 'prompt - describe detached head - describe' '
206 printf " ((t1-1-g%s))" $(git log -1 --format="%h" b1^) > expected &&
207 git checkout b1^ &&
208 test_when_finished "git checkout master" &&
210 GIT_PS1_DESCRIBE_STYLE=describe &&
211 __git_ps1 > "$actual"
212 ) &&
213 test_cmp expected "$actual"
216 test_expect_success 'prompt - describe detached head - default' '
217 printf " ((t2))" > expected &&
218 git checkout --detach b1 &&
219 test_when_finished "git checkout master" &&
220 __git_ps1 > "$actual" &&
221 test_cmp expected "$actual"
224 test_expect_success 'prompt - inside .git directory' '
225 printf " (GIT_DIR!)" > expected &&
227 cd .git &&
228 __git_ps1 > "$actual"
229 ) &&
230 test_cmp expected "$actual"
233 test_expect_success 'prompt - deep inside .git directory' '
234 printf " (GIT_DIR!)" > expected &&
236 cd .git/refs/heads &&
237 __git_ps1 > "$actual"
238 ) &&
239 test_cmp expected "$actual"
242 test_expect_success 'prompt - inside bare repository' '
243 printf " (BARE:master)" > expected &&
244 git init --bare bare.git &&
245 test_when_finished "rm -rf bare.git" &&
247 cd bare.git &&
248 __git_ps1 > "$actual"
249 ) &&
250 test_cmp expected "$actual"
253 test_expect_success 'prompt - interactive rebase' '
254 printf " (b1|REBASE-i 2/3)" > expected
255 echo "#!$SHELL_PATH" >fake_editor.sh &&
256 cat >>fake_editor.sh <<\EOF &&
257 echo "exec echo" > "$1"
258 echo "edit $(git log -1 --format="%h")" >> "$1"
259 echo "exec echo" >> "$1"
261 test_when_finished "rm -f fake_editor.sh" &&
262 chmod a+x fake_editor.sh &&
263 test_set_editor "$TRASH_DIRECTORY/fake_editor.sh" &&
264 git checkout b1 &&
265 test_when_finished "git checkout master" &&
266 git rebase -i HEAD^ &&
267 test_when_finished "git rebase --abort"
268 __git_ps1 > "$actual" &&
269 test_cmp expected "$actual"
272 test_expect_success 'prompt - rebase merge' '
273 printf " (b2|REBASE-m 1/3)" > expected &&
274 git checkout b2 &&
275 test_when_finished "git checkout master" &&
276 test_must_fail git rebase --merge b1 b2 &&
277 test_when_finished "git rebase --abort" &&
278 __git_ps1 > "$actual" &&
279 test_cmp expected "$actual"
282 test_expect_success 'prompt - rebase' '
283 printf " (b2|REBASE 1/3)" > expected &&
284 git checkout b2 &&
285 test_when_finished "git checkout master" &&
286 test_must_fail git rebase b1 b2 &&
287 test_when_finished "git rebase --abort" &&
288 __git_ps1 > "$actual" &&
289 test_cmp expected "$actual"
292 test_expect_success 'prompt - merge' '
293 printf " (b1|MERGING)" > expected &&
294 git checkout b1 &&
295 test_when_finished "git checkout master" &&
296 test_must_fail git merge b2 &&
297 test_when_finished "git reset --hard" &&
298 __git_ps1 > "$actual" &&
299 test_cmp expected "$actual"
302 test_expect_success 'prompt - cherry-pick' '
303 printf " (master|CHERRY-PICKING)" > expected &&
304 test_must_fail git cherry-pick b1 &&
305 test_when_finished "git reset --hard" &&
306 __git_ps1 > "$actual" &&
307 test_cmp expected "$actual"
310 test_expect_success 'prompt - bisect' '
311 printf " (master|BISECTING)" > expected &&
312 git bisect start &&
313 test_when_finished "git bisect reset" &&
314 __git_ps1 > "$actual" &&
315 test_cmp expected "$actual"
318 test_expect_success 'prompt - dirty status indicator - clean' '
319 printf " (master)" > expected &&
321 GIT_PS1_SHOWDIRTYSTATE=y &&
322 __git_ps1 > "$actual"
323 ) &&
324 test_cmp expected "$actual"
327 test_expect_success 'prompt - dirty status indicator - dirty worktree' '
328 printf " (master *)" > expected &&
329 echo "dirty" > file &&
330 test_when_finished "git reset --hard" &&
332 GIT_PS1_SHOWDIRTYSTATE=y &&
333 __git_ps1 > "$actual"
334 ) &&
335 test_cmp expected "$actual"
338 test_expect_success 'prompt - dirty status indicator - dirty index' '
339 printf " (master +)" > expected &&
340 echo "dirty" > file &&
341 test_when_finished "git reset --hard" &&
342 git add -u &&
344 GIT_PS1_SHOWDIRTYSTATE=y &&
345 __git_ps1 > "$actual"
346 ) &&
347 test_cmp expected "$actual"
350 test_expect_success 'prompt - dirty status indicator - dirty index and worktree' '
351 printf " (master *+)" > expected &&
352 echo "dirty index" > file &&
353 test_when_finished "git reset --hard" &&
354 git add -u &&
355 echo "dirty worktree" > file &&
357 GIT_PS1_SHOWDIRTYSTATE=y &&
358 __git_ps1 > "$actual"
359 ) &&
360 test_cmp expected "$actual"
363 test_expect_success 'prompt - dirty status indicator - before root commit' '
364 printf " (master #)" > expected &&
366 GIT_PS1_SHOWDIRTYSTATE=y &&
367 cd otherrepo &&
368 __git_ps1 > "$actual"
369 ) &&
370 test_cmp expected "$actual"
373 test_expect_success 'prompt - dirty status indicator - shell variable unset with config disabled' '
374 printf " (master)" > expected &&
375 echo "dirty" > file &&
376 test_when_finished "git reset --hard" &&
377 test_config bash.showDirtyState false &&
379 sane_unset GIT_PS1_SHOWDIRTYSTATE &&
380 __git_ps1 > "$actual"
381 ) &&
382 test_cmp expected "$actual"
385 test_expect_success 'prompt - dirty status indicator - shell variable unset with config enabled' '
386 printf " (master)" > expected &&
387 echo "dirty" > file &&
388 test_when_finished "git reset --hard" &&
389 test_config bash.showDirtyState true &&
391 sane_unset GIT_PS1_SHOWDIRTYSTATE &&
392 __git_ps1 > "$actual"
393 ) &&
394 test_cmp expected "$actual"
397 test_expect_success 'prompt - dirty status indicator - shell variable set with config disabled' '
398 printf " (master)" > expected &&
399 echo "dirty" > file &&
400 test_when_finished "git reset --hard" &&
401 test_config bash.showDirtyState false &&
403 GIT_PS1_SHOWDIRTYSTATE=y &&
404 __git_ps1 > "$actual"
405 ) &&
406 test_cmp expected "$actual"
409 test_expect_success 'prompt - dirty status indicator - shell variable set with config enabled' '
410 printf " (master *)" > expected &&
411 echo "dirty" > file &&
412 test_when_finished "git reset --hard" &&
413 test_config bash.showDirtyState true &&
415 GIT_PS1_SHOWDIRTYSTATE=y &&
416 __git_ps1 > "$actual"
417 ) &&
418 test_cmp expected "$actual"
421 test_expect_success 'prompt - dirty status indicator - not shown inside .git directory' '
422 printf " (GIT_DIR!)" > expected &&
423 echo "dirty" > file &&
424 test_when_finished "git reset --hard" &&
426 GIT_PS1_SHOWDIRTYSTATE=y &&
427 cd .git &&
428 __git_ps1 > "$actual"
429 ) &&
430 test_cmp expected "$actual"
433 test_expect_success 'prompt - stash status indicator - no stash' '
434 printf " (master)" > expected &&
436 GIT_PS1_SHOWSTASHSTATE=y &&
437 __git_ps1 > "$actual"
438 ) &&
439 test_cmp expected "$actual"
442 test_expect_success 'prompt - stash status indicator - stash' '
443 printf " (master $)" > expected &&
444 echo 2 >file &&
445 git stash &&
446 test_when_finished "git stash drop" &&
448 GIT_PS1_SHOWSTASHSTATE=y &&
449 __git_ps1 > "$actual"
450 ) &&
451 test_cmp expected "$actual"
454 test_expect_success 'prompt - stash status indicator - not shown inside .git directory' '
455 printf " (GIT_DIR!)" > expected &&
456 echo 2 >file &&
457 git stash &&
458 test_when_finished "git stash drop" &&
460 GIT_PS1_SHOWSTASHSTATE=y &&
461 cd .git &&
462 __git_ps1 > "$actual"
463 ) &&
464 test_cmp expected "$actual"
467 test_expect_success 'prompt - untracked files status indicator - no untracked files' '
468 printf " (master)" > expected &&
470 GIT_PS1_SHOWUNTRACKEDFILES=y &&
471 cd otherrepo &&
472 __git_ps1 > "$actual"
473 ) &&
474 test_cmp expected "$actual"
477 test_expect_success 'prompt - untracked files status indicator - untracked files' '
478 printf " (master %%)" > expected &&
480 GIT_PS1_SHOWUNTRACKEDFILES=y &&
481 __git_ps1 > "$actual"
482 ) &&
483 test_cmp expected "$actual"
486 test_expect_success 'prompt - untracked files status indicator - shell variable unset with config disabled' '
487 printf " (master)" > expected &&
488 test_config bash.showUntrackedFiles false &&
490 sane_unset GIT_PS1_SHOWUNTRACKEDFILES &&
491 __git_ps1 > "$actual"
492 ) &&
493 test_cmp expected "$actual"
496 test_expect_success 'prompt - untracked files status indicator - shell variable unset with config enabled' '
497 printf " (master)" > expected &&
498 test_config bash.showUntrackedFiles true &&
500 sane_unset GIT_PS1_SHOWUNTRACKEDFILES &&
501 __git_ps1 > "$actual"
502 ) &&
503 test_cmp expected "$actual"
506 test_expect_success 'prompt - untracked files status indicator - shell variable set with config disabled' '
507 printf " (master)" > expected &&
508 test_config bash.showUntrackedFiles false &&
510 GIT_PS1_SHOWUNTRACKEDFILES=y &&
511 __git_ps1 > "$actual"
512 ) &&
513 test_cmp expected "$actual"
516 test_expect_success 'prompt - untracked files status indicator - shell variable set with config enabled' '
517 printf " (master %%)" > expected &&
518 test_config bash.showUntrackedFiles true &&
520 GIT_PS1_SHOWUNTRACKEDFILES=y &&
521 __git_ps1 > "$actual"
522 ) &&
523 test_cmp expected "$actual"
526 test_expect_success 'prompt - untracked files status indicator - not shown inside .git directory' '
527 printf " (GIT_DIR!)" > expected &&
529 GIT_PS1_SHOWUNTRACKEDFILES=y &&
530 cd .git &&
531 __git_ps1 > "$actual"
532 ) &&
533 test_cmp expected "$actual"
536 test_expect_success 'prompt - format string starting with dash' '
537 printf -- "-master" > expected &&
538 __git_ps1 "-%s" > "$actual" &&
539 test_cmp expected "$actual"
542 test_expect_success 'prompt - pc mode' '
543 printf "BEFORE: (master):AFTER" >expected &&
544 printf "" >expected_output &&
546 __git_ps1 "BEFORE:" ":AFTER" >"$actual" &&
547 test_cmp expected_output "$actual" &&
548 printf "%s" "$PS1" >"$actual"
549 ) &&
550 test_cmp expected "$actual"
553 test_expect_success 'prompt - bash color pc mode - branch name' '
554 printf "BEFORE: (${c_green}master${c_clear}${c_clear}):AFTER" >expected &&
556 GIT_PS1_SHOWCOLORHINTS=y &&
557 __git_ps1 "BEFORE:" ":AFTER" >"$actual"
558 printf "%s" "$PS1" >"$actual"
559 ) &&
560 test_cmp expected "$actual"
563 test_expect_success 'prompt - bash color pc mode - detached head' '
564 printf "BEFORE: (${c_red}(%s...)${c_clear}${c_clear}):AFTER" $(git log -1 --format="%h" b1^) >expected &&
565 git checkout b1^ &&
566 test_when_finished "git checkout master" &&
568 GIT_PS1_SHOWCOLORHINTS=y &&
569 __git_ps1 "BEFORE:" ":AFTER" &&
570 printf "%s" "$PS1" >"$actual"
571 ) &&
572 test_cmp expected "$actual"
575 test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty worktree' '
576 printf "BEFORE: (${c_green}master${c_clear} ${c_red}*${c_clear}):AFTER" >expected &&
577 echo "dirty" >file &&
578 test_when_finished "git reset --hard" &&
580 GIT_PS1_SHOWDIRTYSTATE=y &&
581 GIT_PS1_SHOWCOLORHINTS=y &&
582 __git_ps1 "BEFORE:" ":AFTER" &&
583 printf "%s" "$PS1" >"$actual"
584 ) &&
585 test_cmp expected "$actual"
588 test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index' '
589 printf "BEFORE: (${c_green}master${c_clear} ${c_green}+${c_clear}):AFTER" >expected &&
590 echo "dirty" >file &&
591 test_when_finished "git reset --hard" &&
592 git add -u &&
594 GIT_PS1_SHOWDIRTYSTATE=y &&
595 GIT_PS1_SHOWCOLORHINTS=y &&
596 __git_ps1 "BEFORE:" ":AFTER" &&
597 printf "%s" "$PS1" >"$actual"
598 ) &&
599 test_cmp expected "$actual"
602 test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index and worktree' '
603 printf "BEFORE: (${c_green}master${c_clear} ${c_red}*${c_green}+${c_clear}):AFTER" >expected &&
604 echo "dirty index" >file &&
605 test_when_finished "git reset --hard" &&
606 git add -u &&
607 echo "dirty worktree" >file &&
609 GIT_PS1_SHOWCOLORHINTS=y &&
610 GIT_PS1_SHOWDIRTYSTATE=y &&
611 __git_ps1 "BEFORE:" ":AFTER" &&
612 printf "%s" "$PS1" >"$actual"
613 ) &&
614 test_cmp expected "$actual"
617 test_expect_success 'prompt - bash color pc mode - dirty status indicator - before root commit' '
618 printf "BEFORE: (${c_green}master${c_clear} ${c_green}#${c_clear}):AFTER" >expected &&
620 GIT_PS1_SHOWDIRTYSTATE=y &&
621 GIT_PS1_SHOWCOLORHINTS=y &&
622 cd otherrepo &&
623 __git_ps1 "BEFORE:" ":AFTER" &&
624 printf "%s" "$PS1" >"$actual"
625 ) &&
626 test_cmp expected "$actual"
629 test_expect_success 'prompt - bash color pc mode - inside .git directory' '
630 printf "BEFORE: (${c_green}GIT_DIR!${c_clear}${c_clear}):AFTER" >expected &&
631 echo "dirty" >file &&
632 test_when_finished "git reset --hard" &&
634 GIT_PS1_SHOWDIRTYSTATE=y &&
635 GIT_PS1_SHOWCOLORHINTS=y &&
636 cd .git &&
637 __git_ps1 "BEFORE:" ":AFTER" &&
638 printf "%s" "$PS1" >"$actual"
639 ) &&
640 test_cmp expected "$actual"
643 test_expect_success 'prompt - bash color pc mode - stash status indicator' '
644 printf "BEFORE: (${c_green}master${c_clear} ${c_lblue}\$${c_clear}):AFTER" >expected &&
645 echo 2 >file &&
646 git stash &&
647 test_when_finished "git stash drop" &&
649 GIT_PS1_SHOWSTASHSTATE=y &&
650 GIT_PS1_SHOWCOLORHINTS=y &&
651 __git_ps1 "BEFORE:" ":AFTER" &&
652 printf "%s" "$PS1" >"$actual"
653 ) &&
654 test_cmp expected "$actual"
657 test_expect_success 'prompt - bash color pc mode - untracked files status indicator' '
658 printf "BEFORE: (${c_green}master${c_clear} ${c_red}%%${c_clear}):AFTER" >expected &&
660 GIT_PS1_SHOWUNTRACKEDFILES=y &&
661 GIT_PS1_SHOWCOLORHINTS=y &&
662 __git_ps1 "BEFORE:" ":AFTER" &&
663 printf "%s" "$PS1" >"$actual"
664 ) &&
665 test_cmp expected "$actual"
668 test_expect_success 'prompt - zsh color pc mode - branch name' '
669 printf "BEFORE: (%%F{green}master%%f%%f):AFTER" >expected &&
671 ZSH_VERSION=5.0.0 &&
672 GIT_PS1_SHOWCOLORHINTS=y &&
673 __git_ps1 "BEFORE:" ":AFTER" >"$actual"
674 printf "%s" "$PS1" >"$actual"
675 ) &&
676 test_cmp expected "$actual"
679 test_expect_success 'prompt - zsh color pc mode - detached head' '
680 printf "BEFORE: (%%F{red}(%s...)%%f%%f):AFTER" $(git log -1 --format="%h" b1^) >expected &&
681 git checkout b1^ &&
682 test_when_finished "git checkout master" &&
684 ZSH_VERSION=5.0.0 &&
685 GIT_PS1_SHOWCOLORHINTS=y &&
686 __git_ps1 "BEFORE:" ":AFTER" &&
687 printf "%s" "$PS1" >"$actual"
688 ) &&
689 test_cmp expected "$actual"
692 test_expect_success 'prompt - zsh color pc mode - dirty status indicator - dirty worktree' '
693 printf "BEFORE: (%%F{green}master%%f %%F{red}*%%f):AFTER" >expected &&
694 echo "dirty" >file &&
695 test_when_finished "git reset --hard" &&
697 ZSH_VERSION=5.0.0 &&
698 GIT_PS1_SHOWDIRTYSTATE=y &&
699 GIT_PS1_SHOWCOLORHINTS=y &&
700 __git_ps1 "BEFORE:" ":AFTER" &&
701 printf "%s" "$PS1" >"$actual"
702 ) &&
703 test_cmp expected "$actual"
706 test_expect_success 'prompt - zsh color pc mode - dirty status indicator - dirty index' '
707 printf "BEFORE: (%%F{green}master%%f %%F{green}+%%f):AFTER" >expected &&
708 echo "dirty" >file &&
709 test_when_finished "git reset --hard" &&
710 git add -u &&
712 ZSH_VERSION=5.0.0 &&
713 GIT_PS1_SHOWDIRTYSTATE=y &&
714 GIT_PS1_SHOWCOLORHINTS=y &&
715 __git_ps1 "BEFORE:" ":AFTER" &&
716 printf "%s" "$PS1" >"$actual"
717 ) &&
718 test_cmp expected "$actual"
721 test_expect_success 'prompt - zsh color pc mode - dirty status indicator - dirty index and worktree' '
722 printf "BEFORE: (%%F{green}master%%f %%F{red}*%%F{green}+%%f):AFTER" >expected &&
723 echo "dirty index" >file &&
724 test_when_finished "git reset --hard" &&
725 git add -u &&
726 echo "dirty worktree" >file &&
728 ZSH_VERSION=5.0.0 &&
729 GIT_PS1_SHOWCOLORHINTS=y &&
730 GIT_PS1_SHOWDIRTYSTATE=y &&
731 __git_ps1 "BEFORE:" ":AFTER" &&
732 printf "%s" "$PS1" >"$actual"
733 ) &&
734 test_cmp expected "$actual"
737 test_expect_success 'prompt - zsh color pc mode - dirty status indicator - before root commit' '
738 printf "BEFORE: (%%F{green}master%%f %%F{green}#%%f):AFTER" >expected &&
740 ZSH_VERSION=5.0.0 &&
741 GIT_PS1_SHOWDIRTYSTATE=y &&
742 GIT_PS1_SHOWCOLORHINTS=y &&
743 cd otherrepo &&
744 __git_ps1 "BEFORE:" ":AFTER" &&
745 printf "%s" "$PS1" >"$actual"
746 ) &&
747 test_cmp expected "$actual"
750 test_expect_success 'prompt - zsh color pc mode - inside .git directory' '
751 printf "BEFORE: (%%F{green}GIT_DIR!%%f%%f):AFTER" >expected &&
752 echo "dirty" >file &&
753 test_when_finished "git reset --hard" &&
755 ZSH_VERSION=5.0.0 &&
756 GIT_PS1_SHOWDIRTYSTATE=y &&
757 GIT_PS1_SHOWCOLORHINTS=y &&
758 cd .git &&
759 __git_ps1 "BEFORE:" ":AFTER" &&
760 printf "%s" "$PS1" >"$actual"
761 ) &&
762 test_cmp expected "$actual"
765 test_expect_success 'prompt - zsh color pc mode - stash status indicator' '
766 printf "BEFORE: (%%F{green}master%%f %%F{blue}$%%f):AFTER" >expected &&
767 echo 2 >file &&
768 git stash &&
769 test_when_finished "git stash drop" &&
771 ZSH_VERSION=5.0.0 &&
772 GIT_PS1_SHOWSTASHSTATE=y &&
773 GIT_PS1_SHOWCOLORHINTS=y &&
774 __git_ps1 "BEFORE:" ":AFTER" &&
775 printf "%s" "$PS1" >"$actual"
776 ) &&
777 test_cmp expected "$actual"
780 test_expect_success 'prompt - zsh color pc mode - untracked files status indicator' '
781 printf "BEFORE: (%%F{green}master%%f %%F{red}%%%%%%f):AFTER" >expected &&
783 ZSH_VERSION=5.0.0 &&
784 GIT_PS1_SHOWUNTRACKEDFILES=y &&
785 GIT_PS1_SHOWCOLORHINTS=y &&
786 __git_ps1 "BEFORE:" ":AFTER" &&
787 printf "%s" "$PS1" >"$actual"
788 ) &&
789 test_cmp expected "$actual"
792 test_done