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