The eleventh batch
[git.git] / t / t9903-bash-prompt.sh
blob95e9955bca1bed2f5f51127d1793ac71bebb23c5
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 TEST_PASSES_SANITIZE_LEAK=true
12 . ./lib-bash.sh
14 . "$GIT_BUILD_DIR/contrib/completion/git-prompt.sh"
16 actual="$TRASH_DIRECTORY/actual"
17 c_red='\001\e[31m\002'
18 c_green='\001\e[32m\002'
19 c_lblue='\001\e[1;34m\002'
20 c_clear='\001\e[0m\002'
22 test_expect_success 'setup for prompt tests' '
23 git init otherrepo &&
24 echo 1 >file &&
25 git add file &&
26 test_tick &&
27 git commit -m initial &&
28 git tag -a -m msg1 t1 &&
29 git checkout -b b1 &&
30 echo 2 >file &&
31 git commit -m "second b1" file &&
32 echo 3 >file &&
33 git commit -m "third b1" file &&
34 git tag -a -m msg2 t2 &&
35 git checkout -b b2 main &&
36 echo 0 >file &&
37 git commit -m "second b2" file &&
38 echo 00 >file &&
39 git commit -m "another b2" file &&
40 echo 000 >file &&
41 git commit -m "yet another b2" file &&
42 mkdir ignored_dir &&
43 echo "ignored_dir/" >>.gitignore &&
44 git checkout main
47 test_expect_success 'prompt - branch name' '
48 printf " (main)" >expected &&
49 __git_ps1 >"$actual" &&
50 test_cmp expected "$actual"
53 test_expect_success SYMLINKS 'prompt - branch name - symlink symref' '
54 printf " (main)" >expected &&
55 test_when_finished "git checkout main" &&
56 test_config core.preferSymlinkRefs true &&
57 git checkout main &&
58 __git_ps1 >"$actual" &&
59 test_cmp expected "$actual"
62 test_expect_success 'prompt - unborn branch' '
63 printf " (unborn)" >expected &&
64 git checkout --orphan unborn &&
65 test_when_finished "git checkout main" &&
66 __git_ps1 >"$actual" &&
67 test_cmp expected "$actual"
70 if test_have_prereq !FUNNYNAMES; then
71 say 'Your filesystem does not allow newlines in filenames.'
74 test_expect_success FUNNYNAMES 'prompt - with newline in path' '
75 repo_with_newline="repo
76 with
77 newline" &&
78 mkdir "$repo_with_newline" &&
79 printf " (main)" >expected &&
80 git init "$repo_with_newline" &&
81 test_when_finished "rm -rf \"$repo_with_newline\"" &&
82 mkdir "$repo_with_newline"/subdir &&
84 cd "$repo_with_newline/subdir" &&
85 __git_ps1 >"$actual"
86 ) &&
87 test_cmp expected "$actual"
90 test_expect_success 'prompt - detached head' '
91 printf " ((%s...))" $(git log -1 --format="%h" --abbrev=13 b1^) >expected &&
92 test_config core.abbrev 13 &&
93 git checkout b1^ &&
94 test_when_finished "git checkout main" &&
95 __git_ps1 >"$actual" &&
96 test_cmp expected "$actual"
99 test_expect_success 'prompt - describe detached head - contains' '
100 printf " ((t2~1))" >expected &&
101 git checkout b1^ &&
102 test_when_finished "git checkout main" &&
104 GIT_PS1_DESCRIBE_STYLE=contains &&
105 __git_ps1 >"$actual"
106 ) &&
107 test_cmp expected "$actual"
110 test_expect_success 'prompt - describe detached head - branch' '
111 printf " ((tags/t2~1))" >expected &&
112 git checkout b1^ &&
113 test_when_finished "git checkout main" &&
115 GIT_PS1_DESCRIBE_STYLE=branch &&
116 __git_ps1 >"$actual"
117 ) &&
118 test_cmp expected "$actual"
121 test_expect_success 'prompt - describe detached head - describe' '
122 printf " ((t1-1-g%s))" $(git log -1 --format="%h" b1^) >expected &&
123 git checkout b1^ &&
124 test_when_finished "git checkout main" &&
126 GIT_PS1_DESCRIBE_STYLE=describe &&
127 __git_ps1 >"$actual"
128 ) &&
129 test_cmp expected "$actual"
132 test_expect_success 'prompt - describe detached head - default' '
133 printf " ((t2))" >expected &&
134 git checkout --detach b1 &&
135 test_when_finished "git checkout main" &&
136 __git_ps1 >"$actual" &&
137 test_cmp expected "$actual"
140 test_expect_success 'prompt - inside .git directory' '
141 printf " (GIT_DIR!)" >expected &&
143 cd .git &&
144 __git_ps1 >"$actual"
145 ) &&
146 test_cmp expected "$actual"
149 test_expect_success 'prompt - deep inside .git directory' '
150 printf " (GIT_DIR!)" >expected &&
152 cd .git/objects &&
153 __git_ps1 >"$actual"
154 ) &&
155 test_cmp expected "$actual"
158 test_expect_success 'prompt - inside bare repository' '
159 printf " (BARE:main)" >expected &&
160 git init --bare bare.git &&
161 test_when_finished "rm -rf bare.git" &&
163 cd bare.git &&
164 __git_ps1 >"$actual"
165 ) &&
166 test_cmp expected "$actual"
169 test_expect_success 'prompt - interactive rebase' '
170 printf " (b1|REBASE 2/3)" >expected &&
171 write_script fake_editor.sh <<-\EOF &&
172 echo "exec echo" >"$1"
173 echo "edit $(git log -1 --format="%h")" >>"$1"
174 echo "exec echo" >>"$1"
176 test_when_finished "rm -f fake_editor.sh" &&
177 test_set_editor "$TRASH_DIRECTORY/fake_editor.sh" &&
178 git checkout b1 &&
179 test_when_finished "git checkout main" &&
180 git rebase -i HEAD^ &&
181 test_when_finished "git rebase --abort" &&
182 __git_ps1 >"$actual" &&
183 test_cmp expected "$actual"
186 test_expect_success 'prompt - rebase merge' '
187 printf " (b2|REBASE 1/3)" >expected &&
188 git checkout b2 &&
189 test_when_finished "git checkout main" &&
190 test_must_fail git rebase --merge b1 b2 &&
191 test_when_finished "git rebase --abort" &&
192 __git_ps1 >"$actual" &&
193 test_cmp expected "$actual"
196 test_expect_success 'prompt - rebase am' '
197 printf " (b2|REBASE 1/3)" >expected &&
198 git checkout b2 &&
199 test_when_finished "git checkout main" &&
200 test_must_fail git rebase --apply b1 b2 &&
201 test_when_finished "git rebase --abort" &&
202 __git_ps1 >"$actual" &&
203 test_cmp expected "$actual"
206 test_expect_success 'prompt - merge' '
207 printf " (b1|MERGING)" >expected &&
208 git checkout b1 &&
209 test_when_finished "git checkout main" &&
210 test_must_fail git merge b2 &&
211 test_when_finished "git reset --hard" &&
212 __git_ps1 >"$actual" &&
213 test_cmp expected "$actual"
216 test_expect_success 'prompt - cherry-pick' '
217 printf " (main|CHERRY-PICKING)" >expected &&
218 test_must_fail git cherry-pick b1 b1^ &&
219 test_when_finished "git cherry-pick --abort" &&
220 __git_ps1 >"$actual" &&
221 test_cmp expected "$actual" &&
222 git reset --merge &&
223 test_must_fail git rev-parse CHERRY_PICK_HEAD &&
224 __git_ps1 >"$actual" &&
225 test_cmp expected "$actual"
228 test_expect_success 'prompt - revert' '
229 printf " (main|REVERTING)" >expected &&
230 test_must_fail git revert b1^ b1 &&
231 test_when_finished "git revert --abort" &&
232 __git_ps1 >"$actual" &&
233 test_cmp expected "$actual" &&
234 git reset --merge &&
235 test_must_fail git rev-parse REVERT_HEAD &&
236 __git_ps1 >"$actual" &&
237 test_cmp expected "$actual"
240 test_expect_success 'prompt - bisect' '
241 printf " (main|BISECTING)" >expected &&
242 git bisect start &&
243 test_when_finished "git bisect reset" &&
244 __git_ps1 >"$actual" &&
245 test_cmp expected "$actual"
248 test_expect_success 'prompt - dirty status indicator - clean' '
249 printf " (main)" >expected &&
251 GIT_PS1_SHOWDIRTYSTATE=y &&
252 __git_ps1 >"$actual"
253 ) &&
254 test_cmp expected "$actual"
257 test_expect_success 'prompt - dirty status indicator - dirty worktree' '
258 printf " (main *)" >expected &&
259 echo "dirty" >file &&
260 test_when_finished "git reset --hard" &&
262 GIT_PS1_SHOWDIRTYSTATE=y &&
263 __git_ps1 >"$actual"
264 ) &&
265 test_cmp expected "$actual"
268 test_expect_success 'prompt - dirty status indicator - dirty index' '
269 printf " (main +)" >expected &&
270 echo "dirty" >file &&
271 test_when_finished "git reset --hard" &&
272 git add -u &&
274 GIT_PS1_SHOWDIRTYSTATE=y &&
275 __git_ps1 >"$actual"
276 ) &&
277 test_cmp expected "$actual"
280 test_expect_success 'prompt - dirty status indicator - dirty index and worktree' '
281 printf " (main *+)" >expected &&
282 echo "dirty index" >file &&
283 test_when_finished "git reset --hard" &&
284 git add -u &&
285 echo "dirty worktree" >file &&
287 GIT_PS1_SHOWDIRTYSTATE=y &&
288 __git_ps1 >"$actual"
289 ) &&
290 test_cmp expected "$actual"
293 test_expect_success 'prompt - dirty status indicator - orphan branch - clean' '
294 printf " (orphan #)" >expected &&
295 test_when_finished "git checkout main" &&
296 git checkout --orphan orphan &&
297 git reset --hard &&
299 GIT_PS1_SHOWDIRTYSTATE=y &&
300 __git_ps1 >"$actual"
301 ) &&
302 test_cmp expected "$actual"
305 test_expect_success 'prompt - dirty status indicator - orphan branch - dirty index' '
306 printf " (orphan +)" >expected &&
307 test_when_finished "git checkout main" &&
308 git checkout --orphan orphan &&
310 GIT_PS1_SHOWDIRTYSTATE=y &&
311 __git_ps1 >"$actual"
312 ) &&
313 test_cmp expected "$actual"
316 test_expect_success 'prompt - dirty status indicator - orphan branch - dirty index and worktree' '
317 printf " (orphan *+)" >expected &&
318 test_when_finished "git checkout main" &&
319 git checkout --orphan orphan &&
320 >file &&
322 GIT_PS1_SHOWDIRTYSTATE=y &&
323 __git_ps1 >"$actual"
324 ) &&
325 test_cmp expected "$actual"
328 test_expect_success 'prompt - dirty status indicator - shell variable unset with config disabled' '
329 printf " (main)" >expected &&
330 echo "dirty" >file &&
331 test_when_finished "git reset --hard" &&
332 test_config bash.showDirtyState false &&
334 sane_unset GIT_PS1_SHOWDIRTYSTATE &&
335 __git_ps1 >"$actual"
336 ) &&
337 test_cmp expected "$actual"
340 test_expect_success 'prompt - dirty status indicator - shell variable unset with config enabled' '
341 printf " (main)" >expected &&
342 echo "dirty" >file &&
343 test_when_finished "git reset --hard" &&
344 test_config bash.showDirtyState true &&
346 sane_unset GIT_PS1_SHOWDIRTYSTATE &&
347 __git_ps1 >"$actual"
348 ) &&
349 test_cmp expected "$actual"
352 test_expect_success 'prompt - dirty status indicator - shell variable set with config disabled' '
353 printf " (main)" >expected &&
354 echo "dirty" >file &&
355 test_when_finished "git reset --hard" &&
356 test_config bash.showDirtyState false &&
358 GIT_PS1_SHOWDIRTYSTATE=y &&
359 __git_ps1 >"$actual"
360 ) &&
361 test_cmp expected "$actual"
364 test_expect_success 'prompt - dirty status indicator - shell variable set with config enabled' '
365 printf " (main *)" >expected &&
366 echo "dirty" >file &&
367 test_when_finished "git reset --hard" &&
368 test_config bash.showDirtyState true &&
370 GIT_PS1_SHOWDIRTYSTATE=y &&
371 __git_ps1 >"$actual"
372 ) &&
373 test_cmp expected "$actual"
376 test_expect_success 'prompt - dirty status indicator - not shown inside .git directory' '
377 printf " (GIT_DIR!)" >expected &&
378 echo "dirty" >file &&
379 test_when_finished "git reset --hard" &&
381 GIT_PS1_SHOWDIRTYSTATE=y &&
382 cd .git &&
383 __git_ps1 >"$actual"
384 ) &&
385 test_cmp expected "$actual"
388 test_expect_success 'prompt - stash status indicator - no stash' '
389 printf " (main)" >expected &&
391 GIT_PS1_SHOWSTASHSTATE=y &&
392 __git_ps1 >"$actual"
393 ) &&
394 test_cmp expected "$actual"
397 test_expect_success 'prompt - stash status indicator - stash' '
398 printf " (main $)" >expected &&
399 echo 2 >file &&
400 git stash &&
401 test_when_finished "git stash drop" &&
402 git pack-refs --all &&
404 GIT_PS1_SHOWSTASHSTATE=y &&
405 __git_ps1 >"$actual"
406 ) &&
407 test_cmp expected "$actual"
410 test_expect_success 'prompt - stash status indicator - not shown inside .git directory' '
411 printf " (GIT_DIR!)" >expected &&
412 echo 2 >file &&
413 git stash &&
414 test_when_finished "git stash drop" &&
416 GIT_PS1_SHOWSTASHSTATE=y &&
417 cd .git &&
418 __git_ps1 >"$actual"
419 ) &&
420 test_cmp expected "$actual"
423 test_expect_success 'prompt - untracked files status indicator - no untracked files' '
424 printf " (main)" >expected &&
426 GIT_PS1_SHOWUNTRACKEDFILES=y &&
427 cd otherrepo &&
428 __git_ps1 >"$actual"
429 ) &&
430 test_cmp expected "$actual"
433 test_expect_success 'prompt - untracked files status indicator - untracked files' '
434 printf " (main %%)" >expected &&
436 GIT_PS1_SHOWUNTRACKEDFILES=y &&
437 __git_ps1 >"$actual"
438 ) &&
439 test_cmp expected "$actual"
442 test_expect_success 'prompt - untracked files status indicator - empty untracked dir' '
443 printf " (main)" >expected &&
444 mkdir otherrepo/untracked-dir &&
445 test_when_finished "rm -rf otherrepo/untracked-dir" &&
447 GIT_PS1_SHOWUNTRACKEDFILES=y &&
448 cd otherrepo &&
449 __git_ps1 >"$actual"
450 ) &&
451 test_cmp expected "$actual"
454 test_expect_success 'prompt - untracked files status indicator - non-empty untracked dir' '
455 printf " (main %%)" >expected &&
456 mkdir otherrepo/untracked-dir &&
457 test_when_finished "rm -rf otherrepo/untracked-dir" &&
458 >otherrepo/untracked-dir/untracked-file &&
460 GIT_PS1_SHOWUNTRACKEDFILES=y &&
461 cd otherrepo &&
462 __git_ps1 >"$actual"
463 ) &&
464 test_cmp expected "$actual"
467 test_expect_success 'prompt - untracked files status indicator - untracked files outside cwd' '
468 printf " (main %%)" >expected &&
470 mkdir -p ignored_dir &&
471 cd ignored_dir &&
472 GIT_PS1_SHOWUNTRACKEDFILES=y &&
473 __git_ps1 >"$actual"
474 ) &&
475 test_cmp expected "$actual"
478 test_expect_success 'prompt - untracked files status indicator - shell variable unset with config disabled' '
479 printf " (main)" >expected &&
480 test_config bash.showUntrackedFiles false &&
482 sane_unset GIT_PS1_SHOWUNTRACKEDFILES &&
483 __git_ps1 >"$actual"
484 ) &&
485 test_cmp expected "$actual"
488 test_expect_success 'prompt - untracked files status indicator - shell variable unset with config enabled' '
489 printf " (main)" >expected &&
490 test_config bash.showUntrackedFiles true &&
492 sane_unset GIT_PS1_SHOWUNTRACKEDFILES &&
493 __git_ps1 >"$actual"
494 ) &&
495 test_cmp expected "$actual"
498 test_expect_success 'prompt - untracked files status indicator - shell variable set with config disabled' '
499 printf " (main)" >expected &&
500 test_config bash.showUntrackedFiles false &&
502 GIT_PS1_SHOWUNTRACKEDFILES=y &&
503 __git_ps1 >"$actual"
504 ) &&
505 test_cmp expected "$actual"
508 test_expect_success 'prompt - untracked files status indicator - shell variable set with config enabled' '
509 printf " (main %%)" >expected &&
510 test_config bash.showUntrackedFiles true &&
512 GIT_PS1_SHOWUNTRACKEDFILES=y &&
513 __git_ps1 >"$actual"
514 ) &&
515 test_cmp expected "$actual"
518 test_expect_success 'prompt - untracked files status indicator - not shown inside .git directory' '
519 printf " (GIT_DIR!)" >expected &&
521 GIT_PS1_SHOWUNTRACKEDFILES=y &&
522 cd .git &&
523 __git_ps1 >"$actual"
524 ) &&
525 test_cmp expected "$actual"
528 test_expect_success 'prompt - format string starting with dash' '
529 printf -- "-main" >expected &&
530 __git_ps1 "-%s" >"$actual" &&
531 test_cmp expected "$actual"
534 test_expect_success 'prompt - pc mode' '
535 printf "BEFORE: (\${__git_ps1_branch_name}):AFTER\\nmain" >expected &&
537 __git_ps1 "BEFORE:" ":AFTER" >"$actual" &&
538 test_must_be_empty "$actual" &&
539 printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
540 ) &&
541 test_cmp expected "$actual"
544 test_expect_success 'prompt - bash color pc mode - branch name' '
545 printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear}):AFTER\\nmain" >expected &&
547 GIT_PS1_SHOWCOLORHINTS=y &&
548 __git_ps1 "BEFORE:" ":AFTER" >"$actual" &&
549 printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
550 ) &&
551 test_cmp expected "$actual"
554 test_expect_success 'prompt - bash color pc mode - detached head' '
555 printf "BEFORE: (${c_red}\${__git_ps1_branch_name}${c_clear}):AFTER\\n(%s...)" $(git log -1 --format="%h" b1^) >expected &&
556 git checkout b1^ &&
557 test_when_finished "git checkout main" &&
559 GIT_PS1_SHOWCOLORHINTS=y &&
560 __git_ps1 "BEFORE:" ":AFTER" &&
561 printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
562 ) &&
563 test_cmp expected "$actual"
566 test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty worktree' '
567 printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_red}*${c_clear}):AFTER\\nmain" >expected &&
568 echo "dirty" >file &&
569 test_when_finished "git reset --hard" &&
571 GIT_PS1_SHOWDIRTYSTATE=y &&
572 GIT_PS1_SHOWCOLORHINTS=y &&
573 __git_ps1 "BEFORE:" ":AFTER" &&
574 printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
575 ) &&
576 test_cmp expected "$actual"
579 test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index' '
580 printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_green}+${c_clear}):AFTER\\nmain" >expected &&
581 echo "dirty" >file &&
582 test_when_finished "git reset --hard" &&
583 git add -u &&
585 GIT_PS1_SHOWDIRTYSTATE=y &&
586 GIT_PS1_SHOWCOLORHINTS=y &&
587 __git_ps1 "BEFORE:" ":AFTER" &&
588 printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
589 ) &&
590 test_cmp expected "$actual"
593 test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index and worktree' '
594 printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_red}*${c_clear}${c_green}+${c_clear}):AFTER\\nmain" >expected &&
595 echo "dirty index" >file &&
596 test_when_finished "git reset --hard" &&
597 git add -u &&
598 echo "dirty worktree" >file &&
600 GIT_PS1_SHOWCOLORHINTS=y &&
601 GIT_PS1_SHOWDIRTYSTATE=y &&
602 __git_ps1 "BEFORE:" ":AFTER" &&
603 printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
604 ) &&
605 test_cmp expected "$actual"
608 test_expect_success 'prompt - bash color pc mode - dirty status indicator - before root commit' '
609 printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_green}#${c_clear}):AFTER\\nmain" >expected &&
611 GIT_PS1_SHOWDIRTYSTATE=y &&
612 GIT_PS1_SHOWCOLORHINTS=y &&
613 cd otherrepo &&
614 __git_ps1 "BEFORE:" ":AFTER" &&
615 printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
616 ) &&
617 test_cmp expected "$actual"
620 test_expect_success 'prompt - bash color pc mode - inside .git directory' '
621 printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear}):AFTER\\nGIT_DIR!" >expected &&
622 echo "dirty" >file &&
623 test_when_finished "git reset --hard" &&
625 GIT_PS1_SHOWDIRTYSTATE=y &&
626 GIT_PS1_SHOWCOLORHINTS=y &&
627 cd .git &&
628 __git_ps1 "BEFORE:" ":AFTER" &&
629 printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
630 ) &&
631 test_cmp expected "$actual"
634 test_expect_success 'prompt - bash color pc mode - stash status indicator' '
635 printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_lblue}\$${c_clear}):AFTER\\nmain" >expected &&
636 echo 2 >file &&
637 git stash &&
638 test_when_finished "git stash drop" &&
640 GIT_PS1_SHOWSTASHSTATE=y &&
641 GIT_PS1_SHOWCOLORHINTS=y &&
642 __git_ps1 "BEFORE:" ":AFTER" &&
643 printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
644 ) &&
645 test_cmp expected "$actual"
648 test_expect_success 'prompt - bash color pc mode - untracked files status indicator' '
649 printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_red}%%${c_clear}):AFTER\\nmain" >expected &&
651 GIT_PS1_SHOWUNTRACKEDFILES=y &&
652 GIT_PS1_SHOWCOLORHINTS=y &&
653 __git_ps1 "BEFORE:" ":AFTER" &&
654 printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual"
655 ) &&
656 test_cmp expected "$actual"
659 test_expect_success 'prompt - zsh color pc mode' '
660 printf "BEFORE: (%%F{green}main%%f):AFTER" >expected &&
662 ZSH_VERSION=5.0.0 &&
663 GIT_PS1_SHOWCOLORHINTS=y &&
664 __git_ps1 "BEFORE:" ":AFTER" &&
665 printf "%s" "$PS1" >"$actual"
666 ) &&
667 test_cmp expected "$actual"
670 test_expect_success 'prompt - hide if pwd ignored - env var unset, config disabled' '
671 printf " (main)" >expected &&
672 test_config bash.hideIfPwdIgnored false &&
674 cd ignored_dir &&
675 __git_ps1 >"$actual"
676 ) &&
677 test_cmp expected "$actual"
680 test_expect_success 'prompt - hide if pwd ignored - env var unset, config disabled, pc mode' '
681 printf "BEFORE: (\${__git_ps1_branch_name}):AFTER" >expected &&
682 test_config bash.hideIfPwdIgnored false &&
684 cd ignored_dir &&
685 __git_ps1 "BEFORE:" ":AFTER" &&
686 printf "%s" "$PS1" >"$actual"
687 ) &&
688 test_cmp expected "$actual"
691 test_expect_success 'prompt - hide if pwd ignored - env var unset, config unset' '
692 printf " (main)" >expected &&
694 cd ignored_dir &&
695 __git_ps1 >"$actual"
696 ) &&
697 test_cmp expected "$actual"
700 test_expect_success 'prompt - hide if pwd ignored - env var unset, config unset, pc mode' '
701 printf "BEFORE: (\${__git_ps1_branch_name}):AFTER" >expected &&
703 cd ignored_dir &&
704 __git_ps1 "BEFORE:" ":AFTER" &&
705 printf "%s" "$PS1" >"$actual"
706 ) &&
707 test_cmp expected "$actual"
710 test_expect_success 'prompt - hide if pwd ignored - env var set, config disabled' '
711 printf " (main)" >expected &&
712 test_config bash.hideIfPwdIgnored false &&
714 cd ignored_dir &&
715 GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
716 __git_ps1 >"$actual"
717 ) &&
718 test_cmp expected "$actual"
721 test_expect_success 'prompt - hide if pwd ignored - env var set, config disabled, pc mode' '
722 printf "BEFORE: (\${__git_ps1_branch_name}):AFTER" >expected &&
723 test_config bash.hideIfPwdIgnored false &&
725 cd ignored_dir &&
726 GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
727 __git_ps1 "BEFORE:" ":AFTER" &&
728 printf "%s" "$PS1" >"$actual"
729 ) &&
730 test_cmp expected "$actual"
733 test_expect_success 'prompt - hide if pwd ignored - env var set, config unset' '
735 cd ignored_dir &&
736 GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
737 __git_ps1 >"$actual"
738 ) &&
739 test_must_be_empty "$actual"
742 test_expect_success 'prompt - hide if pwd ignored - env var set, config unset, pc mode' '
743 printf "BEFORE::AFTER" >expected &&
745 cd ignored_dir &&
746 GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
747 __git_ps1 "BEFORE:" ":AFTER" &&
748 printf "%s" "$PS1" >"$actual"
749 ) &&
750 test_cmp expected "$actual"
753 test_expect_success 'prompt - hide if pwd ignored - inside gitdir' '
754 printf " (GIT_DIR!)" >expected &&
756 GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
757 cd .git &&
758 __git_ps1 >"$actual"
759 ) &&
760 test_cmp expected "$actual"
763 test_expect_success 'prompt - conflict indicator' '
764 printf " (main|CONFLICT)" >expected &&
765 echo "stash" >file &&
766 git stash &&
767 test_when_finished "git stash drop" &&
768 echo "commit" >file &&
769 git commit -m "commit" file &&
770 test_when_finished "git reset --hard HEAD~" &&
771 test_must_fail git stash apply &&
773 GIT_PS1_SHOWCONFLICTSTATE="yes" &&
774 __git_ps1 >"$actual"
775 ) &&
776 test_cmp expected "$actual"
779 test_done