Start the 2.46 cycle
[alt-git.git] / t / t9903-bash-prompt.sh
blobd667dda654e2de7f32d5f7d065f6eac59ca9fdbf
1 #!/bin/sh
3 # Copyright (c) 2012 SZEDER Gábor
6 test_description='test git-specific bash prompt functions'
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11 . ./lib-bash.sh
13 . "$GIT_BUILD_DIR/contrib/completion/git-prompt.sh"
15 actual="$TRASH_DIRECTORY/actual"
16 c_red='\001\e[31m\002'
17 c_green='\001\e[32m\002'
18 c_lblue='\001\e[1;34m\002'
19 c_clear='\001\e[0m\002'
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
46 test_expect_success 'prompt - branch name' '
47 printf " (main)" >expected &&
48 __git_ps1 >"$actual" &&
49 test_cmp expected "$actual"
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"
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"
69 if test_have_prereq !FUNNYNAMES; then
70 say 'Your filesystem does not allow newlines in filenames.'
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 &&
83 cd "$repo_with_newline/subdir" &&
84 __git_ps1 >"$actual"
85 ) &&
86 test_cmp expected "$actual"
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"
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" &&
103 GIT_PS1_DESCRIBE_STYLE=contains &&
104 __git_ps1 >"$actual"
105 ) &&
106 test_cmp expected "$actual"
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" &&
114 GIT_PS1_DESCRIBE_STYLE=branch &&
115 __git_ps1 >"$actual"
116 ) &&
117 test_cmp expected "$actual"
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" &&
125 GIT_PS1_DESCRIBE_STYLE=describe &&
126 __git_ps1 >"$actual"
127 ) &&
128 test_cmp expected "$actual"
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"
139 test_expect_success 'prompt - inside .git directory' '
140 printf " (GIT_DIR!)" >expected &&
142 cd .git &&
143 __git_ps1 >"$actual"
144 ) &&
145 test_cmp expected "$actual"
148 test_expect_success 'prompt - deep inside .git directory' '
149 printf " (GIT_DIR!)" >expected &&
151 cd .git/objects &&
152 __git_ps1 >"$actual"
153 ) &&
154 test_cmp expected "$actual"
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" &&
162 cd bare.git &&
163 __git_ps1 >"$actual"
164 ) &&
165 test_cmp expected "$actual"
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"
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"
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"
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"
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"
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"
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"
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"
247 test_expect_success 'prompt - dirty status indicator - clean' '
248 printf " (main)" >expected &&
250 GIT_PS1_SHOWDIRTYSTATE=y &&
251 __git_ps1 >"$actual"
252 ) &&
253 test_cmp expected "$actual"
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" &&
261 GIT_PS1_SHOWDIRTYSTATE=y &&
262 __git_ps1 >"$actual"
263 ) &&
264 test_cmp expected "$actual"
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 &&
273 GIT_PS1_SHOWDIRTYSTATE=y &&
274 __git_ps1 >"$actual"
275 ) &&
276 test_cmp expected "$actual"
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 &&
286 GIT_PS1_SHOWDIRTYSTATE=y &&
287 __git_ps1 >"$actual"
288 ) &&
289 test_cmp expected "$actual"
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 &&
298 GIT_PS1_SHOWDIRTYSTATE=y &&
299 __git_ps1 >"$actual"
300 ) &&
301 test_cmp expected "$actual"
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 &&
309 GIT_PS1_SHOWDIRTYSTATE=y &&
310 __git_ps1 >"$actual"
311 ) &&
312 test_cmp expected "$actual"
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 &&
321 GIT_PS1_SHOWDIRTYSTATE=y &&
322 __git_ps1 >"$actual"
323 ) &&
324 test_cmp expected "$actual"
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 &&
333 sane_unset GIT_PS1_SHOWDIRTYSTATE &&
334 __git_ps1 >"$actual"
335 ) &&
336 test_cmp expected "$actual"
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 &&
345 sane_unset GIT_PS1_SHOWDIRTYSTATE &&
346 __git_ps1 >"$actual"
347 ) &&
348 test_cmp expected "$actual"
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 &&
357 GIT_PS1_SHOWDIRTYSTATE=y &&
358 __git_ps1 >"$actual"
359 ) &&
360 test_cmp expected "$actual"
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 &&
369 GIT_PS1_SHOWDIRTYSTATE=y &&
370 __git_ps1 >"$actual"
371 ) &&
372 test_cmp expected "$actual"
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" &&
380 GIT_PS1_SHOWDIRTYSTATE=y &&
381 cd .git &&
382 __git_ps1 >"$actual"
383 ) &&
384 test_cmp expected "$actual"
387 test_expect_success 'prompt - stash status indicator - no stash' '
388 printf " (main)" >expected &&
390 GIT_PS1_SHOWSTASHSTATE=y &&
391 __git_ps1 >"$actual"
392 ) &&
393 test_cmp expected "$actual"
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 &&
403 GIT_PS1_SHOWSTASHSTATE=y &&
404 __git_ps1 >"$actual"
405 ) &&
406 test_cmp expected "$actual"
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" &&
415 GIT_PS1_SHOWSTASHSTATE=y &&
416 cd .git &&
417 __git_ps1 >"$actual"
418 ) &&
419 test_cmp expected "$actual"
422 test_expect_success 'prompt - untracked files status indicator - no untracked files' '
423 printf " (main)" >expected &&
425 GIT_PS1_SHOWUNTRACKEDFILES=y &&
426 cd otherrepo &&
427 __git_ps1 >"$actual"
428 ) &&
429 test_cmp expected "$actual"
432 test_expect_success 'prompt - untracked files status indicator - untracked files' '
433 printf " (main %%)" >expected &&
435 GIT_PS1_SHOWUNTRACKEDFILES=y &&
436 __git_ps1 >"$actual"
437 ) &&
438 test_cmp expected "$actual"
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" &&
446 GIT_PS1_SHOWUNTRACKEDFILES=y &&
447 cd otherrepo &&
448 __git_ps1 >"$actual"
449 ) &&
450 test_cmp expected "$actual"
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 &&
459 GIT_PS1_SHOWUNTRACKEDFILES=y &&
460 cd otherrepo &&
461 __git_ps1 >"$actual"
462 ) &&
463 test_cmp expected "$actual"
466 test_expect_success 'prompt - untracked files status indicator - untracked files outside cwd' '
467 printf " (main %%)" >expected &&
469 mkdir -p ignored_dir &&
470 cd ignored_dir &&
471 GIT_PS1_SHOWUNTRACKEDFILES=y &&
472 __git_ps1 >"$actual"
473 ) &&
474 test_cmp expected "$actual"
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 &&
481 sane_unset GIT_PS1_SHOWUNTRACKEDFILES &&
482 __git_ps1 >"$actual"
483 ) &&
484 test_cmp expected "$actual"
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 &&
491 sane_unset GIT_PS1_SHOWUNTRACKEDFILES &&
492 __git_ps1 >"$actual"
493 ) &&
494 test_cmp expected "$actual"
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 &&
501 GIT_PS1_SHOWUNTRACKEDFILES=y &&
502 __git_ps1 >"$actual"
503 ) &&
504 test_cmp expected "$actual"
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 &&
511 GIT_PS1_SHOWUNTRACKEDFILES=y &&
512 __git_ps1 >"$actual"
513 ) &&
514 test_cmp expected "$actual"
517 test_expect_success 'prompt - untracked files status indicator - not shown inside .git directory' '
518 printf " (GIT_DIR!)" >expected &&
520 GIT_PS1_SHOWUNTRACKEDFILES=y &&
521 cd .git &&
522 __git_ps1 >"$actual"
523 ) &&
524 test_cmp expected "$actual"
527 test_expect_success 'prompt - format string starting with dash' '
528 printf -- "-main" >expected &&
529 __git_ps1 "-%s" >"$actual" &&
530 test_cmp expected "$actual"
533 test_expect_success 'prompt - pc mode' '
534 printf "BEFORE: (\${__git_ps1_branch_name}):AFTER\\nmain" >expected &&
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"
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 &&
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"
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" &&
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"
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" &&
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"
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 &&
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"
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_clear}${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 &&
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"
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 &&
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"
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" &&
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"
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" &&
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"
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 &&
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"
658 test_expect_success 'prompt - zsh color pc mode' '
659 printf "BEFORE: (%%F{green}main%%f):AFTER" >expected &&
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"
669 test_expect_success 'prompt - hide if pwd ignored - env var unset, config disabled' '
670 printf " (main)" >expected &&
671 test_config bash.hideIfPwdIgnored false &&
673 cd ignored_dir &&
674 __git_ps1 >"$actual"
675 ) &&
676 test_cmp expected "$actual"
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 &&
683 cd ignored_dir &&
684 __git_ps1 "BEFORE:" ":AFTER" &&
685 printf "%s" "$PS1" >"$actual"
686 ) &&
687 test_cmp expected "$actual"
690 test_expect_success 'prompt - hide if pwd ignored - env var unset, config unset' '
691 printf " (main)" >expected &&
693 cd ignored_dir &&
694 __git_ps1 >"$actual"
695 ) &&
696 test_cmp expected "$actual"
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 &&
702 cd ignored_dir &&
703 __git_ps1 "BEFORE:" ":AFTER" &&
704 printf "%s" "$PS1" >"$actual"
705 ) &&
706 test_cmp expected "$actual"
709 test_expect_success 'prompt - hide if pwd ignored - env var set, config disabled' '
710 printf " (main)" >expected &&
711 test_config bash.hideIfPwdIgnored false &&
713 cd ignored_dir &&
714 GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
715 __git_ps1 >"$actual"
716 ) &&
717 test_cmp expected "$actual"
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 &&
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"
732 test_expect_success 'prompt - hide if pwd ignored - env var set, config unset' '
734 cd ignored_dir &&
735 GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
736 __git_ps1 >"$actual"
737 ) &&
738 test_must_be_empty "$actual"
741 test_expect_success 'prompt - hide if pwd ignored - env var set, config unset, pc mode' '
742 printf "BEFORE::AFTER" >expected &&
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"
752 test_expect_success 'prompt - hide if pwd ignored - inside gitdir' '
753 printf " (GIT_DIR!)" >expected &&
755 GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
756 cd .git &&
757 __git_ps1 >"$actual"
758 ) &&
759 test_cmp expected "$actual"
762 test_expect_success 'prompt - conflict indicator' '
763 printf " (main|CONFLICT)" >expected &&
764 echo "stash" >file &&
765 git stash &&
766 test_when_finished "git stash drop" &&
767 echo "commit" >file &&
768 git commit -m "commit" file &&
769 test_when_finished "git reset --hard HEAD~" &&
770 test_must_fail git stash apply &&
772 GIT_PS1_SHOWCONFLICTSTATE="yes" &&
773 __git_ps1 >"$actual"
774 ) &&
775 test_cmp expected "$actual"
778 test_done