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