The second batch
[git] / t / t9903-bash-prompt.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2012 SZEDER Gábor
4 #
5
6 test_description='test git-specific bash prompt functions'
7
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10
11 . ./lib-bash.sh
12
13 . "$GIT_BUILD_DIR/contrib/completion/git-prompt.sh"
14
15 actual="$TRASH_DIRECTORY/actual"
16 c_red='\\[\\e[31m\\]'
17 c_green='\\[\\e[32m\\]'
18 c_lblue='\\[\\e[1;34m\\]'
19 c_clear='\\[\\e[0m\\]'
20
21 test_expect_success 'setup for prompt tests' '
22         git init otherrepo &&
23         echo 1 >file &&
24         git add file &&
25         test_tick &&
26         git commit -m initial &&
27         git tag -a -m msg1 t1 &&
28         git checkout -b b1 &&
29         echo 2 >file &&
30         git commit -m "second b1" file &&
31         echo 3 >file &&
32         git commit -m "third b1" file &&
33         git tag -a -m msg2 t2 &&
34         git checkout -b b2 main &&
35         echo 0 >file &&
36         git commit -m "second b2" file &&
37         echo 00 >file &&
38         git commit -m "another b2" file &&
39         echo 000 >file &&
40         git commit -m "yet another b2" file &&
41         mkdir ignored_dir &&
42         echo "ignored_dir/" >>.gitignore &&
43         git checkout main
44 '
45
46 test_expect_success 'prompt - branch name' '
47         printf " (main)" >expected &&
48         __git_ps1 >"$actual" &&
49         test_cmp expected "$actual"
50 '
51
52 test_expect_success SYMLINKS 'prompt - branch name - symlink symref' '
53         printf " (main)" >expected &&
54         test_when_finished "git checkout main" &&
55         test_config core.preferSymlinkRefs true &&
56         git checkout main &&
57         __git_ps1 >"$actual" &&
58         test_cmp expected "$actual"
59 '
60
61 test_expect_success 'prompt - unborn branch' '
62         printf " (unborn)" >expected &&
63         git checkout --orphan unborn &&
64         test_when_finished "git checkout main" &&
65         __git_ps1 >"$actual" &&
66         test_cmp expected "$actual"
67 '
68
69 if test_have_prereq !FUNNYNAMES; then
70         say 'Your filesystem does not allow newlines in filenames.'
71 fi
72
73 test_expect_success FUNNYNAMES 'prompt - with newline in path' '
74     repo_with_newline="repo
75 with
76 newline" &&
77         mkdir "$repo_with_newline" &&
78         printf " (main)" >expected &&
79         git init "$repo_with_newline" &&
80         test_when_finished "rm -rf \"$repo_with_newline\"" &&
81         mkdir "$repo_with_newline"/subdir &&
82         (
83                 cd "$repo_with_newline/subdir" &&
84                 __git_ps1 >"$actual"
85         ) &&
86         test_cmp expected "$actual"
87 '
88
89 test_expect_success 'prompt - detached head' '
90         printf " ((%s...))" $(git log -1 --format="%h" --abbrev=13 b1^) >expected &&
91         test_config core.abbrev 13 &&
92         git checkout b1^ &&
93         test_when_finished "git checkout main" &&
94         __git_ps1 >"$actual" &&
95         test_cmp expected "$actual"
96 '
97
98 test_expect_success 'prompt - describe detached head - contains' '
99         printf " ((t2~1))" >expected &&
100         git checkout b1^ &&
101         test_when_finished "git checkout main" &&
102         (
103                 GIT_PS1_DESCRIBE_STYLE=contains &&
104                 __git_ps1 >"$actual"
105         ) &&
106         test_cmp expected "$actual"
107 '
108
109 test_expect_success 'prompt - describe detached head - branch' '
110         printf " ((tags/t2~1))" >expected &&
111         git checkout b1^ &&
112         test_when_finished "git checkout main" &&
113         (
114                 GIT_PS1_DESCRIBE_STYLE=branch &&
115                 __git_ps1 >"$actual"
116         ) &&
117         test_cmp expected "$actual"
118 '
119
120 test_expect_success 'prompt - describe detached head - describe' '
121         printf " ((t1-1-g%s))" $(git log -1 --format="%h" b1^) >expected &&
122         git checkout b1^ &&
123         test_when_finished "git checkout main" &&
124         (
125                 GIT_PS1_DESCRIBE_STYLE=describe &&
126                 __git_ps1 >"$actual"
127         ) &&
128         test_cmp expected "$actual"
129 '
130
131 test_expect_success 'prompt - describe detached head - default' '
132         printf " ((t2))" >expected &&
133         git checkout --detach b1 &&
134         test_when_finished "git checkout main" &&
135         __git_ps1 >"$actual" &&
136         test_cmp expected "$actual"
137 '
138
139 test_expect_success 'prompt - inside .git directory' '
140         printf " (GIT_DIR!)" >expected &&
141         (
142                 cd .git &&
143                 __git_ps1 >"$actual"
144         ) &&
145         test_cmp expected "$actual"
146 '
147
148 test_expect_success 'prompt - deep inside .git directory' '
149         printf " (GIT_DIR!)" >expected &&
150         (
151                 cd .git/objects &&
152                 __git_ps1 >"$actual"
153         ) &&
154         test_cmp expected "$actual"
155 '
156
157 test_expect_success 'prompt - inside bare repository' '
158         printf " (BARE:main)" >expected &&
159         git init --bare bare.git &&
160         test_when_finished "rm -rf bare.git" &&
161         (
162                 cd bare.git &&
163                 __git_ps1 >"$actual"
164         ) &&
165         test_cmp expected "$actual"
166 '
167
168 test_expect_success 'prompt - interactive rebase' '
169         printf " (b1|REBASE 2/3)" >expected &&
170         write_script fake_editor.sh <<-\EOF &&
171                 echo "exec echo" >"$1"
172                 echo "edit $(git log -1 --format="%h")" >>"$1"
173                 echo "exec echo" >>"$1"
174         EOF
175         test_when_finished "rm -f fake_editor.sh" &&
176         test_set_editor "$TRASH_DIRECTORY/fake_editor.sh" &&
177         git checkout b1 &&
178         test_when_finished "git checkout main" &&
179         git rebase -i HEAD^ &&
180         test_when_finished "git rebase --abort" &&
181         __git_ps1 >"$actual" &&
182         test_cmp expected "$actual"
183 '
184
185 test_expect_success 'prompt - rebase merge' '
186         printf " (b2|REBASE 1/3)" >expected &&
187         git checkout b2 &&
188         test_when_finished "git checkout main" &&
189         test_must_fail git rebase --merge b1 b2 &&
190         test_when_finished "git rebase --abort" &&
191         __git_ps1 >"$actual" &&
192         test_cmp expected "$actual"
193 '
194
195 test_expect_success 'prompt - rebase am' '
196         printf " (b2|REBASE 1/3)" >expected &&
197         git checkout b2 &&
198         test_when_finished "git checkout main" &&
199         test_must_fail git rebase --apply b1 b2 &&
200         test_when_finished "git rebase --abort" &&
201         __git_ps1 >"$actual" &&
202         test_cmp expected "$actual"
203 '
204
205 test_expect_success 'prompt - merge' '
206         printf " (b1|MERGING)" >expected &&
207         git checkout b1 &&
208         test_when_finished "git checkout main" &&
209         test_must_fail git merge b2 &&
210         test_when_finished "git reset --hard" &&
211         __git_ps1 >"$actual" &&
212         test_cmp expected "$actual"
213 '
214
215 test_expect_success 'prompt - cherry-pick' '
216         printf " (main|CHERRY-PICKING)" >expected &&
217         test_must_fail git cherry-pick b1 b1^ &&
218         test_when_finished "git cherry-pick --abort" &&
219         __git_ps1 >"$actual" &&
220         test_cmp expected "$actual" &&
221         git reset --merge &&
222         test_must_fail git rev-parse CHERRY_PICK_HEAD &&
223         __git_ps1 >"$actual" &&
224         test_cmp expected "$actual"
225 '
226
227 test_expect_success 'prompt - revert' '
228         printf " (main|REVERTING)" >expected &&
229         test_must_fail git revert b1^ b1 &&
230         test_when_finished "git revert --abort" &&
231         __git_ps1 >"$actual" &&
232         test_cmp expected "$actual" &&
233         git reset --merge &&
234         test_must_fail git rev-parse REVERT_HEAD &&
235         __git_ps1 >"$actual" &&
236         test_cmp expected "$actual"
237 '
238
239 test_expect_success 'prompt - bisect' '
240         printf " (main|BISECTING)" >expected &&
241         git bisect start &&
242         test_when_finished "git bisect reset" &&
243         __git_ps1 >"$actual" &&
244         test_cmp expected "$actual"
245 '
246
247 test_expect_success 'prompt - dirty status indicator - clean' '
248         printf " (main)" >expected &&
249         (
250                 GIT_PS1_SHOWDIRTYSTATE=y &&
251                 __git_ps1 >"$actual"
252         ) &&
253         test_cmp expected "$actual"
254 '
255
256 test_expect_success 'prompt - dirty status indicator - dirty worktree' '
257         printf " (main *)" >expected &&
258         echo "dirty" >file &&
259         test_when_finished "git reset --hard" &&
260         (
261                 GIT_PS1_SHOWDIRTYSTATE=y &&
262                 __git_ps1 >"$actual"
263         ) &&
264         test_cmp expected "$actual"
265 '
266
267 test_expect_success 'prompt - dirty status indicator - dirty index' '
268         printf " (main +)" >expected &&
269         echo "dirty" >file &&
270         test_when_finished "git reset --hard" &&
271         git add -u &&
272         (
273                 GIT_PS1_SHOWDIRTYSTATE=y &&
274                 __git_ps1 >"$actual"
275         ) &&
276         test_cmp expected "$actual"
277 '
278
279 test_expect_success 'prompt - dirty status indicator - dirty index and worktree' '
280         printf " (main *+)" >expected &&
281         echo "dirty index" >file &&
282         test_when_finished "git reset --hard" &&
283         git add -u &&
284         echo "dirty worktree" >file &&
285         (
286                 GIT_PS1_SHOWDIRTYSTATE=y &&
287                 __git_ps1 >"$actual"
288         ) &&
289         test_cmp expected "$actual"
290 '
291
292 test_expect_success 'prompt - dirty status indicator - orphan branch - clean' '
293         printf " (orphan #)" >expected &&
294         test_when_finished "git checkout main" &&
295         git checkout --orphan orphan &&
296         git reset --hard &&
297         (
298                 GIT_PS1_SHOWDIRTYSTATE=y &&
299                 __git_ps1 >"$actual"
300         ) &&
301         test_cmp expected "$actual"
302 '
303
304 test_expect_success 'prompt - dirty status indicator - orphan branch - dirty index' '
305         printf " (orphan +)" >expected &&
306         test_when_finished "git checkout main" &&
307         git checkout --orphan orphan &&
308         (
309                 GIT_PS1_SHOWDIRTYSTATE=y &&
310                 __git_ps1 >"$actual"
311         ) &&
312         test_cmp expected "$actual"
313 '
314
315 test_expect_success 'prompt - dirty status indicator - orphan branch - dirty index and worktree' '
316         printf " (orphan *+)" >expected &&
317         test_when_finished "git checkout main" &&
318         git checkout --orphan orphan &&
319         >file &&
320         (
321                 GIT_PS1_SHOWDIRTYSTATE=y &&
322                 __git_ps1 >"$actual"
323         ) &&
324         test_cmp expected "$actual"
325 '
326
327 test_expect_success 'prompt - dirty status indicator - shell variable unset with config disabled' '
328         printf " (main)" >expected &&
329         echo "dirty" >file &&
330         test_when_finished "git reset --hard" &&
331         test_config bash.showDirtyState false &&
332         (
333                 sane_unset GIT_PS1_SHOWDIRTYSTATE &&
334                 __git_ps1 >"$actual"
335         ) &&
336         test_cmp expected "$actual"
337 '
338
339 test_expect_success 'prompt - dirty status indicator - shell variable unset with config enabled' '
340         printf " (main)" >expected &&
341         echo "dirty" >file &&
342         test_when_finished "git reset --hard" &&
343         test_config bash.showDirtyState true &&
344         (
345                 sane_unset GIT_PS1_SHOWDIRTYSTATE &&
346                 __git_ps1 >"$actual"
347         ) &&
348         test_cmp expected "$actual"
349 '
350
351 test_expect_success 'prompt - dirty status indicator - shell variable set with config disabled' '
352         printf " (main)" >expected &&
353         echo "dirty" >file &&
354         test_when_finished "git reset --hard" &&
355         test_config bash.showDirtyState false &&
356         (
357                 GIT_PS1_SHOWDIRTYSTATE=y &&
358                 __git_ps1 >"$actual"
359         ) &&
360         test_cmp expected "$actual"
361 '
362
363 test_expect_success 'prompt - dirty status indicator - shell variable set with config enabled' '
364         printf " (main *)" >expected &&
365         echo "dirty" >file &&
366         test_when_finished "git reset --hard" &&
367         test_config bash.showDirtyState true &&
368         (
369                 GIT_PS1_SHOWDIRTYSTATE=y &&
370                 __git_ps1 >"$actual"
371         ) &&
372         test_cmp expected "$actual"
373 '
374
375 test_expect_success 'prompt - dirty status indicator - not shown inside .git directory' '
376         printf " (GIT_DIR!)" >expected &&
377         echo "dirty" >file &&
378         test_when_finished "git reset --hard" &&
379         (
380                 GIT_PS1_SHOWDIRTYSTATE=y &&
381                 cd .git &&
382                 __git_ps1 >"$actual"
383         ) &&
384         test_cmp expected "$actual"
385 '
386
387 test_expect_success 'prompt - stash status indicator - no stash' '
388         printf " (main)" >expected &&
389         (
390                 GIT_PS1_SHOWSTASHSTATE=y &&
391                 __git_ps1 >"$actual"
392         ) &&
393         test_cmp expected "$actual"
394 '
395
396 test_expect_success 'prompt - stash status indicator - stash' '
397         printf " (main $)" >expected &&
398         echo 2 >file &&
399         git stash &&
400         test_when_finished "git stash drop" &&
401         git pack-refs --all &&
402         (
403                 GIT_PS1_SHOWSTASHSTATE=y &&
404                 __git_ps1 >"$actual"
405         ) &&
406         test_cmp expected "$actual"
407 '
408
409 test_expect_success 'prompt - stash status indicator - not shown inside .git directory' '
410         printf " (GIT_DIR!)" >expected &&
411         echo 2 >file &&
412         git stash &&
413         test_when_finished "git stash drop" &&
414         (
415                 GIT_PS1_SHOWSTASHSTATE=y &&
416                 cd .git &&
417                 __git_ps1 >"$actual"
418         ) &&
419         test_cmp expected "$actual"
420 '
421
422 test_expect_success 'prompt - untracked files status indicator - no untracked files' '
423         printf " (main)" >expected &&
424         (
425                 GIT_PS1_SHOWUNTRACKEDFILES=y &&
426                 cd otherrepo &&
427                 __git_ps1 >"$actual"
428         ) &&
429         test_cmp expected "$actual"
430 '
431
432 test_expect_success 'prompt - untracked files status indicator - untracked files' '
433         printf " (main %%)" >expected &&
434         (
435                 GIT_PS1_SHOWUNTRACKEDFILES=y &&
436                 __git_ps1 >"$actual"
437         ) &&
438         test_cmp expected "$actual"
439 '
440
441 test_expect_success 'prompt - untracked files status indicator - empty untracked dir' '
442         printf " (main)" >expected &&
443         mkdir otherrepo/untracked-dir &&
444         test_when_finished "rm -rf otherrepo/untracked-dir" &&
445         (
446                 GIT_PS1_SHOWUNTRACKEDFILES=y &&
447                 cd otherrepo &&
448                 __git_ps1 >"$actual"
449         ) &&
450         test_cmp expected "$actual"
451 '
452
453 test_expect_success 'prompt - untracked files status indicator - non-empty untracked dir' '
454         printf " (main %%)" >expected &&
455         mkdir otherrepo/untracked-dir &&
456         test_when_finished "rm -rf otherrepo/untracked-dir" &&
457         >otherrepo/untracked-dir/untracked-file &&
458         (
459                 GIT_PS1_SHOWUNTRACKEDFILES=y &&
460                 cd otherrepo &&
461                 __git_ps1 >"$actual"
462         ) &&
463         test_cmp expected "$actual"
464 '
465
466 test_expect_success 'prompt - untracked files status indicator - untracked files outside cwd' '
467         printf " (main %%)" >expected &&
468         (
469                 mkdir -p ignored_dir &&
470                 cd ignored_dir &&
471                 GIT_PS1_SHOWUNTRACKEDFILES=y &&
472                 __git_ps1 >"$actual"
473         ) &&
474         test_cmp expected "$actual"
475 '
476
477 test_expect_success 'prompt - untracked files status indicator - shell variable unset with config disabled' '
478         printf " (main)" >expected &&
479         test_config bash.showUntrackedFiles false &&
480         (
481                 sane_unset GIT_PS1_SHOWUNTRACKEDFILES &&
482                 __git_ps1 >"$actual"
483         ) &&
484         test_cmp expected "$actual"
485 '
486
487 test_expect_success 'prompt - untracked files status indicator - shell variable unset with config enabled' '
488         printf " (main)" >expected &&
489         test_config bash.showUntrackedFiles true &&
490         (
491                 sane_unset GIT_PS1_SHOWUNTRACKEDFILES &&
492                 __git_ps1 >"$actual"
493         ) &&
494         test_cmp expected "$actual"
495 '
496
497 test_expect_success 'prompt - untracked files status indicator - shell variable set with config disabled' '
498         printf " (main)" >expected &&
499         test_config bash.showUntrackedFiles false &&
500         (
501                 GIT_PS1_SHOWUNTRACKEDFILES=y &&
502                 __git_ps1 >"$actual"
503         ) &&
504         test_cmp expected "$actual"
505 '
506
507 test_expect_success 'prompt - untracked files status indicator - shell variable set with config enabled' '
508         printf " (main %%)" >expected &&
509         test_config bash.showUntrackedFiles true &&
510         (
511                 GIT_PS1_SHOWUNTRACKEDFILES=y &&
512                 __git_ps1 >"$actual"
513         ) &&
514         test_cmp expected "$actual"
515 '
516
517 test_expect_success 'prompt - untracked files status indicator - not shown inside .git directory' '
518         printf " (GIT_DIR!)" >expected &&
519         (
520                 GIT_PS1_SHOWUNTRACKEDFILES=y &&
521                 cd .git &&
522                 __git_ps1 >"$actual"
523         ) &&
524         test_cmp expected "$actual"
525 '
526
527 test_expect_success 'prompt - format string starting with dash' '
528         printf -- "-main" >expected &&
529         __git_ps1 "-%s" >"$actual" &&
530         test_cmp expected "$actual"
531 '
532
533 test_expect_success 'prompt - pc mode' '
534         printf "BEFORE: (\${__git_ps1_branch_name}):AFTER\\nmain" >expected &&
535         (
536                 __git_ps1 "BEFORE:" ":AFTER" >"$actual" &&
537                 test_must_be_empty "$actual" &&
538                 printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
539         ) &&
540         test_cmp expected "$actual"
541 '
542
543 test_expect_success 'prompt - bash color pc mode - branch name' '
544         printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear}):AFTER\\nmain" >expected &&
545         (
546                 GIT_PS1_SHOWCOLORHINTS=y &&
547                 __git_ps1 "BEFORE:" ":AFTER" >"$actual" &&
548                 printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
549         ) &&
550         test_cmp expected "$actual"
551 '
552
553 test_expect_success 'prompt - bash color pc mode - detached head' '
554         printf "BEFORE: (${c_red}\${__git_ps1_branch_name}${c_clear}):AFTER\\n(%s...)" $(git log -1 --format="%h" b1^) >expected &&
555         git checkout b1^ &&
556         test_when_finished "git checkout main" &&
557         (
558                 GIT_PS1_SHOWCOLORHINTS=y &&
559                 __git_ps1 "BEFORE:" ":AFTER" &&
560                 printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
561         ) &&
562         test_cmp expected "$actual"
563 '
564
565 test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty worktree' '
566         printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_red}*${c_clear}):AFTER\\nmain" >expected &&
567         echo "dirty" >file &&
568         test_when_finished "git reset --hard" &&
569         (
570                 GIT_PS1_SHOWDIRTYSTATE=y &&
571                 GIT_PS1_SHOWCOLORHINTS=y &&
572                 __git_ps1 "BEFORE:" ":AFTER" &&
573                 printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
574         ) &&
575         test_cmp expected "$actual"
576 '
577
578 test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index' '
579         printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_green}+${c_clear}):AFTER\\nmain" >expected &&
580         echo "dirty" >file &&
581         test_when_finished "git reset --hard" &&
582         git add -u &&
583         (
584                 GIT_PS1_SHOWDIRTYSTATE=y &&
585                 GIT_PS1_SHOWCOLORHINTS=y &&
586                 __git_ps1 "BEFORE:" ":AFTER" &&
587                 printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
588         ) &&
589         test_cmp expected "$actual"
590 '
591
592 test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index and worktree' '
593         printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_red}*${c_green}+${c_clear}):AFTER\\nmain" >expected &&
594         echo "dirty index" >file &&
595         test_when_finished "git reset --hard" &&
596         git add -u &&
597         echo "dirty worktree" >file &&
598         (
599                 GIT_PS1_SHOWCOLORHINTS=y &&
600                 GIT_PS1_SHOWDIRTYSTATE=y &&
601                 __git_ps1 "BEFORE:" ":AFTER" &&
602                 printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
603         ) &&
604         test_cmp expected "$actual"
605 '
606
607 test_expect_success 'prompt - bash color pc mode - dirty status indicator - before root commit' '
608         printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_green}#${c_clear}):AFTER\\nmain" >expected &&
609         (
610                 GIT_PS1_SHOWDIRTYSTATE=y &&
611                 GIT_PS1_SHOWCOLORHINTS=y &&
612                 cd otherrepo &&
613                 __git_ps1 "BEFORE:" ":AFTER" &&
614                 printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
615         ) &&
616         test_cmp expected "$actual"
617 '
618
619 test_expect_success 'prompt - bash color pc mode - inside .git directory' '
620         printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear}):AFTER\\nGIT_DIR!" >expected &&
621         echo "dirty" >file &&
622         test_when_finished "git reset --hard" &&
623         (
624                 GIT_PS1_SHOWDIRTYSTATE=y &&
625                 GIT_PS1_SHOWCOLORHINTS=y &&
626                 cd .git &&
627                 __git_ps1 "BEFORE:" ":AFTER" &&
628                 printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
629         ) &&
630         test_cmp expected "$actual"
631 '
632
633 test_expect_success 'prompt - bash color pc mode - stash status indicator' '
634         printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_lblue}\$${c_clear}):AFTER\\nmain" >expected &&
635         echo 2 >file &&
636         git stash &&
637         test_when_finished "git stash drop" &&
638         (
639                 GIT_PS1_SHOWSTASHSTATE=y &&
640                 GIT_PS1_SHOWCOLORHINTS=y &&
641                 __git_ps1 "BEFORE:" ":AFTER" &&
642                 printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
643         ) &&
644         test_cmp expected "$actual"
645 '
646
647 test_expect_success 'prompt - bash color pc mode - untracked files status indicator' '
648         printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_red}%%${c_clear}):AFTER\\nmain" >expected &&
649         (
650                 GIT_PS1_SHOWUNTRACKEDFILES=y &&
651                 GIT_PS1_SHOWCOLORHINTS=y &&
652                 __git_ps1 "BEFORE:" ":AFTER" &&
653                 printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
654         ) &&
655         test_cmp expected "$actual"
656 '
657
658 test_expect_success 'prompt - zsh color pc mode' '
659         printf "BEFORE: (%%F{green}main%%f):AFTER" >expected &&
660         (
661                 ZSH_VERSION=5.0.0 &&
662                 GIT_PS1_SHOWCOLORHINTS=y &&
663                 __git_ps1 "BEFORE:" ":AFTER" &&
664                 printf "%s" "$PS1" >"$actual"
665         ) &&
666         test_cmp expected "$actual"
667 '
668
669 test_expect_success 'prompt - hide if pwd ignored - env var unset, config disabled' '
670         printf " (main)" >expected &&
671         test_config bash.hideIfPwdIgnored false &&
672         (
673                 cd ignored_dir &&
674                 __git_ps1 >"$actual"
675         ) &&
676         test_cmp expected "$actual"
677 '
678
679 test_expect_success 'prompt - hide if pwd ignored - env var unset, config disabled, pc mode' '
680         printf "BEFORE: (\${__git_ps1_branch_name}):AFTER" >expected &&
681         test_config bash.hideIfPwdIgnored false &&
682         (
683                 cd ignored_dir &&
684                 __git_ps1 "BEFORE:" ":AFTER" &&
685                 printf "%s" "$PS1" >"$actual"
686         ) &&
687         test_cmp expected "$actual"
688 '
689
690 test_expect_success 'prompt - hide if pwd ignored - env var unset, config unset' '
691         printf " (main)" >expected &&
692         (
693                 cd ignored_dir &&
694                 __git_ps1 >"$actual"
695         ) &&
696         test_cmp expected "$actual"
697 '
698
699 test_expect_success 'prompt - hide if pwd ignored - env var unset, config unset, pc mode' '
700         printf "BEFORE: (\${__git_ps1_branch_name}):AFTER" >expected &&
701         (
702                 cd ignored_dir &&
703                 __git_ps1 "BEFORE:" ":AFTER" &&
704                 printf "%s" "$PS1" >"$actual"
705         ) &&
706         test_cmp expected "$actual"
707 '
708
709 test_expect_success 'prompt - hide if pwd ignored - env var set, config disabled' '
710         printf " (main)" >expected &&
711         test_config bash.hideIfPwdIgnored false &&
712         (
713                 cd ignored_dir &&
714                 GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
715                 __git_ps1 >"$actual"
716         ) &&
717         test_cmp expected "$actual"
718 '
719
720 test_expect_success 'prompt - hide if pwd ignored - env var set, config disabled, pc mode' '
721         printf "BEFORE: (\${__git_ps1_branch_name}):AFTER" >expected &&
722         test_config bash.hideIfPwdIgnored false &&
723         (
724                 cd ignored_dir &&
725                 GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
726                 __git_ps1 "BEFORE:" ":AFTER" &&
727                 printf "%s" "$PS1" >"$actual"
728         ) &&
729         test_cmp expected "$actual"
730 '
731
732 test_expect_success 'prompt - hide if pwd ignored - env var set, config unset' '
733         (
734                 cd ignored_dir &&
735                 GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
736                 __git_ps1 >"$actual"
737         ) &&
738         test_must_be_empty "$actual"
739 '
740
741 test_expect_success 'prompt - hide if pwd ignored - env var set, config unset, pc mode' '
742         printf "BEFORE::AFTER" >expected &&
743         (
744                 cd ignored_dir &&
745                 GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
746                 __git_ps1 "BEFORE:" ":AFTER" &&
747                 printf "%s" "$PS1" >"$actual"
748         ) &&
749         test_cmp expected "$actual"
750 '
751
752 test_expect_success 'prompt - hide if pwd ignored - inside gitdir' '
753         printf " (GIT_DIR!)" >expected &&
754         (
755                 GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
756                 cd .git &&
757                 __git_ps1 >"$actual"
758         ) &&
759         test_cmp expected "$actual"
760 '
761
762 test_done