{"thread":{"id":"36705","subject":"[PATCH] git-prompt.sh: don't assume the shell expands the value of PS1","startedAt":"2014-05-19T22:55:37Z","lastAt":"2014-06-11T23:46:21Z","messageCount":35,"participants":["Richard Hansen","Junio C Hamano","Thomas Rast","Torsten Bögershausen","brian m. carlson"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"242213","messageId":"1400540137-29994-1-git-send-email-rhansen@bbn.com","threadId":"36705","inReplyTo":null,"subject":"[PATCH] git-prompt.sh: don't assume the shell expands the value of PS1","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2014-05-19T22:55:37Z","receivedAt":"2014-05-19T22:55:37Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"Not all shells subject the prompt string to parameter expansion.  Test\nwhether the shell will expand the value of PS1, and use the result to\ncontrol whether raw ref names are included directly in PS1.\n\nThis fixes a regression introduced in commit 8976500 (\"git-prompt.sh:\ndon't put unsanitized branch names in $PS1\"):  zsh does not expand PS1\nby default, but that commit assumed it did.  The bug resulted in\nprompts containing the literal string '${__git_ps1_branch_name}'\ninstead of the actual branch name.\n\nReported-by: Caleb Thompson <caleb@calebthompson.io>\nSigned-off-by: Richard Hansen <rhansen@bbn.com>\n---\n\nTo prevent a regression like this from happening again, I plan on\nadding new zsh test cases and expanding the bash test cases (to test\nthe behavior with 'shopt -u promptvars').  I'd like the zsh tests to\ncover the same stuff as the bash tests.  These are the steps I am\nconsidering:\n\n  1. delete the last test case in t9903 (\"prompt - zsh color pc mode\")\n  2. add two new functions to t/lib-bash.sh:\n         ps1_expansion_enable () { shopt -s promptvars; }\n         ps1_expansion_disable () { shopt -u promptvars; }\n  3. loop over the relevant test cases twice:  once after calling\n     ps1_expansion_enable and once after calling ps1_expansion_disable\n     (with appropriate adjustments to the expected output)\n  4. move the test cases in t9903 to a separate library file and\n     source it from t9903-bash-prompt.sh\n  5. create two new files:\n       * t/lib-zsh.sh (same as t/lib-bash.sh but tweaked for zsh)\n       * t/t9904-zsh-prompt.sh (same as t/t9903-bash-prompt.sh but\n         tweaked for zsh)\n\nDoes this approach sound reasonable?\n\n contrib/completion/git-prompt.sh | 56 ++++++++++++++++++++++++++++------------\n t/t9903-bash-prompt.sh           |  6 ++---\n 2 files changed, 42 insertions(+), 20 deletions(-)\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex 853425d..9d684b1 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -209,9 +209,7 @@ __git_ps1_show_upstream ()\n \t\tif [[ -n \"$count\" && -n \"$name\" ]]; then\n \t\t\t__git_ps1_upstream_name=$(git rev-parse \\\n \t\t\t\t--abbrev-ref \"$upstream\" 2>/dev/null)\n-\t\t\tif [ $pcmode = yes ]; then\n-\t\t\t\t# see the comments around the\n-\t\t\t\t# __git_ps1_branch_name variable below\n+\t\t\tif [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then\n \t\t\t\tp=\"$p \\${__git_ps1_upstream_name}\"\n \t\t\telse\n \t\t\t\tp=\"$p ${__git_ps1_upstream_name}\"\n@@ -308,6 +306,43 @@ __git_ps1 ()\n \t\t;;\n \tesac\n \n+\t# ps1_expanded:  This variable is set to 'yes' if the shell\n+\t# subjects the value of PS1 to parameter expansion:\n+\t#\n+\t#   * bash does unless the promptvars option is disabled\n+\t#   * zsh does not unless the PROMPT_SUBST option is set\n+\t#   * POSIX shells always do\n+\t#\n+\t# If the shell would expand the contents of PS1 when drawing\n+\t# the prompt, a raw ref name must not be included in PS1.\n+\t# This protects the user from arbitrary code execution via\n+\t# specially crafted ref names.  For example, a ref named\n+\t# 'refs/heads/$(IFS=_;cmd=sudo_rm_-rf_/;$cmd)' might cause the\n+\t# shell to execute 'sudo rm -rf /' when the prompt is drawn.\n+\t#\n+\t# Instead, the ref name should be placed in a separate global\n+\t# variable (in the __git_ps1_* namespace to avoid colliding\n+\t# with the user's environment) and that variable should be\n+\t# referenced from PS1.  For example:\n+\t#\n+\t#     __git_ps1_foo=$(do_something_to_get_ref_name)\n+\t#     PS1=\"...stuff...\\${__git_ps1_foo}...stuff...\"\n+\t#\n+\t# If the shell does not expand the contents of PS1, the raw\n+\t# ref name must be included in PS1.\n+\t#\n+\t# The value of this variable is only relevant when in pcmode.\n+\t#\n+\t# Assume that the shell follows the POSIX specification and\n+\t# expands PS1 unless determined otherwise.  (This is more\n+\t# likely to be correct if the user has a non-bash, non-zsh\n+\t# shell and safer than the alternative if the assumption is\n+\t# incorrect.)\n+\t#\n+\tlocal ps1_expanded=yes\n+\t[ -z \"$ZSH_VERSION\" ] || [[ -o PROMPT_SUBST ]] || ps1_expanded=no\n+\t[ -z \"$BASH_VERSION\" ] || shopt -q promptvars || ps1_expanded=no\n+\n \tlocal repo_info rev_parse_exit_code\n \trepo_info=\"$(git rev-parse --git-dir --is-inside-git-dir \\\n \t\t--is-bare-repository --is-inside-work-tree \\\n@@ -457,21 +492,8 @@ __git_ps1 ()\n \tfi\n \n \tb=${b##refs/heads/}\n-\tif [ $pcmode = yes ]; then\n-\t\t# In pcmode (and only pcmode) the contents of\n-\t\t# $gitstring are subject to expansion by the shell.\n-\t\t# Avoid putting the raw ref name in the prompt to\n-\t\t# protect the user from arbitrary code execution via\n-\t\t# specially crafted ref names (e.g., a ref named\n-\t\t# '$(IFS=_;cmd=sudo_rm_-rf_/;$cmd)' would execute\n-\t\t# 'sudo rm -rf /' when the prompt is drawn).  Instead,\n-\t\t# put the ref name in a new global variable (in the\n-\t\t# __git_ps1_* namespace to avoid colliding with the\n-\t\t# user's environment) and reference that variable from\n-\t\t# PS1.\n+\tif [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then\n \t\t__git_ps1_branch_name=$b\n-\t\t# note that the $ is escaped -- the variable will be\n-\t\t# expanded later (when it's time to draw the prompt)\n \t\tb=\"\\${__git_ps1_branch_name}\"\n \tfi\n \ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex 6efd0d9..9150984 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -578,12 +578,12 @@ test_expect_success 'prompt - bash color pc mode - untracked files status indica\n '\n \n test_expect_success 'prompt - zsh color pc mode' '\n-\tprintf \"BEFORE: (%%F{green}\\${__git_ps1_branch_name}%%f):AFTER\\\\nmaster\" >expected &&\n+\tprintf \"BEFORE: (%%F{green}master%%f):AFTER\" >expected &&\n \t(\n \t\tZSH_VERSION=5.0.0 &&\n \t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\t__git_ps1 \"BEFORE:\" \":AFTER\" >\"$actual\"\n-\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n+\t\tprintf \"%s\" \"$PS1\" >\"$actual\"\n \t) &&\n \ttest_cmp expected \"$actual\"\n '\n-- \n1.9.3\n"},{"id":"242304","messageId":"xmqqbnusz46e.fsf@gitster.dls.corp.google.com","threadId":"36705","inReplyTo":"1400540137-29994-1-git-send-email-rhansen@bbn.com","subject":"Re: [PATCH] git-prompt.sh: don't assume the shell expands the value of PS1","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-05-20T18:38:17Z","receivedAt":"2014-05-20T18:38:17Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Richard Hansen <rhansen@bbn.com> writes:\n\n> Not all shells subject the prompt string to parameter expansion.  Test\n> whether the shell will expand the value of PS1, and use the result to\n> control whether raw ref names are included directly in PS1.\n>\n> This fixes a regression introduced in commit 8976500 (\"git-prompt.sh:\n> don't put unsanitized branch names in $PS1\"):  zsh does not expand PS1\n> by default, but that commit assumed it did.  The bug resulted in\n> prompts containing the literal string '${__git_ps1_branch_name}'\n> instead of the actual branch name.\n>\n> Reported-by: Caleb Thompson <caleb@calebthompson.io>\n> Signed-off-by: Richard Hansen <rhansen@bbn.com>\n> ---\n\nThanks, applied.\n\n> To prevent a regression like this from happening again, I plan on\n> adding new zsh test cases and expanding the bash test cases (to test\n> the behavior with 'shopt -u promptvars').  I'd like the zsh tests to\n> cover the same stuff as the bash tests.  These are the steps I am\n> considering:\n>\n>   1. delete the last test case in t9903 (\"prompt - zsh color pc mode\")\n>   2. add two new functions to t/lib-bash.sh:\n>          ps1_expansion_enable () { shopt -s promptvars; }\n>          ps1_expansion_disable () { shopt -u promptvars; }\n>   3. loop over the relevant test cases twice:  once after calling\n>      ps1_expansion_enable and once after calling ps1_expansion_disable\n>      (with appropriate adjustments to the expected output)\n>   4. move the test cases in t9903 to a separate library file and\n>      source it from t9903-bash-prompt.sh\n>   5. create two new files:\n>        * t/lib-zsh.sh (same as t/lib-bash.sh but tweaked for zsh)\n>        * t/t9904-zsh-prompt.sh (same as t/t9903-bash-prompt.sh but\n>          tweaked for zsh)\n>\n> Does this approach sound reasonable?\n\nSounds like a plan, especially if step 4 does a reasonable job of\nfactoring out as much common stuff as possible.\n"},{"id":"242724","messageId":"1401176460-31564-1-git-send-email-rhansen@bbn.com","threadId":"36705","inReplyTo":"xmqqbnusz46e.fsf@gitster.dls.corp.google.com","subject":"[PATCH 00/10] Zsh prompt tests","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2014-05-27T07:40:50Z","receivedAt":"2014-05-27T07:40:50Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"This series adds test cases for running __git_ps1 (see\ncontrib/completion/git-prompt.sh) from Zsh.\n\nThis series also adds more Bash test cases to test how __git_ps1\nreacts to disabling Bash's PS1 parameter expansion.  (This is related\nto adding Zsh test cases:  Zsh doesn't perform parameter expansion on\nPS1 by default but many users turn it on, so the Zsh test script must\ntest __git_ps1 in both states.  Bash expands PS1 by default and users\nrarely turn it off, but testing both states in Bash improves the\nsymmetry with the Zsh test cases.)\n\nThis is the approach I took:\n\n  1. delete the last test case in t9903 (\"prompt - zsh color pc mode\")\n  2. add two new functions to t/lib-bash.sh:\n         ps1_expansion_enable () { shopt -s promptvars; }\n         ps1_expansion_disable () { shopt -u promptvars; }\n  3. loop over the relevant test cases twice:  once after calling\n     ps1_expansion_enable and once after calling ps1_expansion_disable\n     (with appropriate adjustments to the expected output)\n  4. move the test cases in t9903 to a separate library file and\n     source it from t9903-bash-prompt.sh\n  5. create two new files:\n       * t/lib-zsh.sh (same as t/lib-bash.sh but tweaked for zsh)\n       * t/t9904-zsh-prompt.sh (same as t/t9903-bash-prompt.sh but\n         tweaked for zsh)\n\nThere are a lot of indendation changes, so I recommend examining the\nchanges via diff -w.\n\nRichard Hansen (10):\n  t9903: remove Zsh test from the suite of Bash prompt tests\n  t9903: put the Bash pc mode prompt test cases in a function\n  t9903: move test name prefix to a separate variable\n  t9903: run pc mode tests again with PS1 expansion disabled\n  t9903: include \"Bash\" in test names via new $shellname var\n  t9903: move PS1 color code variable definitions to lib-bash.sh\n  t9903: move prompt tests to a new lib-prompt-tests.sh file\n  lib-prompt-tests.sh: put all tests inside a function\n  lib-prompt-tests.sh: add variable for string that encodes percent in\n    PS1\n  t9904: new __git_ps1 tests for Zsh\n\n t/lib-bash.sh          |  12 +\n t/lib-prompt-tests.sh  | 633 +++++++++++++++++++++++++++++++++++++++++++++++++\n t/lib-zsh.sh           |  30 +++\n t/t9903-bash-prompt.sh | 582 +--------------------------------------------\n t/t9904-zsh-prompt.sh  |  10 +\n 5 files changed, 687 insertions(+), 580 deletions(-)\n create mode 100644 t/lib-prompt-tests.sh\n create mode 100644 t/lib-zsh.sh\n create mode 100755 t/t9904-zsh-prompt.sh\n\n-- \n1.9.3\n"},{"id":"242723","messageId":"1401176460-31564-2-git-send-email-rhansen@bbn.com","threadId":"36705","inReplyTo":"1401176460-31564-1-git-send-email-rhansen@bbn.com","subject":"[PATCH 01/10] t9903: remove Zsh test from the suite of Bash prompt tests","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2014-05-27T07:40:51Z","receivedAt":"2014-05-27T07:40:51Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"This test is about to become redundant:  All of the Bash prompt tests\nwill be moved into a separate library file that will also be used by a\nnew Zsh-specific test script.\n\nSigned-off-by: Richard Hansen <rhansen@bbn.com>\n---\n t/t9903-bash-prompt.sh | 11 -----------\n 1 file changed, 11 deletions(-)\n\ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex 9150984..335383d 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -577,15 +577,4 @@ test_expect_success 'prompt - bash color pc mode - untracked files status indica\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - zsh color pc mode' '\n-\tprintf \"BEFORE: (%%F{green}master%%f):AFTER\" >expected &&\n-\t(\n-\t\tZSH_VERSION=5.0.0 &&\n-\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\tprintf \"%s\" \"$PS1\" >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n test_done\n-- \n1.9.3\n"},{"id":"242728","messageId":"1401176460-31564-3-git-send-email-rhansen@bbn.com","threadId":"36705","inReplyTo":"1401176460-31564-1-git-send-email-rhansen@bbn.com","subject":"[PATCH 02/10] t9903: put the Bash pc mode prompt test cases in a function","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2014-05-27T07:40:52Z","receivedAt":"2014-05-27T07:40:52Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"This is a step toward invoking the same pc mode test cases twice:\nonce with PS1 parameter expansion enabled and once with it disabled.\n\nSigned-off-by: Richard Hansen <rhansen@bbn.com>\n---\n t/t9903-bash-prompt.sh | 236 +++++++++++++++++++++++++------------------------\n 1 file changed, 120 insertions(+), 116 deletions(-)\n\ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex 335383d..c691869 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -451,130 +451,134 @@ test_expect_success 'prompt - format string starting with dash' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - pc mode' '\n-\tprintf \"BEFORE: (\\${__git_ps1_branch_name}):AFTER\\\\nmaster\" >expected &&\n-\tprintf \"\" >expected_output &&\n-\t(\n-\t\t__git_ps1 \"BEFORE:\" \":AFTER\" >\"$actual\" &&\n-\t\ttest_cmp expected_output \"$actual\" &&\n-\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+run_pcmode_tests () {\n+\ttest_expect_success 'prompt - pc mode' '\n+\t\tprintf \"BEFORE: (\\${__git_ps1_branch_name}):AFTER\\\\nmaster\" >expected &&\n+\t\tprintf \"\" >expected_output &&\n+\t\t(\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" >\"$actual\" &&\n+\t\t\ttest_cmp expected_output \"$actual\" &&\n+\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success 'prompt - bash color pc mode - branch name' '\n-\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear}):AFTER\\\\nmaster\" >expected &&\n-\t(\n-\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\t__git_ps1 \"BEFORE:\" \":AFTER\" >\"$actual\"\n-\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success 'prompt - bash color pc mode - branch name' '\n+\t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear}):AFTER\\\\nmaster\" >expected &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" >\"$actual\"\n+\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success 'prompt - bash color pc mode - detached head' '\n-\tprintf \"BEFORE: (${c_red}\\${__git_ps1_branch_name}${c_clear}):AFTER\\\\n(%s...)\" $(git log -1 --format=\"%h\" b1^) >expected &&\n-\tgit checkout b1^ &&\n-\ttest_when_finished \"git checkout master\" &&\n-\t(\n-\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success 'prompt - bash color pc mode - detached head' '\n+\t\tprintf \"BEFORE: (${c_red}\\${__git_ps1_branch_name}${c_clear}):AFTER\\\\n(%s...)\" $(git log -1 --format=\"%h\" b1^) >expected &&\n+\t\tgit checkout b1^ &&\n+\t\ttest_when_finished \"git checkout master\" &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n+\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty worktree' '\n-\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_red}*${c_clear}):AFTER\\\\nmaster\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty worktree' '\n+\t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_red}*${c_clear}):AFTER\\\\nmaster\" >expected &&\n+\t\techo \"dirty\" >file &&\n+\t\ttest_when_finished \"git reset --hard\" &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n+\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index' '\n-\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_green}+${c_clear}):AFTER\\\\nmaster\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\tgit add -u &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index' '\n+\t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_green}+${c_clear}):AFTER\\\\nmaster\" >expected &&\n+\t\techo \"dirty\" >file &&\n+\t\ttest_when_finished \"git reset --hard\" &&\n+\t\tgit add -u &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n+\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index and worktree' '\n-\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_red}*${c_green}+${c_clear}):AFTER\\\\nmaster\" >expected &&\n-\techo \"dirty index\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\tgit add -u &&\n-\techo \"dirty worktree\" >file &&\n-\t(\n-\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index and worktree' '\n+\t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_red}*${c_green}+${c_clear}):AFTER\\\\nmaster\" >expected &&\n+\t\techo \"dirty index\" >file &&\n+\t\ttest_when_finished \"git reset --hard\" &&\n+\t\tgit add -u &&\n+\t\techo \"dirty worktree\" >file &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n+\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success 'prompt - bash color pc mode - dirty status indicator - before root commit' '\n-\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_green}#${c_clear}):AFTER\\\\nmaster\" >expected &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\tcd otherrepo &&\n-\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success 'prompt - bash color pc mode - dirty status indicator - before root commit' '\n+\t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_green}#${c_clear}):AFTER\\\\nmaster\" >expected &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t\tcd otherrepo &&\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n+\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success 'prompt - bash color pc mode - inside .git directory' '\n-\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear}):AFTER\\\\nGIT_DIR!\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\tcd .git &&\n-\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success 'prompt - bash color pc mode - inside .git directory' '\n+\t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear}):AFTER\\\\nGIT_DIR!\" >expected &&\n+\t\techo \"dirty\" >file &&\n+\t\ttest_when_finished \"git reset --hard\" &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t\tcd .git &&\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n+\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success 'prompt - bash color pc mode - stash status indicator' '\n-\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_lblue}\\$${c_clear}):AFTER\\\\nmaster\" >expected &&\n-\techo 2 >file &&\n-\tgit stash &&\n-\ttest_when_finished \"git stash drop\" &&\n-\t(\n-\t\tGIT_PS1_SHOWSTASHSTATE=y &&\n-\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success 'prompt - bash color pc mode - stash status indicator' '\n+\t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_lblue}\\$${c_clear}):AFTER\\\\nmaster\" >expected &&\n+\t\techo 2 >file &&\n+\t\tgit stash &&\n+\t\ttest_when_finished \"git stash drop\" &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWSTASHSTATE=y &&\n+\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n+\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success 'prompt - bash color pc mode - untracked files status indicator' '\n-\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_red}%%${c_clear}):AFTER\\\\nmaster\" >expected &&\n-\t(\n-\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n-\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success 'prompt - bash color pc mode - untracked files status indicator' '\n+\t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_red}%%${c_clear}):AFTER\\\\nmaster\" >expected &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n+\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n+\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n+}\n+\n+run_pcmode_tests\n \n test_done\n-- \n1.9.3\n"},{"id":"242726","messageId":"1401176460-31564-4-git-send-email-rhansen@bbn.com","threadId":"36705","inReplyTo":"1401176460-31564-1-git-send-email-rhansen@bbn.com","subject":"[PATCH 03/10] t9903: move test name prefix to a separate variable","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2014-05-27T07:40:53Z","receivedAt":"2014-05-27T07:40:53Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"This is a step toward reusing the same test cases after disabling PS1\nparameter expansion.\n\nSigned-off-by: Richard Hansen <rhansen@bbn.com>\n---\n t/t9903-bash-prompt.sh | 20 +++++++++++---------\n 1 file changed, 11 insertions(+), 9 deletions(-)\n\ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex c691869..d29dd2b 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -463,7 +463,9 @@ run_pcmode_tests () {\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n-\ttest_expect_success 'prompt - bash color pc mode - branch name' '\n+\tpfx=\"prompt - bash color pc mode\"\n+\n+\ttest_expect_success \"$pfx - branch name\" '\n \t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear}):AFTER\\\\nmaster\" >expected &&\n \t\t(\n \t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n@@ -473,7 +475,7 @@ run_pcmode_tests () {\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n-\ttest_expect_success 'prompt - bash color pc mode - detached head' '\n+\ttest_expect_success \"$pfx - detached head\" '\n \t\tprintf \"BEFORE: (${c_red}\\${__git_ps1_branch_name}${c_clear}):AFTER\\\\n(%s...)\" $(git log -1 --format=\"%h\" b1^) >expected &&\n \t\tgit checkout b1^ &&\n \t\ttest_when_finished \"git checkout master\" &&\n@@ -485,7 +487,7 @@ run_pcmode_tests () {\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n-\ttest_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty worktree' '\n+\ttest_expect_success \"$pfx - dirty status indicator - dirty worktree\" '\n \t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_red}*${c_clear}):AFTER\\\\nmaster\" >expected &&\n \t\techo \"dirty\" >file &&\n \t\ttest_when_finished \"git reset --hard\" &&\n@@ -498,7 +500,7 @@ run_pcmode_tests () {\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n-\ttest_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index' '\n+\ttest_expect_success \"$pfx - dirty status indicator - dirty index\" '\n \t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_green}+${c_clear}):AFTER\\\\nmaster\" >expected &&\n \t\techo \"dirty\" >file &&\n \t\ttest_when_finished \"git reset --hard\" &&\n@@ -512,7 +514,7 @@ run_pcmode_tests () {\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n-\ttest_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index and worktree' '\n+\ttest_expect_success \"$pfx - dirty status indicator - dirty index and worktree\" '\n \t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_red}*${c_green}+${c_clear}):AFTER\\\\nmaster\" >expected &&\n \t\techo \"dirty index\" >file &&\n \t\ttest_when_finished \"git reset --hard\" &&\n@@ -527,7 +529,7 @@ run_pcmode_tests () {\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n-\ttest_expect_success 'prompt - bash color pc mode - dirty status indicator - before root commit' '\n+\ttest_expect_success \"$pfx - dirty status indicator - before root commit\" '\n \t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_green}#${c_clear}):AFTER\\\\nmaster\" >expected &&\n \t\t(\n \t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n@@ -539,7 +541,7 @@ run_pcmode_tests () {\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n-\ttest_expect_success 'prompt - bash color pc mode - inside .git directory' '\n+\ttest_expect_success \"$pfx - inside .git directory\" '\n \t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear}):AFTER\\\\nGIT_DIR!\" >expected &&\n \t\techo \"dirty\" >file &&\n \t\ttest_when_finished \"git reset --hard\" &&\n@@ -553,7 +555,7 @@ run_pcmode_tests () {\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n-\ttest_expect_success 'prompt - bash color pc mode - stash status indicator' '\n+\ttest_expect_success \"$pfx - stash status indicator\" '\n \t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_lblue}\\$${c_clear}):AFTER\\\\nmaster\" >expected &&\n \t\techo 2 >file &&\n \t\tgit stash &&\n@@ -567,7 +569,7 @@ run_pcmode_tests () {\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n-\ttest_expect_success 'prompt - bash color pc mode - untracked files status indicator' '\n+\ttest_expect_success \"$pfx - untracked files status indicator\" '\n \t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_red}%%${c_clear}):AFTER\\\\nmaster\" >expected &&\n \t\t(\n \t\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n-- \n1.9.3\n"},{"id":"242725","messageId":"1401176460-31564-5-git-send-email-rhansen@bbn.com","threadId":"36705","inReplyTo":"1401176460-31564-1-git-send-email-rhansen@bbn.com","subject":"[PATCH 04/10] t9903: run pc mode tests again with PS1 expansion disabled","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2014-05-27T07:40:54Z","receivedAt":"2014-05-27T07:40:54Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"Bash has a shell option that makes it possible to disable parameter\nexpansion in PS1.  Test __git_ps1's ability to detect and react to\ndisabled PS1 expansion by running the \"pc mode\" tests twice:  once\nwith PS1 parameter expansion enabled and once with it disabled.\n\nSigned-off-by: Richard Hansen <rhansen@bbn.com>\n---\n t/lib-bash.sh          |  3 ++\n t/t9903-bash-prompt.sh | 75 ++++++++++++++++++++++++++++++++++----------------\n 2 files changed, 55 insertions(+), 23 deletions(-)\n\ndiff --git a/t/lib-bash.sh b/t/lib-bash.sh\nindex 2be955f..37a48fd 100644\n--- a/t/lib-bash.sh\n+++ b/t/lib-bash.sh\n@@ -14,4 +14,7 @@ else\n \texit 0\n fi\n \n+ps1_expansion_enable () { shopt -s promptvars; }\n+ps1_expansion_disable () { shopt -u promptvars; }\n+\n . ./test-lib.sh\ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex d29dd2b..fbd77e6 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -451,57 +451,81 @@ test_expect_success 'prompt - format string starting with dash' '\n \ttest_cmp expected \"$actual\"\n '\n \n-run_pcmode_tests () {\n-\ttest_expect_success 'prompt - pc mode' '\n-\t\tprintf \"BEFORE: (\\${__git_ps1_branch_name}):AFTER\\\\nmaster\" >expected &&\n+pcmode_expected () {\n+\tcase $ps1expansion in\n+\ton) printf \"$1\" '${__git_ps1_branch_name}' \"$2\";;\n+\toff) printf \"$1\" \"$2\" \"\";;\n+\tesac >expected\n+}\n+\n+pcmode_actual () {\n+\tcase $ps1expansion in\n+\ton) printf %s\\\\n%s \"$PS1\" \"${__git_ps1_branch_name}\";;\n+\toff) printf %s\\\\n \"$PS1\";;\n+\tesac >\"$actual\"\n+}\n+\n+_run_pcmode_tests () {\n+\tps1expansion=$1; shift\n+\n+\tcase $ps1expansion in\n+\t# if the shell doesn't allow ps1 expansion to be enabled,\n+\t# quietly skip the tests (same goes for disabling)\n+\ton) ps1_expansion_enable || return 0;;\n+\toff) ps1_expansion_disable || return 0;;\n+\t*) error \"invalid argument to _run_pcmode_tests: $ps1expansion\";;\n+\tesac\n+\n+\ttest_expect_success \"prompt - pc mode (PS1 expansion $ps1expansion)\" '\n+\t\tpcmode_expected \"BEFORE: (%s):AFTER\\\\n%s\" master &&\n \t\tprintf \"\" >expected_output &&\n \t\t(\n \t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" >\"$actual\" &&\n \t\t\ttest_cmp expected_output \"$actual\" &&\n-\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t\tpcmode_actual\n \t\t) &&\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n-\tpfx=\"prompt - bash color pc mode\"\n+\tpfx=\"prompt - bash color pc mode (PS1 expansion $ps1expansion)\"\n \n \ttest_expect_success \"$pfx - branch name\" '\n-\t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear}):AFTER\\\\nmaster\" >expected &&\n+\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear}):AFTER\\\\n%s\" master &&\n \t\t(\n \t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n \t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" >\"$actual\"\n-\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t\tpcmode_actual\n \t\t) &&\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n \ttest_expect_success \"$pfx - detached head\" '\n-\t\tprintf \"BEFORE: (${c_red}\\${__git_ps1_branch_name}${c_clear}):AFTER\\\\n(%s...)\" $(git log -1 --format=\"%h\" b1^) >expected &&\n+\t\tpcmode_expected \"BEFORE: (${c_red}%s${c_clear}):AFTER\\\\n%s\" \"($(git log -1 --format=\"%h\" b1^)...)\" &&\n \t\tgit checkout b1^ &&\n \t\ttest_when_finished \"git checkout master\" &&\n \t\t(\n \t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n \t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t\tpcmode_actual\n \t\t) &&\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n \ttest_expect_success \"$pfx - dirty status indicator - dirty worktree\" '\n-\t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_red}*${c_clear}):AFTER\\\\nmaster\" >expected &&\n+\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_red}*${c_clear}):AFTER\\\\n%s\" master &&\n \t\techo \"dirty\" >file &&\n \t\ttest_when_finished \"git reset --hard\" &&\n \t\t(\n \t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n \t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n \t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t\tpcmode_actual\n \t\t) &&\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n \ttest_expect_success \"$pfx - dirty status indicator - dirty index\" '\n-\t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_green}+${c_clear}):AFTER\\\\nmaster\" >expected &&\n+\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_green}+${c_clear}):AFTER\\\\n%s\" master &&\n \t\techo \"dirty\" >file &&\n \t\ttest_when_finished \"git reset --hard\" &&\n \t\tgit add -u &&\n@@ -509,13 +533,13 @@ run_pcmode_tests () {\n \t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n \t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n \t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t\tpcmode_actual\n \t\t) &&\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n \ttest_expect_success \"$pfx - dirty status indicator - dirty index and worktree\" '\n-\t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_red}*${c_green}+${c_clear}):AFTER\\\\nmaster\" >expected &&\n+\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_red}*${c_green}+${c_clear}):AFTER\\\\n%s\" master &&\n \t\techo \"dirty index\" >file &&\n \t\ttest_when_finished \"git reset --hard\" &&\n \t\tgit add -u &&\n@@ -524,25 +548,25 @@ run_pcmode_tests () {\n \t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n \t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n \t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t\tpcmode_actual\n \t\t) &&\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n \ttest_expect_success \"$pfx - dirty status indicator - before root commit\" '\n-\t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_green}#${c_clear}):AFTER\\\\nmaster\" >expected &&\n+\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_green}#${c_clear}):AFTER\\\\n%s\" master &&\n \t\t(\n \t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n \t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n \t\t\tcd otherrepo &&\n \t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t\tpcmode_actual\n \t\t) &&\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n \ttest_expect_success \"$pfx - inside .git directory\" '\n-\t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear}):AFTER\\\\nGIT_DIR!\" >expected &&\n+\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear}):AFTER\\\\n%s\" \"GIT_DIR!\" &&\n \t\techo \"dirty\" >file &&\n \t\ttest_when_finished \"git reset --hard\" &&\n \t\t(\n@@ -550,13 +574,13 @@ run_pcmode_tests () {\n \t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n \t\t\tcd .git &&\n \t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t\tpcmode_actual\n \t\t) &&\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n \ttest_expect_success \"$pfx - stash status indicator\" '\n-\t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_lblue}\\$${c_clear}):AFTER\\\\nmaster\" >expected &&\n+\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_lblue}\\$${c_clear}):AFTER\\\\n%s\" master &&\n \t\techo 2 >file &&\n \t\tgit stash &&\n \t\ttest_when_finished \"git stash drop\" &&\n@@ -564,23 +588,28 @@ run_pcmode_tests () {\n \t\t\tGIT_PS1_SHOWSTASHSTATE=y &&\n \t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n \t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t\tpcmode_actual\n \t\t) &&\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n \ttest_expect_success \"$pfx - untracked files status indicator\" '\n-\t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_red}%%${c_clear}):AFTER\\\\nmaster\" >expected &&\n+\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_red}%%${c_clear}):AFTER\\\\n%s\" master &&\n \t\t(\n \t\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n \t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n \t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t\tpcmode_actual\n \t\t) &&\n \t\ttest_cmp expected \"$actual\"\n \t'\n }\n \n+run_pcmode_tests () {\n+\t_run_pcmode_tests on\n+\t_run_pcmode_tests off\n+}\n+\n run_pcmode_tests\n \n test_done\n-- \n1.9.3\n"},{"id":"242733","messageId":"1401176460-31564-6-git-send-email-rhansen@bbn.com","threadId":"36705","inReplyTo":"1401176460-31564-1-git-send-email-rhansen@bbn.com","subject":"[PATCH 05/10] t9903: include \"Bash\" in test names via new $shellname var","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2014-05-27T07:40:55Z","receivedAt":"2014-05-27T07:40:55Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"Define a new 'shellname' variable in lib-bash.sh and use it in the\nprompt test names.  This is a step toward moving the shell prompt\ntests to a separate library file so that they can be reused to test\nprompting in Zsh.\n\nSigned-off-by: Richard Hansen <rhansen@bbn.com>\n---\n t/lib-bash.sh          |  2 ++\n t/t9903-bash-prompt.sh | 86 ++++++++++++++++++++++++++------------------------\n 2 files changed, 46 insertions(+), 42 deletions(-)\n\ndiff --git a/t/lib-bash.sh b/t/lib-bash.sh\nindex 37a48fd..a0f4e16 100644\n--- a/t/lib-bash.sh\n+++ b/t/lib-bash.sh\n@@ -14,6 +14,8 @@ else\n \texit 0\n fi\n \n+shellname=Bash\n+\n ps1_expansion_enable () { shopt -s promptvars; }\n ps1_expansion_disable () { shopt -u promptvars; }\n \ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex fbd77e6..05ff246 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -15,7 +15,7 @@ c_green='\\\\[\\\\e[32m\\\\]'\n c_lblue='\\\\[\\\\e[1;34m\\\\]'\n c_clear='\\\\[\\\\e[0m\\\\]'\n \n-test_expect_success 'setup for prompt tests' '\n+test_expect_success \"setup for $shellname prompt tests\" '\n \tgit init otherrepo &&\n \techo 1 >file &&\n \tgit add file &&\n@@ -38,13 +38,15 @@ test_expect_success 'setup for prompt tests' '\n \tgit checkout master\n '\n \n-test_expect_success 'prompt - branch name' '\n+pfx=\"$shellname prompt\"\n+\n+test_expect_success \"$pfx - branch name\" '\n \tprintf \" (master)\" >expected &&\n \t__git_ps1 >\"$actual\" &&\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success SYMLINKS 'prompt - branch name - symlink symref' '\n+test_expect_success SYMLINKS \"$pfx - branch name - symlink symref\" '\n \tprintf \" (master)\" >expected &&\n \ttest_when_finished \"git checkout master\" &&\n \ttest_config core.preferSymlinkRefs true &&\n@@ -53,7 +55,7 @@ test_expect_success SYMLINKS 'prompt - branch name - symlink symref' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - unborn branch' '\n+test_expect_success \"$pfx - unborn branch\" '\n \tprintf \" (unborn)\" >expected &&\n \tgit checkout --orphan unborn &&\n \ttest_when_finished \"git checkout master\" &&\n@@ -72,7 +74,7 @@ else\n \tsay 'Your filesystem does not allow newlines in filenames.'\n fi\n \n-test_expect_success FUNNYNAMES 'prompt - with newline in path' '\n+test_expect_success FUNNYNAMES \"$pfx - with newline in path\" '\n \tprintf \" (master)\" >expected &&\n \tgit init \"$repo_with_newline\" &&\n \ttest_when_finished \"rm -rf \\\"$repo_with_newline\\\"\" &&\n@@ -84,7 +86,7 @@ test_expect_success FUNNYNAMES 'prompt - with newline in path' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - detached head' '\n+test_expect_success \"$pfx - detached head\" '\n \tprintf \" ((%s...))\" $(git log -1 --format=\"%h\" --abbrev=13 b1^) >expected &&\n \ttest_config core.abbrev 13 &&\n \tgit checkout b1^ &&\n@@ -93,7 +95,7 @@ test_expect_success 'prompt - detached head' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - describe detached head - contains' '\n+test_expect_success \"$pfx - describe detached head - contains\" '\n \tprintf \" ((t2~1))\" >expected &&\n \tgit checkout b1^ &&\n \ttest_when_finished \"git checkout master\" &&\n@@ -104,7 +106,7 @@ test_expect_success 'prompt - describe detached head - contains' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - describe detached head - branch' '\n+test_expect_success \"$pfx - describe detached head - branch\" '\n \tprintf \" ((b1~1))\" >expected &&\n \tgit checkout b1^ &&\n \ttest_when_finished \"git checkout master\" &&\n@@ -115,7 +117,7 @@ test_expect_success 'prompt - describe detached head - branch' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - describe detached head - describe' '\n+test_expect_success \"$pfx - describe detached head - describe\" '\n \tprintf \" ((t1-1-g%s))\" $(git log -1 --format=\"%h\" b1^) >expected &&\n \tgit checkout b1^ &&\n \ttest_when_finished \"git checkout master\" &&\n@@ -126,7 +128,7 @@ test_expect_success 'prompt - describe detached head - describe' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - describe detached head - default' '\n+test_expect_success \"$pfx - describe detached head - default\" '\n \tprintf \" ((t2))\" >expected &&\n \tgit checkout --detach b1 &&\n \ttest_when_finished \"git checkout master\" &&\n@@ -134,7 +136,7 @@ test_expect_success 'prompt - describe detached head - default' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - inside .git directory' '\n+test_expect_success \"$pfx - inside .git directory\" '\n \tprintf \" (GIT_DIR!)\" >expected &&\n \t(\n \t\tcd .git &&\n@@ -143,7 +145,7 @@ test_expect_success 'prompt - inside .git directory' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - deep inside .git directory' '\n+test_expect_success \"$pfx - deep inside .git directory\" '\n \tprintf \" (GIT_DIR!)\" >expected &&\n \t(\n \t\tcd .git/refs/heads &&\n@@ -152,7 +154,7 @@ test_expect_success 'prompt - deep inside .git directory' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - inside bare repository' '\n+test_expect_success \"$pfx - inside bare repository\" '\n \tprintf \" (BARE:master)\" >expected &&\n \tgit init --bare bare.git &&\n \ttest_when_finished \"rm -rf bare.git\" &&\n@@ -163,7 +165,7 @@ test_expect_success 'prompt - inside bare repository' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - interactive rebase' '\n+test_expect_success \"$pfx - interactive rebase\" '\n \tprintf \" (b1|REBASE-i 2/3)\" >expected\n \twrite_script fake_editor.sh <<-\\EOF &&\n \t\techo \"exec echo\" >\"$1\"\n@@ -180,7 +182,7 @@ test_expect_success 'prompt - interactive rebase' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - rebase merge' '\n+test_expect_success \"$pfx - rebase merge\" '\n \tprintf \" (b2|REBASE-m 1/3)\" >expected &&\n \tgit checkout b2 &&\n \ttest_when_finished \"git checkout master\" &&\n@@ -190,7 +192,7 @@ test_expect_success 'prompt - rebase merge' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - rebase' '\n+test_expect_success \"$pfx - rebase\" '\n \tprintf \" (b2|REBASE 1/3)\" >expected &&\n \tgit checkout b2 &&\n \ttest_when_finished \"git checkout master\" &&\n@@ -200,7 +202,7 @@ test_expect_success 'prompt - rebase' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - merge' '\n+test_expect_success \"$pfx - merge\" '\n \tprintf \" (b1|MERGING)\" >expected &&\n \tgit checkout b1 &&\n \ttest_when_finished \"git checkout master\" &&\n@@ -210,7 +212,7 @@ test_expect_success 'prompt - merge' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - cherry-pick' '\n+test_expect_success \"$pfx - cherry-pick\" '\n \tprintf \" (master|CHERRY-PICKING)\" >expected &&\n \ttest_must_fail git cherry-pick b1 &&\n \ttest_when_finished \"git reset --hard\" &&\n@@ -218,7 +220,7 @@ test_expect_success 'prompt - cherry-pick' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - bisect' '\n+test_expect_success \"$pfx - bisect\" '\n \tprintf \" (master|BISECTING)\" >expected &&\n \tgit bisect start &&\n \ttest_when_finished \"git bisect reset\" &&\n@@ -226,7 +228,7 @@ test_expect_success 'prompt - bisect' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - dirty status indicator - clean' '\n+test_expect_success \"$pfx - dirty status indicator - clean\" '\n \tprintf \" (master)\" >expected &&\n \t(\n \t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n@@ -235,7 +237,7 @@ test_expect_success 'prompt - dirty status indicator - clean' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - dirty status indicator - dirty worktree' '\n+test_expect_success \"$pfx - dirty status indicator - dirty worktree\" '\n \tprintf \" (master *)\" >expected &&\n \techo \"dirty\" >file &&\n \ttest_when_finished \"git reset --hard\" &&\n@@ -246,7 +248,7 @@ test_expect_success 'prompt - dirty status indicator - dirty worktree' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - dirty status indicator - dirty index' '\n+test_expect_success \"$pfx - dirty status indicator - dirty index\" '\n \tprintf \" (master +)\" >expected &&\n \techo \"dirty\" >file &&\n \ttest_when_finished \"git reset --hard\" &&\n@@ -258,7 +260,7 @@ test_expect_success 'prompt - dirty status indicator - dirty index' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - dirty status indicator - dirty index and worktree' '\n+test_expect_success \"$pfx - dirty status indicator - dirty index and worktree\" '\n \tprintf \" (master *+)\" >expected &&\n \techo \"dirty index\" >file &&\n \ttest_when_finished \"git reset --hard\" &&\n@@ -271,7 +273,7 @@ test_expect_success 'prompt - dirty status indicator - dirty index and worktree'\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - dirty status indicator - before root commit' '\n+test_expect_success \"$pfx - dirty status indicator - before root commit\" '\n \tprintf \" (master #)\" >expected &&\n \t(\n \t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n@@ -281,7 +283,7 @@ test_expect_success 'prompt - dirty status indicator - before root commit' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - dirty status indicator - shell variable unset with config disabled' '\n+test_expect_success \"$pfx - dirty status indicator - shell variable unset with config disabled\" '\n \tprintf \" (master)\" >expected &&\n \techo \"dirty\" >file &&\n \ttest_when_finished \"git reset --hard\" &&\n@@ -293,7 +295,7 @@ test_expect_success 'prompt - dirty status indicator - shell variable unset with\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - dirty status indicator - shell variable unset with config enabled' '\n+test_expect_success \"$pfx - dirty status indicator - shell variable unset with config enabled\" '\n \tprintf \" (master)\" >expected &&\n \techo \"dirty\" >file &&\n \ttest_when_finished \"git reset --hard\" &&\n@@ -305,7 +307,7 @@ test_expect_success 'prompt - dirty status indicator - shell variable unset with\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - dirty status indicator - shell variable set with config disabled' '\n+test_expect_success \"$pfx - dirty status indicator - shell variable set with config disabled\" '\n \tprintf \" (master)\" >expected &&\n \techo \"dirty\" >file &&\n \ttest_when_finished \"git reset --hard\" &&\n@@ -317,7 +319,7 @@ test_expect_success 'prompt - dirty status indicator - shell variable set with c\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - dirty status indicator - shell variable set with config enabled' '\n+test_expect_success \"$pfx - dirty status indicator - shell variable set with config enabled\" '\n \tprintf \" (master *)\" >expected &&\n \techo \"dirty\" >file &&\n \ttest_when_finished \"git reset --hard\" &&\n@@ -329,7 +331,7 @@ test_expect_success 'prompt - dirty status indicator - shell variable set with c\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - dirty status indicator - not shown inside .git directory' '\n+test_expect_success \"$pfx - dirty status indicator - not shown inside .git directory\" '\n \tprintf \" (GIT_DIR!)\" >expected &&\n \techo \"dirty\" >file &&\n \ttest_when_finished \"git reset --hard\" &&\n@@ -341,7 +343,7 @@ test_expect_success 'prompt - dirty status indicator - not shown inside .git dir\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - stash status indicator - no stash' '\n+test_expect_success \"$pfx - stash status indicator - no stash\" '\n \tprintf \" (master)\" >expected &&\n \t(\n \t\tGIT_PS1_SHOWSTASHSTATE=y &&\n@@ -350,7 +352,7 @@ test_expect_success 'prompt - stash status indicator - no stash' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - stash status indicator - stash' '\n+test_expect_success \"$pfx - stash status indicator - stash\" '\n \tprintf \" (master $)\" >expected &&\n \techo 2 >file &&\n \tgit stash &&\n@@ -363,7 +365,7 @@ test_expect_success 'prompt - stash status indicator - stash' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - stash status indicator - not shown inside .git directory' '\n+test_expect_success \"$pfx - stash status indicator - not shown inside .git directory\" '\n \tprintf \" (GIT_DIR!)\" >expected &&\n \techo 2 >file &&\n \tgit stash &&\n@@ -376,7 +378,7 @@ test_expect_success 'prompt - stash status indicator - not shown inside .git dir\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - untracked files status indicator - no untracked files' '\n+test_expect_success \"$pfx - untracked files status indicator - no untracked files\" '\n \tprintf \" (master)\" >expected &&\n \t(\n \t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n@@ -386,7 +388,7 @@ test_expect_success 'prompt - untracked files status indicator - no untracked fi\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - untracked files status indicator - untracked files' '\n+test_expect_success \"$pfx - untracked files status indicator - untracked files\" '\n \tprintf \" (master %%)\" >expected &&\n \t(\n \t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n@@ -395,7 +397,7 @@ test_expect_success 'prompt - untracked files status indicator - untracked files\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - untracked files status indicator - shell variable unset with config disabled' '\n+test_expect_success \"$pfx - untracked files status indicator - shell variable unset with config disabled\" '\n \tprintf \" (master)\" >expected &&\n \ttest_config bash.showUntrackedFiles false &&\n \t(\n@@ -405,7 +407,7 @@ test_expect_success 'prompt - untracked files status indicator - shell variable\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - untracked files status indicator - shell variable unset with config enabled' '\n+test_expect_success \"$pfx - untracked files status indicator - shell variable unset with config enabled\" '\n \tprintf \" (master)\" >expected &&\n \ttest_config bash.showUntrackedFiles true &&\n \t(\n@@ -415,7 +417,7 @@ test_expect_success 'prompt - untracked files status indicator - shell variable\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - untracked files status indicator - shell variable set with config disabled' '\n+test_expect_success \"$pfx - untracked files status indicator - shell variable set with config disabled\" '\n \tprintf \" (master)\" >expected &&\n \ttest_config bash.showUntrackedFiles false &&\n \t(\n@@ -425,7 +427,7 @@ test_expect_success 'prompt - untracked files status indicator - shell variable\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - untracked files status indicator - shell variable set with config enabled' '\n+test_expect_success \"$pfx - untracked files status indicator - shell variable set with config enabled\" '\n \tprintf \" (master %%)\" >expected &&\n \ttest_config bash.showUntrackedFiles true &&\n \t(\n@@ -435,7 +437,7 @@ test_expect_success 'prompt - untracked files status indicator - shell variable\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - untracked files status indicator - not shown inside .git directory' '\n+test_expect_success \"$pfx - untracked files status indicator - not shown inside .git directory\" '\n \tprintf \" (GIT_DIR!)\" >expected &&\n \t(\n \t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n@@ -445,7 +447,7 @@ test_expect_success 'prompt - untracked files status indicator - not shown insid\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - format string starting with dash' '\n+test_expect_success \"$pfx - format string starting with dash\" '\n \tprintf -- \"-master\" >expected &&\n \t__git_ps1 \"-%s\" >\"$actual\" &&\n \ttest_cmp expected \"$actual\"\n@@ -476,7 +478,7 @@ _run_pcmode_tests () {\n \t*) error \"invalid argument to _run_pcmode_tests: $ps1expansion\";;\n \tesac\n \n-\ttest_expect_success \"prompt - pc mode (PS1 expansion $ps1expansion)\" '\n+\ttest_expect_success \"$shellname prompt - pc mode (PS1 expansion $ps1expansion)\" '\n \t\tpcmode_expected \"BEFORE: (%s):AFTER\\\\n%s\" master &&\n \t\tprintf \"\" >expected_output &&\n \t\t(\n@@ -487,7 +489,7 @@ _run_pcmode_tests () {\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n-\tpfx=\"prompt - bash color pc mode (PS1 expansion $ps1expansion)\"\n+\tpfx=\"$shellname prompt - color pc mode (PS1 expansion $ps1expansion)\"\n \n \ttest_expect_success \"$pfx - branch name\" '\n \t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear}):AFTER\\\\n%s\" master &&\n-- \n1.9.3\n"},{"id":"242729","messageId":"1401176460-31564-7-git-send-email-rhansen@bbn.com","threadId":"36705","inReplyTo":"1401176460-31564-1-git-send-email-rhansen@bbn.com","subject":"[PATCH 06/10] t9903: move PS1 color code variable definitions to lib-bash.sh","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2014-05-27T07:40:56Z","receivedAt":"2014-05-27T07:40:56Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"Define a new 'set_ps1_format_vars' function in lib-bash.sh that sets\nthe c_red, c_green, c_lblue, and c_clear variables.  Call this\nfunction from run_pcmode_tests().  This is a step toward moving the\nshell prompt tests to a separate library file so that they can be\nreused to test prompting in Zsh.\n\nSigned-off-by: Richard Hansen <rhansen@bbn.com>\n---\n t/lib-bash.sh          | 6 ++++++\n t/t9903-bash-prompt.sh | 5 +----\n 2 files changed, 7 insertions(+), 4 deletions(-)\n\ndiff --git a/t/lib-bash.sh b/t/lib-bash.sh\nindex a0f4e16..9d428bd 100644\n--- a/t/lib-bash.sh\n+++ b/t/lib-bash.sh\n@@ -18,5 +18,11 @@ shellname=Bash\n \n ps1_expansion_enable () { shopt -s promptvars; }\n ps1_expansion_disable () { shopt -u promptvars; }\n+set_ps1_format_vars () {\n+\tc_red='\\\\[\\\\e[31m\\\\]'\n+\tc_green='\\\\[\\\\e[32m\\\\]'\n+\tc_lblue='\\\\[\\\\e[1;34m\\\\]'\n+\tc_clear='\\\\[\\\\e[0m\\\\]'\n+}\n \n . ./test-lib.sh\ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex 05ff246..ef10e34 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -10,10 +10,7 @@ test_description='test git-specific bash prompt functions'\n . \"$GIT_BUILD_DIR/contrib/completion/git-prompt.sh\"\n \n actual=\"$TRASH_DIRECTORY/actual\"\n-c_red='\\\\[\\\\e[31m\\\\]'\n-c_green='\\\\[\\\\e[32m\\\\]'\n-c_lblue='\\\\[\\\\e[1;34m\\\\]'\n-c_clear='\\\\[\\\\e[0m\\\\]'\n+set_ps1_format_vars\n \n test_expect_success \"setup for $shellname prompt tests\" '\n \tgit init otherrepo &&\n-- \n1.9.3\n"},{"id":"242732","messageId":"1401176460-31564-8-git-send-email-rhansen@bbn.com","threadId":"36705","inReplyTo":"1401176460-31564-1-git-send-email-rhansen@bbn.com","subject":"[PATCH 07/10] t9903: move prompt tests to a new lib-prompt-tests.sh file","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2014-05-27T07:40:57Z","receivedAt":"2014-05-27T07:40:57Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"This is a step toward creating a new test script that runs the same\nprompt tests as t9903 but with Zsh instead of Bash.\n\nSigned-off-by: Richard Hansen <rhansen@bbn.com>\n---\n t/lib-prompt-tests.sh  | 632 +++++++++++++++++++++++++++++++++++++++++++++++++\n t/t9903-bash-prompt.sh | 605 +---------------------------------------------\n 2 files changed, 633 insertions(+), 604 deletions(-)\n create mode 100644 t/lib-prompt-tests.sh\n\ndiff --git a/t/lib-prompt-tests.sh b/t/lib-prompt-tests.sh\nnew file mode 100644\nindex 0000000..32c3c08\n--- /dev/null\n+++ b/t/lib-prompt-tests.sh\n@@ -0,0 +1,632 @@\n+# Copyright (c) 2012 SZEDER Gábor\n+\n+# To use this library:\n+#   1. set the variable shellname to the name of the shell (e.g.,\n+#      \"Bash\")\n+#   2. define functions named ps1_expansion_enable and\n+#      ps1_expansion_disable that, upon return, guarantee that the\n+#      shell will and will not (respectively) perform parameter\n+#      expansion on PS1, if supported by the shell.  If it is not\n+#      possible to configure the shell to disable (enable) PS1\n+#      expansion, ps1_expansion_enable should simply return 0\n+#      (non-zero) and ps1_expansion_disable should simply return\n+#      non-zero (0)\n+#   3. define a function named set_ps1_format_vars that sets the\n+#      variables c_red, c_green, c_lblue, and c_clear to the strings\n+#      that __git_ps1 uses to add color to the prompt.  The values of\n+#      these variables are used in the first argument to the printf\n+#      command, so they must be escaped appropriately.\n+#   4. source this library\n+\n+# sanity checks\n+[ -n \"$shellname\" ] || error \"shellname must be set to the name of the shell\"\n+for i in ps1_expansion_enable ps1_expansion_disable set_ps1_format_vars\n+do\n+\tcommand -v \"$i\" >/dev/null 2>&1 || error \"function $i not defined\"\n+done\n+(ps1_expansion_enable || ps1_expansion_disable) \\\n+\t|| error \"either ps1_expansion_enable or ps1_expansion_disable must return true\"\n+\n+. \"$GIT_BUILD_DIR/contrib/completion/git-prompt.sh\"\n+\n+actual=\"$TRASH_DIRECTORY/actual\"\n+set_ps1_format_vars\n+\n+test_expect_success \"setup for $shellname prompt tests\" '\n+\tgit init otherrepo &&\n+\techo 1 >file &&\n+\tgit add file &&\n+\ttest_tick &&\n+\tgit commit -m initial &&\n+\tgit tag -a -m msg1 t1 &&\n+\tgit checkout -b b1 &&\n+\techo 2 >file &&\n+\tgit commit -m \"second b1\" file &&\n+\techo 3 >file &&\n+\tgit commit -m \"third b1\" file &&\n+\tgit tag -a -m msg2 t2 &&\n+\tgit checkout -b b2 master &&\n+\techo 0 >file &&\n+\tgit commit -m \"second b2\" file &&\n+\techo 00 >file &&\n+\tgit commit -m \"another b2\" file &&\n+\techo 000 >file &&\n+\tgit commit -m \"yet another b2\" file &&\n+\tgit checkout master\n+'\n+\n+pfx=\"$shellname prompt\"\n+\n+test_expect_success \"$pfx - branch name\" '\n+\tprintf \" (master)\" >expected &&\n+\t__git_ps1 >\"$actual\" &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success SYMLINKS \"$pfx - branch name - symlink symref\" '\n+\tprintf \" (master)\" >expected &&\n+\ttest_when_finished \"git checkout master\" &&\n+\ttest_config core.preferSymlinkRefs true &&\n+\tgit checkout master &&\n+\t__git_ps1 >\"$actual\" &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - unborn branch\" '\n+\tprintf \" (unborn)\" >expected &&\n+\tgit checkout --orphan unborn &&\n+\ttest_when_finished \"git checkout master\" &&\n+\t__git_ps1 >\"$actual\" &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+repo_with_newline='repo\n+with\n+newline'\n+\n+if mkdir \"$repo_with_newline\" 2>/dev/null\n+then\n+\ttest_set_prereq FUNNYNAMES\n+else\n+\tsay 'Your filesystem does not allow newlines in filenames.'\n+fi\n+\n+test_expect_success FUNNYNAMES \"$pfx - with newline in path\" '\n+\tprintf \" (master)\" >expected &&\n+\tgit init \"$repo_with_newline\" &&\n+\ttest_when_finished \"rm -rf \\\"$repo_with_newline\\\"\" &&\n+\tmkdir \"$repo_with_newline\"/subdir &&\n+\t(\n+\t\tcd \"$repo_with_newline/subdir\" &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - detached head\" '\n+\tprintf \" ((%s...))\" $(git log -1 --format=\"%h\" --abbrev=13 b1^) >expected &&\n+\ttest_config core.abbrev 13 &&\n+\tgit checkout b1^ &&\n+\ttest_when_finished \"git checkout master\" &&\n+\t__git_ps1 >\"$actual\" &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - describe detached head - contains\" '\n+\tprintf \" ((t2~1))\" >expected &&\n+\tgit checkout b1^ &&\n+\ttest_when_finished \"git checkout master\" &&\n+\t(\n+\t\tGIT_PS1_DESCRIBE_STYLE=contains &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - describe detached head - branch\" '\n+\tprintf \" ((b1~1))\" >expected &&\n+\tgit checkout b1^ &&\n+\ttest_when_finished \"git checkout master\" &&\n+\t(\n+\t\tGIT_PS1_DESCRIBE_STYLE=branch &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - describe detached head - describe\" '\n+\tprintf \" ((t1-1-g%s))\" $(git log -1 --format=\"%h\" b1^) >expected &&\n+\tgit checkout b1^ &&\n+\ttest_when_finished \"git checkout master\" &&\n+\t(\n+\t\tGIT_PS1_DESCRIBE_STYLE=describe &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - describe detached head - default\" '\n+\tprintf \" ((t2))\" >expected &&\n+\tgit checkout --detach b1 &&\n+\ttest_when_finished \"git checkout master\" &&\n+\t__git_ps1 >\"$actual\" &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - inside .git directory\" '\n+\tprintf \" (GIT_DIR!)\" >expected &&\n+\t(\n+\t\tcd .git &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - deep inside .git directory\" '\n+\tprintf \" (GIT_DIR!)\" >expected &&\n+\t(\n+\t\tcd .git/refs/heads &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - inside bare repository\" '\n+\tprintf \" (BARE:master)\" >expected &&\n+\tgit init --bare bare.git &&\n+\ttest_when_finished \"rm -rf bare.git\" &&\n+\t(\n+\t\tcd bare.git &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - interactive rebase\" '\n+\tprintf \" (b1|REBASE-i 2/3)\" >expected\n+\twrite_script fake_editor.sh <<-\\EOF &&\n+\t\techo \"exec echo\" >\"$1\"\n+\t\techo \"edit $(git log -1 --format=\"%h\")\" >>\"$1\"\n+\t\techo \"exec echo\" >>\"$1\"\n+\tEOF\n+\ttest_when_finished \"rm -f fake_editor.sh\" &&\n+\ttest_set_editor \"$TRASH_DIRECTORY/fake_editor.sh\" &&\n+\tgit checkout b1 &&\n+\ttest_when_finished \"git checkout master\" &&\n+\tgit rebase -i HEAD^ &&\n+\ttest_when_finished \"git rebase --abort\"\n+\t__git_ps1 >\"$actual\" &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - rebase merge\" '\n+\tprintf \" (b2|REBASE-m 1/3)\" >expected &&\n+\tgit checkout b2 &&\n+\ttest_when_finished \"git checkout master\" &&\n+\ttest_must_fail git rebase --merge b1 b2 &&\n+\ttest_when_finished \"git rebase --abort\" &&\n+\t__git_ps1 >\"$actual\" &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - rebase\" '\n+\tprintf \" (b2|REBASE 1/3)\" >expected &&\n+\tgit checkout b2 &&\n+\ttest_when_finished \"git checkout master\" &&\n+\ttest_must_fail git rebase b1 b2 &&\n+\ttest_when_finished \"git rebase --abort\" &&\n+\t__git_ps1 >\"$actual\" &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - merge\" '\n+\tprintf \" (b1|MERGING)\" >expected &&\n+\tgit checkout b1 &&\n+\ttest_when_finished \"git checkout master\" &&\n+\ttest_must_fail git merge b2 &&\n+\ttest_when_finished \"git reset --hard\" &&\n+\t__git_ps1 >\"$actual\" &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - cherry-pick\" '\n+\tprintf \" (master|CHERRY-PICKING)\" >expected &&\n+\ttest_must_fail git cherry-pick b1 &&\n+\ttest_when_finished \"git reset --hard\" &&\n+\t__git_ps1 >\"$actual\" &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - bisect\" '\n+\tprintf \" (master|BISECTING)\" >expected &&\n+\tgit bisect start &&\n+\ttest_when_finished \"git bisect reset\" &&\n+\t__git_ps1 >\"$actual\" &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - dirty status indicator - clean\" '\n+\tprintf \" (master)\" >expected &&\n+\t(\n+\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - dirty status indicator - dirty worktree\" '\n+\tprintf \" (master *)\" >expected &&\n+\techo \"dirty\" >file &&\n+\ttest_when_finished \"git reset --hard\" &&\n+\t(\n+\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - dirty status indicator - dirty index\" '\n+\tprintf \" (master +)\" >expected &&\n+\techo \"dirty\" >file &&\n+\ttest_when_finished \"git reset --hard\" &&\n+\tgit add -u &&\n+\t(\n+\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - dirty status indicator - dirty index and worktree\" '\n+\tprintf \" (master *+)\" >expected &&\n+\techo \"dirty index\" >file &&\n+\ttest_when_finished \"git reset --hard\" &&\n+\tgit add -u &&\n+\techo \"dirty worktree\" >file &&\n+\t(\n+\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - dirty status indicator - before root commit\" '\n+\tprintf \" (master #)\" >expected &&\n+\t(\n+\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\tcd otherrepo &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - dirty status indicator - shell variable unset with config disabled\" '\n+\tprintf \" (master)\" >expected &&\n+\techo \"dirty\" >file &&\n+\ttest_when_finished \"git reset --hard\" &&\n+\ttest_config bash.showDirtyState false &&\n+\t(\n+\t\tsane_unset GIT_PS1_SHOWDIRTYSTATE &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - dirty status indicator - shell variable unset with config enabled\" '\n+\tprintf \" (master)\" >expected &&\n+\techo \"dirty\" >file &&\n+\ttest_when_finished \"git reset --hard\" &&\n+\ttest_config bash.showDirtyState true &&\n+\t(\n+\t\tsane_unset GIT_PS1_SHOWDIRTYSTATE &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - dirty status indicator - shell variable set with config disabled\" '\n+\tprintf \" (master)\" >expected &&\n+\techo \"dirty\" >file &&\n+\ttest_when_finished \"git reset --hard\" &&\n+\ttest_config bash.showDirtyState false &&\n+\t(\n+\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - dirty status indicator - shell variable set with config enabled\" '\n+\tprintf \" (master *)\" >expected &&\n+\techo \"dirty\" >file &&\n+\ttest_when_finished \"git reset --hard\" &&\n+\ttest_config bash.showDirtyState true &&\n+\t(\n+\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - dirty status indicator - not shown inside .git directory\" '\n+\tprintf \" (GIT_DIR!)\" >expected &&\n+\techo \"dirty\" >file &&\n+\ttest_when_finished \"git reset --hard\" &&\n+\t(\n+\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\tcd .git &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - stash status indicator - no stash\" '\n+\tprintf \" (master)\" >expected &&\n+\t(\n+\t\tGIT_PS1_SHOWSTASHSTATE=y &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - stash status indicator - stash\" '\n+\tprintf \" (master $)\" >expected &&\n+\techo 2 >file &&\n+\tgit stash &&\n+\ttest_when_finished \"git stash drop\" &&\n+\tgit pack-refs --all &&\n+\t(\n+\t\tGIT_PS1_SHOWSTASHSTATE=y &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - stash status indicator - not shown inside .git directory\" '\n+\tprintf \" (GIT_DIR!)\" >expected &&\n+\techo 2 >file &&\n+\tgit stash &&\n+\ttest_when_finished \"git stash drop\" &&\n+\t(\n+\t\tGIT_PS1_SHOWSTASHSTATE=y &&\n+\t\tcd .git &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - untracked files status indicator - no untracked files\" '\n+\tprintf \" (master)\" >expected &&\n+\t(\n+\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n+\t\tcd otherrepo &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - untracked files status indicator - untracked files\" '\n+\tprintf \" (master %%)\" >expected &&\n+\t(\n+\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - untracked files status indicator - shell variable unset with config disabled\" '\n+\tprintf \" (master)\" >expected &&\n+\ttest_config bash.showUntrackedFiles false &&\n+\t(\n+\t\tsane_unset GIT_PS1_SHOWUNTRACKEDFILES &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - untracked files status indicator - shell variable unset with config enabled\" '\n+\tprintf \" (master)\" >expected &&\n+\ttest_config bash.showUntrackedFiles true &&\n+\t(\n+\t\tsane_unset GIT_PS1_SHOWUNTRACKEDFILES &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - untracked files status indicator - shell variable set with config disabled\" '\n+\tprintf \" (master)\" >expected &&\n+\ttest_config bash.showUntrackedFiles false &&\n+\t(\n+\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - untracked files status indicator - shell variable set with config enabled\" '\n+\tprintf \" (master %%)\" >expected &&\n+\ttest_config bash.showUntrackedFiles true &&\n+\t(\n+\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - untracked files status indicator - not shown inside .git directory\" '\n+\tprintf \" (GIT_DIR!)\" >expected &&\n+\t(\n+\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n+\t\tcd .git &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - format string starting with dash\" '\n+\tprintf -- \"-master\" >expected &&\n+\t__git_ps1 \"-%s\" >\"$actual\" &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+pcmode_expected () {\n+\tcase $ps1expansion in\n+\ton) printf \"$1\" '${__git_ps1_branch_name}' \"$2\";;\n+\toff) printf \"$1\" \"$2\" \"\";;\n+\tesac >expected\n+}\n+\n+pcmode_actual () {\n+\tcase $ps1expansion in\n+\ton) printf %s\\\\n%s \"$PS1\" \"${__git_ps1_branch_name}\";;\n+\toff) printf %s\\\\n \"$PS1\";;\n+\tesac >\"$actual\"\n+}\n+\n+_run_pcmode_tests () {\n+\tps1expansion=$1; shift\n+\n+\tcase $ps1expansion in\n+\t# if the shell doesn't allow ps1 expansion to be enabled,\n+\t# quietly skip the tests (same goes for disabling)\n+\ton) ps1_expansion_enable || return 0;;\n+\toff) ps1_expansion_disable || return 0;;\n+\t*) error \"invalid argument to _run_pcmode_tests: $ps1expansion\";;\n+\tesac\n+\n+\ttest_expect_success \"$shellname prompt - pc mode (PS1 expansion $ps1expansion)\" '\n+\t\tpcmode_expected \"BEFORE: (%s):AFTER\\\\n%s\" master &&\n+\t\tprintf \"\" >expected_output &&\n+\t\t(\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" >\"$actual\" &&\n+\t\t\ttest_cmp expected_output \"$actual\" &&\n+\t\t\tpcmode_actual\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n+\n+\tpfx=\"$shellname prompt - color pc mode (PS1 expansion $ps1expansion)\"\n+\n+\ttest_expect_success \"$pfx - branch name\" '\n+\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear}):AFTER\\\\n%s\" master &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" >\"$actual\"\n+\t\t\tpcmode_actual\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n+\n+\ttest_expect_success \"$pfx - detached head\" '\n+\t\tpcmode_expected \"BEFORE: (${c_red}%s${c_clear}):AFTER\\\\n%s\" \"($(git log -1 --format=\"%h\" b1^)...)\" &&\n+\t\tgit checkout b1^ &&\n+\t\ttest_when_finished \"git checkout master\" &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n+\t\t\tpcmode_actual\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n+\n+\ttest_expect_success \"$pfx - dirty status indicator - dirty worktree\" '\n+\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_red}*${c_clear}):AFTER\\\\n%s\" master &&\n+\t\techo \"dirty\" >file &&\n+\t\ttest_when_finished \"git reset --hard\" &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n+\t\t\tpcmode_actual\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n+\n+\ttest_expect_success \"$pfx - dirty status indicator - dirty index\" '\n+\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_green}+${c_clear}):AFTER\\\\n%s\" master &&\n+\t\techo \"dirty\" >file &&\n+\t\ttest_when_finished \"git reset --hard\" &&\n+\t\tgit add -u &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n+\t\t\tpcmode_actual\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n+\n+\ttest_expect_success \"$pfx - dirty status indicator - dirty index and worktree\" '\n+\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_red}*${c_green}+${c_clear}):AFTER\\\\n%s\" master &&\n+\t\techo \"dirty index\" >file &&\n+\t\ttest_when_finished \"git reset --hard\" &&\n+\t\tgit add -u &&\n+\t\techo \"dirty worktree\" >file &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n+\t\t\tpcmode_actual\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n+\n+\ttest_expect_success \"$pfx - dirty status indicator - before root commit\" '\n+\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_green}#${c_clear}):AFTER\\\\n%s\" master &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t\tcd otherrepo &&\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n+\t\t\tpcmode_actual\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n+\n+\ttest_expect_success \"$pfx - inside .git directory\" '\n+\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear}):AFTER\\\\n%s\" \"GIT_DIR!\" &&\n+\t\techo \"dirty\" >file &&\n+\t\ttest_when_finished \"git reset --hard\" &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t\tcd .git &&\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n+\t\t\tpcmode_actual\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n+\n+\ttest_expect_success \"$pfx - stash status indicator\" '\n+\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_lblue}\\$${c_clear}):AFTER\\\\n%s\" master &&\n+\t\techo 2 >file &&\n+\t\tgit stash &&\n+\t\ttest_when_finished \"git stash drop\" &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWSTASHSTATE=y &&\n+\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n+\t\t\tpcmode_actual\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n+\n+\ttest_expect_success \"$pfx - untracked files status indicator\" '\n+\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_red}%%${c_clear}):AFTER\\\\n%s\" master &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n+\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n+\t\t\tpcmode_actual\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n+}\n+\n+run_pcmode_tests () {\n+\t_run_pcmode_tests on\n+\t_run_pcmode_tests off\n+}\n+\n+run_pcmode_tests\ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex ef10e34..b698fe9 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -6,609 +6,6 @@\n test_description='test git-specific bash prompt functions'\n \n . ./lib-bash.sh\n-\n-. \"$GIT_BUILD_DIR/contrib/completion/git-prompt.sh\"\n-\n-actual=\"$TRASH_DIRECTORY/actual\"\n-set_ps1_format_vars\n-\n-test_expect_success \"setup for $shellname prompt tests\" '\n-\tgit init otherrepo &&\n-\techo 1 >file &&\n-\tgit add file &&\n-\ttest_tick &&\n-\tgit commit -m initial &&\n-\tgit tag -a -m msg1 t1 &&\n-\tgit checkout -b b1 &&\n-\techo 2 >file &&\n-\tgit commit -m \"second b1\" file &&\n-\techo 3 >file &&\n-\tgit commit -m \"third b1\" file &&\n-\tgit tag -a -m msg2 t2 &&\n-\tgit checkout -b b2 master &&\n-\techo 0 >file &&\n-\tgit commit -m \"second b2\" file &&\n-\techo 00 >file &&\n-\tgit commit -m \"another b2\" file &&\n-\techo 000 >file &&\n-\tgit commit -m \"yet another b2\" file &&\n-\tgit checkout master\n-'\n-\n-pfx=\"$shellname prompt\"\n-\n-test_expect_success \"$pfx - branch name\" '\n-\tprintf \" (master)\" >expected &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success SYMLINKS \"$pfx - branch name - symlink symref\" '\n-\tprintf \" (master)\" >expected &&\n-\ttest_when_finished \"git checkout master\" &&\n-\ttest_config core.preferSymlinkRefs true &&\n-\tgit checkout master &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - unborn branch\" '\n-\tprintf \" (unborn)\" >expected &&\n-\tgit checkout --orphan unborn &&\n-\ttest_when_finished \"git checkout master\" &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-repo_with_newline='repo\n-with\n-newline'\n-\n-if mkdir \"$repo_with_newline\" 2>/dev/null\n-then\n-\ttest_set_prereq FUNNYNAMES\n-else\n-\tsay 'Your filesystem does not allow newlines in filenames.'\n-fi\n-\n-test_expect_success FUNNYNAMES \"$pfx - with newline in path\" '\n-\tprintf \" (master)\" >expected &&\n-\tgit init \"$repo_with_newline\" &&\n-\ttest_when_finished \"rm -rf \\\"$repo_with_newline\\\"\" &&\n-\tmkdir \"$repo_with_newline\"/subdir &&\n-\t(\n-\t\tcd \"$repo_with_newline/subdir\" &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - detached head\" '\n-\tprintf \" ((%s...))\" $(git log -1 --format=\"%h\" --abbrev=13 b1^) >expected &&\n-\ttest_config core.abbrev 13 &&\n-\tgit checkout b1^ &&\n-\ttest_when_finished \"git checkout master\" &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - describe detached head - contains\" '\n-\tprintf \" ((t2~1))\" >expected &&\n-\tgit checkout b1^ &&\n-\ttest_when_finished \"git checkout master\" &&\n-\t(\n-\t\tGIT_PS1_DESCRIBE_STYLE=contains &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - describe detached head - branch\" '\n-\tprintf \" ((b1~1))\" >expected &&\n-\tgit checkout b1^ &&\n-\ttest_when_finished \"git checkout master\" &&\n-\t(\n-\t\tGIT_PS1_DESCRIBE_STYLE=branch &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - describe detached head - describe\" '\n-\tprintf \" ((t1-1-g%s))\" $(git log -1 --format=\"%h\" b1^) >expected &&\n-\tgit checkout b1^ &&\n-\ttest_when_finished \"git checkout master\" &&\n-\t(\n-\t\tGIT_PS1_DESCRIBE_STYLE=describe &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - describe detached head - default\" '\n-\tprintf \" ((t2))\" >expected &&\n-\tgit checkout --detach b1 &&\n-\ttest_when_finished \"git checkout master\" &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - inside .git directory\" '\n-\tprintf \" (GIT_DIR!)\" >expected &&\n-\t(\n-\t\tcd .git &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - deep inside .git directory\" '\n-\tprintf \" (GIT_DIR!)\" >expected &&\n-\t(\n-\t\tcd .git/refs/heads &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - inside bare repository\" '\n-\tprintf \" (BARE:master)\" >expected &&\n-\tgit init --bare bare.git &&\n-\ttest_when_finished \"rm -rf bare.git\" &&\n-\t(\n-\t\tcd bare.git &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - interactive rebase\" '\n-\tprintf \" (b1|REBASE-i 2/3)\" >expected\n-\twrite_script fake_editor.sh <<-\\EOF &&\n-\t\techo \"exec echo\" >\"$1\"\n-\t\techo \"edit $(git log -1 --format=\"%h\")\" >>\"$1\"\n-\t\techo \"exec echo\" >>\"$1\"\n-\tEOF\n-\ttest_when_finished \"rm -f fake_editor.sh\" &&\n-\ttest_set_editor \"$TRASH_DIRECTORY/fake_editor.sh\" &&\n-\tgit checkout b1 &&\n-\ttest_when_finished \"git checkout master\" &&\n-\tgit rebase -i HEAD^ &&\n-\ttest_when_finished \"git rebase --abort\"\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - rebase merge\" '\n-\tprintf \" (b2|REBASE-m 1/3)\" >expected &&\n-\tgit checkout b2 &&\n-\ttest_when_finished \"git checkout master\" &&\n-\ttest_must_fail git rebase --merge b1 b2 &&\n-\ttest_when_finished \"git rebase --abort\" &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - rebase\" '\n-\tprintf \" (b2|REBASE 1/3)\" >expected &&\n-\tgit checkout b2 &&\n-\ttest_when_finished \"git checkout master\" &&\n-\ttest_must_fail git rebase b1 b2 &&\n-\ttest_when_finished \"git rebase --abort\" &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - merge\" '\n-\tprintf \" (b1|MERGING)\" >expected &&\n-\tgit checkout b1 &&\n-\ttest_when_finished \"git checkout master\" &&\n-\ttest_must_fail git merge b2 &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - cherry-pick\" '\n-\tprintf \" (master|CHERRY-PICKING)\" >expected &&\n-\ttest_must_fail git cherry-pick b1 &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - bisect\" '\n-\tprintf \" (master|BISECTING)\" >expected &&\n-\tgit bisect start &&\n-\ttest_when_finished \"git bisect reset\" &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - dirty status indicator - clean\" '\n-\tprintf \" (master)\" >expected &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - dirty status indicator - dirty worktree\" '\n-\tprintf \" (master *)\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - dirty status indicator - dirty index\" '\n-\tprintf \" (master +)\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\tgit add -u &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - dirty status indicator - dirty index and worktree\" '\n-\tprintf \" (master *+)\" >expected &&\n-\techo \"dirty index\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\tgit add -u &&\n-\techo \"dirty worktree\" >file &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - dirty status indicator - before root commit\" '\n-\tprintf \" (master #)\" >expected &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\tcd otherrepo &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - dirty status indicator - shell variable unset with config disabled\" '\n-\tprintf \" (master)\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\ttest_config bash.showDirtyState false &&\n-\t(\n-\t\tsane_unset GIT_PS1_SHOWDIRTYSTATE &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - dirty status indicator - shell variable unset with config enabled\" '\n-\tprintf \" (master)\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\ttest_config bash.showDirtyState true &&\n-\t(\n-\t\tsane_unset GIT_PS1_SHOWDIRTYSTATE &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - dirty status indicator - shell variable set with config disabled\" '\n-\tprintf \" (master)\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\ttest_config bash.showDirtyState false &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - dirty status indicator - shell variable set with config enabled\" '\n-\tprintf \" (master *)\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\ttest_config bash.showDirtyState true &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - dirty status indicator - not shown inside .git directory\" '\n-\tprintf \" (GIT_DIR!)\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\tcd .git &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - stash status indicator - no stash\" '\n-\tprintf \" (master)\" >expected &&\n-\t(\n-\t\tGIT_PS1_SHOWSTASHSTATE=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - stash status indicator - stash\" '\n-\tprintf \" (master $)\" >expected &&\n-\techo 2 >file &&\n-\tgit stash &&\n-\ttest_when_finished \"git stash drop\" &&\n-\tgit pack-refs --all &&\n-\t(\n-\t\tGIT_PS1_SHOWSTASHSTATE=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - stash status indicator - not shown inside .git directory\" '\n-\tprintf \" (GIT_DIR!)\" >expected &&\n-\techo 2 >file &&\n-\tgit stash &&\n-\ttest_when_finished \"git stash drop\" &&\n-\t(\n-\t\tGIT_PS1_SHOWSTASHSTATE=y &&\n-\t\tcd .git &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - untracked files status indicator - no untracked files\" '\n-\tprintf \" (master)\" >expected &&\n-\t(\n-\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n-\t\tcd otherrepo &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - untracked files status indicator - untracked files\" '\n-\tprintf \" (master %%)\" >expected &&\n-\t(\n-\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - untracked files status indicator - shell variable unset with config disabled\" '\n-\tprintf \" (master)\" >expected &&\n-\ttest_config bash.showUntrackedFiles false &&\n-\t(\n-\t\tsane_unset GIT_PS1_SHOWUNTRACKEDFILES &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - untracked files status indicator - shell variable unset with config enabled\" '\n-\tprintf \" (master)\" >expected &&\n-\ttest_config bash.showUntrackedFiles true &&\n-\t(\n-\t\tsane_unset GIT_PS1_SHOWUNTRACKEDFILES &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - untracked files status indicator - shell variable set with config disabled\" '\n-\tprintf \" (master)\" >expected &&\n-\ttest_config bash.showUntrackedFiles false &&\n-\t(\n-\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - untracked files status indicator - shell variable set with config enabled\" '\n-\tprintf \" (master %%)\" >expected &&\n-\ttest_config bash.showUntrackedFiles true &&\n-\t(\n-\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - untracked files status indicator - not shown inside .git directory\" '\n-\tprintf \" (GIT_DIR!)\" >expected &&\n-\t(\n-\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n-\t\tcd .git &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - format string starting with dash\" '\n-\tprintf -- \"-master\" >expected &&\n-\t__git_ps1 \"-%s\" >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-pcmode_expected () {\n-\tcase $ps1expansion in\n-\ton) printf \"$1\" '${__git_ps1_branch_name}' \"$2\";;\n-\toff) printf \"$1\" \"$2\" \"\";;\n-\tesac >expected\n-}\n-\n-pcmode_actual () {\n-\tcase $ps1expansion in\n-\ton) printf %s\\\\n%s \"$PS1\" \"${__git_ps1_branch_name}\";;\n-\toff) printf %s\\\\n \"$PS1\";;\n-\tesac >\"$actual\"\n-}\n-\n-_run_pcmode_tests () {\n-\tps1expansion=$1; shift\n-\n-\tcase $ps1expansion in\n-\t# if the shell doesn't allow ps1 expansion to be enabled,\n-\t# quietly skip the tests (same goes for disabling)\n-\ton) ps1_expansion_enable || return 0;;\n-\toff) ps1_expansion_disable || return 0;;\n-\t*) error \"invalid argument to _run_pcmode_tests: $ps1expansion\";;\n-\tesac\n-\n-\ttest_expect_success \"$shellname prompt - pc mode (PS1 expansion $ps1expansion)\" '\n-\t\tpcmode_expected \"BEFORE: (%s):AFTER\\\\n%s\" master &&\n-\t\tprintf \"\" >expected_output &&\n-\t\t(\n-\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" >\"$actual\" &&\n-\t\t\ttest_cmp expected_output \"$actual\" &&\n-\t\t\tpcmode_actual\n-\t\t) &&\n-\t\ttest_cmp expected \"$actual\"\n-\t'\n-\n-\tpfx=\"$shellname prompt - color pc mode (PS1 expansion $ps1expansion)\"\n-\n-\ttest_expect_success \"$pfx - branch name\" '\n-\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear}):AFTER\\\\n%s\" master &&\n-\t\t(\n-\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" >\"$actual\"\n-\t\t\tpcmode_actual\n-\t\t) &&\n-\t\ttest_cmp expected \"$actual\"\n-\t'\n-\n-\ttest_expect_success \"$pfx - detached head\" '\n-\t\tpcmode_expected \"BEFORE: (${c_red}%s${c_clear}):AFTER\\\\n%s\" \"($(git log -1 --format=\"%h\" b1^)...)\" &&\n-\t\tgit checkout b1^ &&\n-\t\ttest_when_finished \"git checkout master\" &&\n-\t\t(\n-\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\t\tpcmode_actual\n-\t\t) &&\n-\t\ttest_cmp expected \"$actual\"\n-\t'\n-\n-\ttest_expect_success \"$pfx - dirty status indicator - dirty worktree\" '\n-\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_red}*${c_clear}):AFTER\\\\n%s\" master &&\n-\t\techo \"dirty\" >file &&\n-\t\ttest_when_finished \"git reset --hard\" &&\n-\t\t(\n-\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\t\tpcmode_actual\n-\t\t) &&\n-\t\ttest_cmp expected \"$actual\"\n-\t'\n-\n-\ttest_expect_success \"$pfx - dirty status indicator - dirty index\" '\n-\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_green}+${c_clear}):AFTER\\\\n%s\" master &&\n-\t\techo \"dirty\" >file &&\n-\t\ttest_when_finished \"git reset --hard\" &&\n-\t\tgit add -u &&\n-\t\t(\n-\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\t\tpcmode_actual\n-\t\t) &&\n-\t\ttest_cmp expected \"$actual\"\n-\t'\n-\n-\ttest_expect_success \"$pfx - dirty status indicator - dirty index and worktree\" '\n-\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_red}*${c_green}+${c_clear}):AFTER\\\\n%s\" master &&\n-\t\techo \"dirty index\" >file &&\n-\t\ttest_when_finished \"git reset --hard\" &&\n-\t\tgit add -u &&\n-\t\techo \"dirty worktree\" >file &&\n-\t\t(\n-\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\t\tpcmode_actual\n-\t\t) &&\n-\t\ttest_cmp expected \"$actual\"\n-\t'\n-\n-\ttest_expect_success \"$pfx - dirty status indicator - before root commit\" '\n-\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_green}#${c_clear}):AFTER\\\\n%s\" master &&\n-\t\t(\n-\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\t\tcd otherrepo &&\n-\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\t\tpcmode_actual\n-\t\t) &&\n-\t\ttest_cmp expected \"$actual\"\n-\t'\n-\n-\ttest_expect_success \"$pfx - inside .git directory\" '\n-\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear}):AFTER\\\\n%s\" \"GIT_DIR!\" &&\n-\t\techo \"dirty\" >file &&\n-\t\ttest_when_finished \"git reset --hard\" &&\n-\t\t(\n-\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\t\tcd .git &&\n-\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\t\tpcmode_actual\n-\t\t) &&\n-\t\ttest_cmp expected \"$actual\"\n-\t'\n-\n-\ttest_expect_success \"$pfx - stash status indicator\" '\n-\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_lblue}\\$${c_clear}):AFTER\\\\n%s\" master &&\n-\t\techo 2 >file &&\n-\t\tgit stash &&\n-\t\ttest_when_finished \"git stash drop\" &&\n-\t\t(\n-\t\t\tGIT_PS1_SHOWSTASHSTATE=y &&\n-\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\t\tpcmode_actual\n-\t\t) &&\n-\t\ttest_cmp expected \"$actual\"\n-\t'\n-\n-\ttest_expect_success \"$pfx - untracked files status indicator\" '\n-\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_red}%%${c_clear}):AFTER\\\\n%s\" master &&\n-\t\t(\n-\t\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n-\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\t\tpcmode_actual\n-\t\t) &&\n-\t\ttest_cmp expected \"$actual\"\n-\t'\n-}\n-\n-run_pcmode_tests () {\n-\t_run_pcmode_tests on\n-\t_run_pcmode_tests off\n-}\n-\n-run_pcmode_tests\n+. \"$TEST_DIRECTORY\"/lib-prompt-tests.sh\n \n test_done\n-- \n1.9.3\n"},{"id":"242730","messageId":"1401176460-31564-9-git-send-email-rhansen@bbn.com","threadId":"36705","inReplyTo":"1401176460-31564-1-git-send-email-rhansen@bbn.com","subject":"[PATCH 08/10] lib-prompt-tests.sh: put all tests inside a function","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2014-05-27T07:40:58Z","receivedAt":"2014-05-27T07:40:58Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"Modify lib-prompt-tests.sh so that it does nothing when sourced except\ndefine a function for running the prompt tests (plus some \"private\"\nhelper functions).\n\nSigned-off-by: Richard Hansen <rhansen@bbn.com>\n---\n t/lib-prompt-tests.sh  | 802 ++++++++++++++++++++++++-------------------------\n t/t9903-bash-prompt.sh |   2 +\n 2 files changed, 403 insertions(+), 401 deletions(-)\n\ndiff --git a/t/lib-prompt-tests.sh b/t/lib-prompt-tests.sh\nindex 32c3c08..baa6762 100644\n--- a/t/lib-prompt-tests.sh\n+++ b/t/lib-prompt-tests.sh\n@@ -17,6 +17,7 @@\n #      these variables are used in the first argument to the printf\n #      command, so they must be escaped appropriately.\n #   4. source this library\n+#   5. invoke the run_prompt_tests function\n \n # sanity checks\n [ -n \"$shellname\" ] || error \"shellname must be set to the name of the shell\"\n@@ -27,448 +28,445 @@ done\n (ps1_expansion_enable || ps1_expansion_disable) \\\n \t|| error \"either ps1_expansion_enable or ps1_expansion_disable must return true\"\n \n-. \"$GIT_BUILD_DIR/contrib/completion/git-prompt.sh\"\n+_run_non_pcmode_tests () {\n+\ttest_expect_success \"setup for $shellname prompt tests\" '\n+\t\tgit init otherrepo &&\n+\t\techo 1 >file &&\n+\t\tgit add file &&\n+\t\ttest_tick &&\n+\t\tgit commit -m initial &&\n+\t\tgit tag -a -m msg1 t1 &&\n+\t\tgit checkout -b b1 &&\n+\t\techo 2 >file &&\n+\t\tgit commit -m \"second b1\" file &&\n+\t\techo 3 >file &&\n+\t\tgit commit -m \"third b1\" file &&\n+\t\tgit tag -a -m msg2 t2 &&\n+\t\tgit checkout -b b2 master &&\n+\t\techo 0 >file &&\n+\t\tgit commit -m \"second b2\" file &&\n+\t\techo 00 >file &&\n+\t\tgit commit -m \"another b2\" file &&\n+\t\techo 000 >file &&\n+\t\tgit commit -m \"yet another b2\" file &&\n+\t\tgit checkout master\n+\t'\n \n-actual=\"$TRASH_DIRECTORY/actual\"\n-set_ps1_format_vars\n+\tpfx=\"$shellname prompt\"\n \n-test_expect_success \"setup for $shellname prompt tests\" '\n-\tgit init otherrepo &&\n-\techo 1 >file &&\n-\tgit add file &&\n-\ttest_tick &&\n-\tgit commit -m initial &&\n-\tgit tag -a -m msg1 t1 &&\n-\tgit checkout -b b1 &&\n-\techo 2 >file &&\n-\tgit commit -m \"second b1\" file &&\n-\techo 3 >file &&\n-\tgit commit -m \"third b1\" file &&\n-\tgit tag -a -m msg2 t2 &&\n-\tgit checkout -b b2 master &&\n-\techo 0 >file &&\n-\tgit commit -m \"second b2\" file &&\n-\techo 00 >file &&\n-\tgit commit -m \"another b2\" file &&\n-\techo 000 >file &&\n-\tgit commit -m \"yet another b2\" file &&\n-\tgit checkout master\n-'\n+\ttest_expect_success \"$pfx - branch name\" '\n+\t\tprintf \" (master)\" >expected &&\n+\t\t__git_ps1 >\"$actual\" &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-pfx=\"$shellname prompt\"\n+\ttest_expect_success SYMLINKS \"$pfx - branch name - symlink symref\" '\n+\t\tprintf \" (master)\" >expected &&\n+\t\ttest_when_finished \"git checkout master\" &&\n+\t\ttest_config core.preferSymlinkRefs true &&\n+\t\tgit checkout master &&\n+\t\t__git_ps1 >\"$actual\" &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - branch name\" '\n-\tprintf \" (master)\" >expected &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - unborn branch\" '\n+\t\tprintf \" (unborn)\" >expected &&\n+\t\tgit checkout --orphan unborn &&\n+\t\ttest_when_finished \"git checkout master\" &&\n+\t\t__git_ps1 >\"$actual\" &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success SYMLINKS \"$pfx - branch name - symlink symref\" '\n-\tprintf \" (master)\" >expected &&\n-\ttest_when_finished \"git checkout master\" &&\n-\ttest_config core.preferSymlinkRefs true &&\n-\tgit checkout master &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - unborn branch\" '\n-\tprintf \" (unborn)\" >expected &&\n-\tgit checkout --orphan unborn &&\n-\ttest_when_finished \"git checkout master\" &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-repo_with_newline='repo\n+\trepo_with_newline='repo\n with\n newline'\n \n-if mkdir \"$repo_with_newline\" 2>/dev/null\n-then\n-\ttest_set_prereq FUNNYNAMES\n-else\n-\tsay 'Your filesystem does not allow newlines in filenames.'\n-fi\n+\tif mkdir \"$repo_with_newline\" 2>/dev/null\n+\tthen\n+\t\ttest_set_prereq FUNNYNAMES\n+\telse\n+\t\tsay 'Your filesystem does not allow newlines in filenames.'\n+\tfi\n \n-test_expect_success FUNNYNAMES \"$pfx - with newline in path\" '\n-\tprintf \" (master)\" >expected &&\n-\tgit init \"$repo_with_newline\" &&\n-\ttest_when_finished \"rm -rf \\\"$repo_with_newline\\\"\" &&\n-\tmkdir \"$repo_with_newline\"/subdir &&\n-\t(\n-\t\tcd \"$repo_with_newline/subdir\" &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success FUNNYNAMES \"$pfx - with newline in path\" '\n+\t\tprintf \" (master)\" >expected &&\n+\t\tgit init \"$repo_with_newline\" &&\n+\t\ttest_when_finished \"rm -rf \\\"$repo_with_newline\\\"\" &&\n+\t\tmkdir \"$repo_with_newline\"/subdir &&\n+\t\t(\n+\t\t\tcd \"$repo_with_newline/subdir\" &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - detached head\" '\n-\tprintf \" ((%s...))\" $(git log -1 --format=\"%h\" --abbrev=13 b1^) >expected &&\n-\ttest_config core.abbrev 13 &&\n-\tgit checkout b1^ &&\n-\ttest_when_finished \"git checkout master\" &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - detached head\" '\n+\t\tprintf \" ((%s...))\" $(git log -1 --format=\"%h\" --abbrev=13 b1^) >expected &&\n+\t\ttest_config core.abbrev 13 &&\n+\t\tgit checkout b1^ &&\n+\t\ttest_when_finished \"git checkout master\" &&\n+\t\t__git_ps1 >\"$actual\" &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - describe detached head - contains\" '\n-\tprintf \" ((t2~1))\" >expected &&\n-\tgit checkout b1^ &&\n-\ttest_when_finished \"git checkout master\" &&\n-\t(\n-\t\tGIT_PS1_DESCRIBE_STYLE=contains &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - describe detached head - contains\" '\n+\t\tprintf \" ((t2~1))\" >expected &&\n+\t\tgit checkout b1^ &&\n+\t\ttest_when_finished \"git checkout master\" &&\n+\t\t(\n+\t\t\tGIT_PS1_DESCRIBE_STYLE=contains &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - describe detached head - branch\" '\n-\tprintf \" ((b1~1))\" >expected &&\n-\tgit checkout b1^ &&\n-\ttest_when_finished \"git checkout master\" &&\n-\t(\n-\t\tGIT_PS1_DESCRIBE_STYLE=branch &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - describe detached head - branch\" '\n+\t\tprintf \" ((b1~1))\" >expected &&\n+\t\tgit checkout b1^ &&\n+\t\ttest_when_finished \"git checkout master\" &&\n+\t\t(\n+\t\t\tGIT_PS1_DESCRIBE_STYLE=branch &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - describe detached head - describe\" '\n-\tprintf \" ((t1-1-g%s))\" $(git log -1 --format=\"%h\" b1^) >expected &&\n-\tgit checkout b1^ &&\n-\ttest_when_finished \"git checkout master\" &&\n-\t(\n-\t\tGIT_PS1_DESCRIBE_STYLE=describe &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - describe detached head - describe\" '\n+\t\tprintf \" ((t1-1-g%s))\" $(git log -1 --format=\"%h\" b1^) >expected &&\n+\t\tgit checkout b1^ &&\n+\t\ttest_when_finished \"git checkout master\" &&\n+\t\t(\n+\t\t\tGIT_PS1_DESCRIBE_STYLE=describe &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - describe detached head - default\" '\n-\tprintf \" ((t2))\" >expected &&\n-\tgit checkout --detach b1 &&\n-\ttest_when_finished \"git checkout master\" &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - describe detached head - default\" '\n+\t\tprintf \" ((t2))\" >expected &&\n+\t\tgit checkout --detach b1 &&\n+\t\ttest_when_finished \"git checkout master\" &&\n+\t\t__git_ps1 >\"$actual\" &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - inside .git directory\" '\n-\tprintf \" (GIT_DIR!)\" >expected &&\n-\t(\n-\t\tcd .git &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - inside .git directory\" '\n+\t\tprintf \" (GIT_DIR!)\" >expected &&\n+\t\t(\n+\t\t\tcd .git &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - deep inside .git directory\" '\n-\tprintf \" (GIT_DIR!)\" >expected &&\n-\t(\n-\t\tcd .git/refs/heads &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - deep inside .git directory\" '\n+\t\tprintf \" (GIT_DIR!)\" >expected &&\n+\t\t(\n+\t\t\tcd .git/refs/heads &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - inside bare repository\" '\n-\tprintf \" (BARE:master)\" >expected &&\n-\tgit init --bare bare.git &&\n-\ttest_when_finished \"rm -rf bare.git\" &&\n-\t(\n-\t\tcd bare.git &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - inside bare repository\" '\n+\t\tprintf \" (BARE:master)\" >expected &&\n+\t\tgit init --bare bare.git &&\n+\t\ttest_when_finished \"rm -rf bare.git\" &&\n+\t\t(\n+\t\t\tcd bare.git &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - interactive rebase\" '\n-\tprintf \" (b1|REBASE-i 2/3)\" >expected\n-\twrite_script fake_editor.sh <<-\\EOF &&\n-\t\techo \"exec echo\" >\"$1\"\n-\t\techo \"edit $(git log -1 --format=\"%h\")\" >>\"$1\"\n-\t\techo \"exec echo\" >>\"$1\"\n-\tEOF\n-\ttest_when_finished \"rm -f fake_editor.sh\" &&\n-\ttest_set_editor \"$TRASH_DIRECTORY/fake_editor.sh\" &&\n-\tgit checkout b1 &&\n-\ttest_when_finished \"git checkout master\" &&\n-\tgit rebase -i HEAD^ &&\n-\ttest_when_finished \"git rebase --abort\"\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - interactive rebase\" '\n+\t\tprintf \" (b1|REBASE-i 2/3)\" >expected\n+\t\twrite_script fake_editor.sh <<-\\EOF &&\n+\t\t\techo \"exec echo\" >\"$1\"\n+\t\t\techo \"edit $(git log -1 --format=\"%h\")\" >>\"$1\"\n+\t\t\techo \"exec echo\" >>\"$1\"\n+\t\tEOF\n+\t\ttest_when_finished \"rm -f fake_editor.sh\" &&\n+\t\ttest_set_editor \"$TRASH_DIRECTORY/fake_editor.sh\" &&\n+\t\tgit checkout b1 &&\n+\t\ttest_when_finished \"git checkout master\" &&\n+\t\tgit rebase -i HEAD^ &&\n+\t\ttest_when_finished \"git rebase --abort\"\n+\t\t__git_ps1 >\"$actual\" &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - rebase merge\" '\n-\tprintf \" (b2|REBASE-m 1/3)\" >expected &&\n-\tgit checkout b2 &&\n-\ttest_when_finished \"git checkout master\" &&\n-\ttest_must_fail git rebase --merge b1 b2 &&\n-\ttest_when_finished \"git rebase --abort\" &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - rebase merge\" '\n+\t\tprintf \" (b2|REBASE-m 1/3)\" >expected &&\n+\t\tgit checkout b2 &&\n+\t\ttest_when_finished \"git checkout master\" &&\n+\t\ttest_must_fail git rebase --merge b1 b2 &&\n+\t\ttest_when_finished \"git rebase --abort\" &&\n+\t\t__git_ps1 >\"$actual\" &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - rebase\" '\n-\tprintf \" (b2|REBASE 1/3)\" >expected &&\n-\tgit checkout b2 &&\n-\ttest_when_finished \"git checkout master\" &&\n-\ttest_must_fail git rebase b1 b2 &&\n-\ttest_when_finished \"git rebase --abort\" &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - rebase\" '\n+\t\tprintf \" (b2|REBASE 1/3)\" >expected &&\n+\t\tgit checkout b2 &&\n+\t\ttest_when_finished \"git checkout master\" &&\n+\t\ttest_must_fail git rebase b1 b2 &&\n+\t\ttest_when_finished \"git rebase --abort\" &&\n+\t\t__git_ps1 >\"$actual\" &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - merge\" '\n-\tprintf \" (b1|MERGING)\" >expected &&\n-\tgit checkout b1 &&\n-\ttest_when_finished \"git checkout master\" &&\n-\ttest_must_fail git merge b2 &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - merge\" '\n+\t\tprintf \" (b1|MERGING)\" >expected &&\n+\t\tgit checkout b1 &&\n+\t\ttest_when_finished \"git checkout master\" &&\n+\t\ttest_must_fail git merge b2 &&\n+\t\ttest_when_finished \"git reset --hard\" &&\n+\t\t__git_ps1 >\"$actual\" &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - cherry-pick\" '\n-\tprintf \" (master|CHERRY-PICKING)\" >expected &&\n-\ttest_must_fail git cherry-pick b1 &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - cherry-pick\" '\n+\t\tprintf \" (master|CHERRY-PICKING)\" >expected &&\n+\t\ttest_must_fail git cherry-pick b1 &&\n+\t\ttest_when_finished \"git reset --hard\" &&\n+\t\t__git_ps1 >\"$actual\" &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - bisect\" '\n-\tprintf \" (master|BISECTING)\" >expected &&\n-\tgit bisect start &&\n-\ttest_when_finished \"git bisect reset\" &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - bisect\" '\n+\t\tprintf \" (master|BISECTING)\" >expected &&\n+\t\tgit bisect start &&\n+\t\ttest_when_finished \"git bisect reset\" &&\n+\t\t__git_ps1 >\"$actual\" &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - dirty status indicator - clean\" '\n-\tprintf \" (master)\" >expected &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - dirty status indicator - clean\" '\n+\t\tprintf \" (master)\" >expected &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - dirty status indicator - dirty worktree\" '\n-\tprintf \" (master *)\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - dirty status indicator - dirty worktree\" '\n+\t\tprintf \" (master *)\" >expected &&\n+\t\techo \"dirty\" >file &&\n+\t\ttest_when_finished \"git reset --hard\" &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - dirty status indicator - dirty index\" '\n-\tprintf \" (master +)\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\tgit add -u &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - dirty status indicator - dirty index\" '\n+\t\tprintf \" (master +)\" >expected &&\n+\t\techo \"dirty\" >file &&\n+\t\ttest_when_finished \"git reset --hard\" &&\n+\t\tgit add -u &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - dirty status indicator - dirty index and worktree\" '\n-\tprintf \" (master *+)\" >expected &&\n-\techo \"dirty index\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\tgit add -u &&\n-\techo \"dirty worktree\" >file &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - dirty status indicator - dirty index and worktree\" '\n+\t\tprintf \" (master *+)\" >expected &&\n+\t\techo \"dirty index\" >file &&\n+\t\ttest_when_finished \"git reset --hard\" &&\n+\t\tgit add -u &&\n+\t\techo \"dirty worktree\" >file &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - dirty status indicator - before root commit\" '\n-\tprintf \" (master #)\" >expected &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\tcd otherrepo &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - dirty status indicator - before root commit\" '\n+\t\tprintf \" (master #)\" >expected &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t\tcd otherrepo &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - dirty status indicator - shell variable unset with config disabled\" '\n-\tprintf \" (master)\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\ttest_config bash.showDirtyState false &&\n-\t(\n-\t\tsane_unset GIT_PS1_SHOWDIRTYSTATE &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - dirty status indicator - shell variable unset with config disabled\" '\n+\t\tprintf \" (master)\" >expected &&\n+\t\techo \"dirty\" >file &&\n+\t\ttest_when_finished \"git reset --hard\" &&\n+\t\ttest_config bash.showDirtyState false &&\n+\t\t(\n+\t\t\tsane_unset GIT_PS1_SHOWDIRTYSTATE &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - dirty status indicator - shell variable unset with config enabled\" '\n-\tprintf \" (master)\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\ttest_config bash.showDirtyState true &&\n-\t(\n-\t\tsane_unset GIT_PS1_SHOWDIRTYSTATE &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - dirty status indicator - shell variable unset with config enabled\" '\n+\t\tprintf \" (master)\" >expected &&\n+\t\techo \"dirty\" >file &&\n+\t\ttest_when_finished \"git reset --hard\" &&\n+\t\ttest_config bash.showDirtyState true &&\n+\t\t(\n+\t\t\tsane_unset GIT_PS1_SHOWDIRTYSTATE &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - dirty status indicator - shell variable set with config disabled\" '\n-\tprintf \" (master)\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\ttest_config bash.showDirtyState false &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - dirty status indicator - shell variable set with config disabled\" '\n+\t\tprintf \" (master)\" >expected &&\n+\t\techo \"dirty\" >file &&\n+\t\ttest_when_finished \"git reset --hard\" &&\n+\t\ttest_config bash.showDirtyState false &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - dirty status indicator - shell variable set with config enabled\" '\n-\tprintf \" (master *)\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\ttest_config bash.showDirtyState true &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - dirty status indicator - shell variable set with config enabled\" '\n+\t\tprintf \" (master *)\" >expected &&\n+\t\techo \"dirty\" >file &&\n+\t\ttest_when_finished \"git reset --hard\" &&\n+\t\ttest_config bash.showDirtyState true &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - dirty status indicator - not shown inside .git directory\" '\n-\tprintf \" (GIT_DIR!)\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\tcd .git &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - dirty status indicator - not shown inside .git directory\" '\n+\t\tprintf \" (GIT_DIR!)\" >expected &&\n+\t\techo \"dirty\" >file &&\n+\t\ttest_when_finished \"git reset --hard\" &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t\tcd .git &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - stash status indicator - no stash\" '\n-\tprintf \" (master)\" >expected &&\n-\t(\n-\t\tGIT_PS1_SHOWSTASHSTATE=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - stash status indicator - no stash\" '\n+\t\tprintf \" (master)\" >expected &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWSTASHSTATE=y &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - stash status indicator - stash\" '\n-\tprintf \" (master $)\" >expected &&\n-\techo 2 >file &&\n-\tgit stash &&\n-\ttest_when_finished \"git stash drop\" &&\n-\tgit pack-refs --all &&\n-\t(\n-\t\tGIT_PS1_SHOWSTASHSTATE=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - stash status indicator - stash\" '\n+\t\tprintf \" (master $)\" >expected &&\n+\t\techo 2 >file &&\n+\t\tgit stash &&\n+\t\ttest_when_finished \"git stash drop\" &&\n+\t\tgit pack-refs --all &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWSTASHSTATE=y &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - stash status indicator - not shown inside .git directory\" '\n-\tprintf \" (GIT_DIR!)\" >expected &&\n-\techo 2 >file &&\n-\tgit stash &&\n-\ttest_when_finished \"git stash drop\" &&\n-\t(\n-\t\tGIT_PS1_SHOWSTASHSTATE=y &&\n-\t\tcd .git &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - stash status indicator - not shown inside .git directory\" '\n+\t\tprintf \" (GIT_DIR!)\" >expected &&\n+\t\techo 2 >file &&\n+\t\tgit stash &&\n+\t\ttest_when_finished \"git stash drop\" &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWSTASHSTATE=y &&\n+\t\t\tcd .git &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - untracked files status indicator - no untracked files\" '\n-\tprintf \" (master)\" >expected &&\n-\t(\n-\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n-\t\tcd otherrepo &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - untracked files status indicator - no untracked files\" '\n+\t\tprintf \" (master)\" >expected &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n+\t\t\tcd otherrepo &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - untracked files status indicator - untracked files\" '\n-\tprintf \" (master %%)\" >expected &&\n-\t(\n-\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - untracked files status indicator - untracked files\" '\n+\t\tprintf \" (master %%)\" >expected &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - untracked files status indicator - shell variable unset with config disabled\" '\n-\tprintf \" (master)\" >expected &&\n-\ttest_config bash.showUntrackedFiles false &&\n-\t(\n-\t\tsane_unset GIT_PS1_SHOWUNTRACKEDFILES &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - untracked files status indicator - shell variable unset with config disabled\" '\n+\t\tprintf \" (master)\" >expected &&\n+\t\ttest_config bash.showUntrackedFiles false &&\n+\t\t(\n+\t\t\tsane_unset GIT_PS1_SHOWUNTRACKEDFILES &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - untracked files status indicator - shell variable unset with config enabled\" '\n-\tprintf \" (master)\" >expected &&\n-\ttest_config bash.showUntrackedFiles true &&\n-\t(\n-\t\tsane_unset GIT_PS1_SHOWUNTRACKEDFILES &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - untracked files status indicator - shell variable unset with config enabled\" '\n+\t\tprintf \" (master)\" >expected &&\n+\t\ttest_config bash.showUntrackedFiles true &&\n+\t\t(\n+\t\t\tsane_unset GIT_PS1_SHOWUNTRACKEDFILES &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - untracked files status indicator - shell variable set with config disabled\" '\n-\tprintf \" (master)\" >expected &&\n-\ttest_config bash.showUntrackedFiles false &&\n-\t(\n-\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - untracked files status indicator - shell variable set with config disabled\" '\n+\t\tprintf \" (master)\" >expected &&\n+\t\ttest_config bash.showUntrackedFiles false &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - untracked files status indicator - shell variable set with config enabled\" '\n-\tprintf \" (master %%)\" >expected &&\n-\ttest_config bash.showUntrackedFiles true &&\n-\t(\n-\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - untracked files status indicator - shell variable set with config enabled\" '\n+\t\tprintf \" (master %%)\" >expected &&\n+\t\ttest_config bash.showUntrackedFiles true &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - untracked files status indicator - not shown inside .git directory\" '\n-\tprintf \" (GIT_DIR!)\" >expected &&\n-\t(\n-\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n-\t\tcd .git &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - untracked files status indicator - not shown inside .git directory\" '\n+\t\tprintf \" (GIT_DIR!)\" >expected &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n+\t\t\tcd .git &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - format string starting with dash\" '\n-\tprintf -- \"-master\" >expected &&\n-\t__git_ps1 \"-%s\" >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - format string starting with dash\" '\n+\t\tprintf -- \"-master\" >expected &&\n+\t\t__git_ps1 \"-%s\" >\"$actual\" &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n+}\n \n pcmode_expected () {\n \tcase $ps1expansion in\n@@ -624,9 +622,11 @@ _run_pcmode_tests () {\n \t'\n }\n \n-run_pcmode_tests () {\n+run_prompt_tests () {\n+\t. \"$GIT_BUILD_DIR/contrib/completion/git-prompt.sh\"\n+\tactual=\"$TRASH_DIRECTORY/actual\"\n+\tset_ps1_format_vars\n+\t_run_non_pcmode_tests\n \t_run_pcmode_tests on\n \t_run_pcmode_tests off\n }\n-\n-run_pcmode_tests\ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex b698fe9..858f0cd 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -8,4 +8,6 @@ test_description='test git-specific bash prompt functions'\n . ./lib-bash.sh\n . \"$TEST_DIRECTORY\"/lib-prompt-tests.sh\n \n+run_prompt_tests\n+\n test_done\n-- \n1.9.3\n"},{"id":"242731","messageId":"1401176460-31564-10-git-send-email-rhansen@bbn.com","threadId":"36705","inReplyTo":"1401176460-31564-1-git-send-email-rhansen@bbn.com","subject":"[PATCH 09/10] lib-prompt-tests.sh: add variable for string that encodes percent in PS1","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2014-05-27T07:40:59Z","receivedAt":"2014-05-27T07:40:59Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"To add a literal percent character to a Zsh prompt, the string \"%%\" is\nused in PS1.  Bash and POSIX shells simply use \"%\".  To accommodate\nthis difference, use ${percent} where a percent character is expected\nand define the percent variable in the set_ps1_format_vars function.\n\nSigned-off-by: Richard Hansen <rhansen@bbn.com>\n---\n t/lib-bash.sh         |  1 +\n t/lib-prompt-tests.sh | 15 ++++++++-------\n 2 files changed, 9 insertions(+), 7 deletions(-)\n\ndiff --git a/t/lib-bash.sh b/t/lib-bash.sh\nindex 9d428bd..8a030ac 100644\n--- a/t/lib-bash.sh\n+++ b/t/lib-bash.sh\n@@ -19,6 +19,7 @@ shellname=Bash\n ps1_expansion_enable () { shopt -s promptvars; }\n ps1_expansion_disable () { shopt -u promptvars; }\n set_ps1_format_vars () {\n+\tpercent='%%'\n \tc_red='\\\\[\\\\e[31m\\\\]'\n \tc_green='\\\\[\\\\e[32m\\\\]'\n \tc_lblue='\\\\[\\\\e[1;34m\\\\]'\ndiff --git a/t/lib-prompt-tests.sh b/t/lib-prompt-tests.sh\nindex baa6762..244e765 100644\n--- a/t/lib-prompt-tests.sh\n+++ b/t/lib-prompt-tests.sh\n@@ -12,10 +12,11 @@\n #      (non-zero) and ps1_expansion_disable should simply return\n #      non-zero (0)\n #   3. define a function named set_ps1_format_vars that sets the\n-#      variables c_red, c_green, c_lblue, and c_clear to the strings\n-#      that __git_ps1 uses to add color to the prompt.  The values of\n-#      these variables are used in the first argument to the printf\n-#      command, so they must be escaped appropriately.\n+#      variables percent, c_red, c_green, c_lblue, and c_clear to the\n+#      strings that __git_ps1 uses to add percent characters and color\n+#      to the prompt.  The values of these variables are used in the\n+#      first argument to the printf command, so they must be escaped\n+#      appropriately.\n #   4. source this library\n #   5. invoke the run_prompt_tests function\n \n@@ -403,7 +404,7 @@ newline'\n \t'\n \n \ttest_expect_success \"$pfx - untracked files status indicator - untracked files\" '\n-\t\tprintf \" (master %%)\" >expected &&\n+\t\tprintf \" (master ${percent})\" >expected &&\n \t\t(\n \t\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n \t\t\t__git_ps1 >\"$actual\"\n@@ -442,7 +443,7 @@ newline'\n \t'\n \n \ttest_expect_success \"$pfx - untracked files status indicator - shell variable set with config enabled\" '\n-\t\tprintf \" (master %%)\" >expected &&\n+\t\tprintf \" (master ${percent})\" >expected &&\n \t\ttest_config bash.showUntrackedFiles true &&\n \t\t(\n \t\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n@@ -611,7 +612,7 @@ _run_pcmode_tests () {\n \t'\n \n \ttest_expect_success \"$pfx - untracked files status indicator\" '\n-\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_red}%%${c_clear}):AFTER\\\\n%s\" master &&\n+\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_red}${percent}${c_clear}):AFTER\\\\n%s\" master &&\n \t\t(\n \t\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n \t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-- \n1.9.3\n"},{"id":"242727","messageId":"1401176460-31564-11-git-send-email-rhansen@bbn.com","threadId":"36705","inReplyTo":"1401176460-31564-1-git-send-email-rhansen@bbn.com","subject":"[PATCH 10/10] t9904: new __git_ps1 tests for Zsh","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2014-05-27T07:41:00Z","receivedAt":"2014-05-27T07:41:00Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"These are the same tests as in t9903, but run in zsh instead of bash.\n\nSigned-off-by: Richard Hansen <rhansen@bbn.com>\n---\n t/lib-zsh.sh          | 30 ++++++++++++++++++++++++++++++\n t/t9904-zsh-prompt.sh | 10 ++++++++++\n 2 files changed, 40 insertions(+)\n create mode 100644 t/lib-zsh.sh\n create mode 100755 t/t9904-zsh-prompt.sh\n\ndiff --git a/t/lib-zsh.sh b/t/lib-zsh.sh\nnew file mode 100644\nindex 0000000..fa6fcd9\n--- /dev/null\n+++ b/t/lib-zsh.sh\n@@ -0,0 +1,30 @@\n+# Shell library sourced instead of ./test-lib.sh by tests that need to\n+# run under Zsh; primarily intended for tests of the git-prompt.sh\n+# script.\n+\n+if test -n \"$ZSH_VERSION\" && test -z \"$POSIXLY_CORRECT\"; then\n+\ttrue\n+elif command -v zsh >/dev/null 2>&1; then\n+\tunset POSIXLY_CORRECT\n+\texec zsh \"$0\" \"$@\"\n+else\n+\techo '1..0 #SKIP skipping Zsh-specific tests; zsh not available'\n+\texit 0\n+fi\n+\n+# ensure that we are in full-on Zsh mode\n+emulate -R zsh || exit 1\n+\n+shellname=Zsh\n+\n+ps1_expansion_enable () { setopt PROMPT_SUBST; }\n+ps1_expansion_disable () { unsetopt PROMPT_SUBST; }\n+set_ps1_format_vars () {\n+\tpercent='%%%%'\n+\tc_red='%%F{red}'\n+\tc_green='%%F{green}'\n+\tc_lblue='%%F{blue}'\n+\tc_clear='%%f'\n+}\n+\n+emulate sh -c '. ./test-lib.sh'\ndiff --git a/t/t9904-zsh-prompt.sh b/t/t9904-zsh-prompt.sh\nnew file mode 100755\nindex 0000000..a38a3fd\n--- /dev/null\n+++ b/t/t9904-zsh-prompt.sh\n@@ -0,0 +1,10 @@\n+#!/bin/sh\n+\n+test_description='test git-specific Zsh prompt functions'\n+\n+. ./lib-zsh.sh\n+. \"$TEST_DIRECTORY\"/lib-prompt-tests.sh\n+\n+run_prompt_tests\n+\n+test_done\n-- \n1.9.3\n"},{"id":"242973","messageId":"87fvjsmmr4.fsf@thomasrast.ch","threadId":"36705","inReplyTo":"1401176460-31564-11-git-send-email-rhansen@bbn.com","subject":"Re: [PATCH 10/10] t9904: new __git_ps1 tests for Zsh","fromName":"Thomas Rast","fromEmail":"tr@thomasrast.ch","sentAt":"2014-05-29T19:02:39Z","receivedAt":"2014-05-29T19:02:39Z","isPatch":true,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Richard Hansen <rhansen@bbn.com> writes:\n\n> These are the same tests as in t9903, but run in zsh instead of bash.\n>\n> Signed-off-by: Richard Hansen <rhansen@bbn.com>\n> ---\n>  t/lib-zsh.sh          | 30 ++++++++++++++++++++++++++++++\n>  t/t9904-zsh-prompt.sh | 10 ++++++++++\n>  2 files changed, 40 insertions(+)\n>  create mode 100644 t/lib-zsh.sh\n>  create mode 100755 t/t9904-zsh-prompt.sh\n\nThis doesn't appear to work in valgrind mode:\n\n$ ./t9904-zsh-prompt.sh --valgrind\nerror: Test script did not set test_description.\n\nt9903 however works.  I'm not sure how much of a difference it makes,\nbut: I use bash as my shell and as /bin/sh, but I do have zsh installed.\n\nCan you look into it?\n\n-- \nThomas Rast\ntr@thomasrast.ch\n"},{"id":"242981","messageId":"1401402633-14742-1-git-send-email-rhansen@bbn.com","threadId":"36705","inReplyTo":"87fvjsmmr4.fsf@thomasrast.ch","subject":"[PATCH 11/10] fixup! t9904: new __git_ps1 tests for Zsh","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2014-05-29T22:30:33Z","receivedAt":"2014-05-29T22:30:33Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"Signed-off-by: Richard Hansen <rhansen@bbn.com>\n---\n\nOn 2014-05-29 15:02, Thomas Rast wrote:\n> Richard Hansen <rhansen@bbn.com> writes:\n>\n>> These are the same tests as in t9903, but run in zsh instead of bash.\n>>\n>> Signed-off-by: Richard Hansen <rhansen@bbn.com>\n>> ---\n>>  t/lib-zsh.sh          | 30 ++++++++++++++++++++++++++++++\n>>  t/t9904-zsh-prompt.sh | 10 ++++++++++\n>>  2 files changed, 40 insertions(+)\n>>  create mode 100644 t/lib-zsh.sh\n>>  create mode 100755 t/t9904-zsh-prompt.sh\n>\n> This doesn't appear to work in valgrind mode:\n>\n> $ ./t9904-zsh-prompt.sh --valgrind\n> error: Test script did not set test_description.\n>\n> t9903 however works.  I'm not sure how much of a difference it makes,\n> but: I use bash as my shell and as /bin/sh, but I do have zsh installed.\n>\n> Can you look into it?\n\n*sigh* By default, Zsh munges $0 whenever a function is called or a\nfile is sourced, with no (immediately obvious) way to get the original\nvalue of $0.  This fixup causes that feature to be temporarily turned\noff so that test-lib.sh does the right thing when it execs $0.\n\nThank you for finding this bug!\n\n-Richard\n\n\n t/lib-zsh.sh | 15 ++++++++++++---\n 1 file changed, 12 insertions(+), 3 deletions(-)\n\ndiff --git a/t/lib-zsh.sh b/t/lib-zsh.sh\nindex fa6fcd9..ab4bef2 100644\n--- a/t/lib-zsh.sh\n+++ b/t/lib-zsh.sh\n@@ -2,17 +2,23 @@\n # run under Zsh; primarily intended for tests of the git-prompt.sh\n # script.\n \n-if test -n \"$ZSH_VERSION\" && test -z \"$POSIXLY_CORRECT\"; then\n+if test -n \"$ZSH_VERSION\" && test -z \"$POSIXLY_CORRECT\" && [[ ! -o FUNCTION_ARGZERO ]]; then\n \ttrue\n elif command -v zsh >/dev/null 2>&1; then\n \tunset POSIXLY_CORRECT\n-\texec zsh \"$0\" \"$@\"\n+\t# Run Zsh with the FUNCTION_ARGZERO option disabled so that\n+\t# test-lib.sh sees the test script pathname when it examines\n+\t# $0 instead of \"./lib-zsh.sh\".  (This works around a Zsh bug;\n+\t# 'emulate sh -c' should temporarily restore $0 to the POSIX\n+\t# specification for $0, but it doesn't.)\n+\texec zsh +o FUNCTION_ARGZERO \"$0\" \"$@\"\n else\n \techo '1..0 #SKIP skipping Zsh-specific tests; zsh not available'\n \texit 0\n fi\n \n-# ensure that we are in full-on Zsh mode\n+# ensure that we are in full-on Zsh mode.  note: this re-enables the\n+# FUNCTION_ARGZERO option\n emulate -R zsh || exit 1\n \n shellname=Zsh\n@@ -27,4 +33,7 @@ set_ps1_format_vars () {\n \tc_clear='%%f'\n }\n \n+# note: although the FUNCTION_ARGZERO option is currently enabled, sh\n+# emulation mode temporarily turns it off ($0 is left alone when\n+# sourcing test-lib.sh)\n emulate sh -c '. ./test-lib.sh'\n-- \n2.0.0\n"},{"id":"243342","messageId":"1401915687-8602-1-git-send-email-rhansen@bbn.com","threadId":"36705","inReplyTo":"1401176460-31564-1-git-send-email-rhansen@bbn.com","subject":"[PATCH v2 00/11] Zsh prompt tests","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2014-06-04T21:01:16Z","receivedAt":"2014-06-04T21:01:16Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"Changes from v1:\n\n  * fix a bug that caused the Zsh test cases to run in Zsh's sh\n    emulation mode, not Zsh \"native\" mode\n\nDescription:\n\nThis series adds test cases for running __git_ps1 (see\ncontrib/completion/git-prompt.sh) from Zsh.\n\nThis series also adds more Bash test cases to test how __git_ps1\nreacts to disabling Bash's PS1 parameter expansion.  (This is related\nto adding Zsh test cases:  Zsh doesn't perform parameter expansion on\nPS1 by default but many users turn it on, so the Zsh test script must\ntest __git_ps1 in both states.  Bash expands PS1 by default and users\nrarely turn it off, but testing both states in Bash improves the\nsymmetry with the Zsh test cases.)\n\nThis is the approach I took:\n\n  1. delete the last test case in t9903 (\"prompt - zsh color pc mode\")\n  2. add two new functions to t/lib-bash.sh:\n         ps1_expansion_enable () { shopt -s promptvars; }\n         ps1_expansion_disable () { shopt -u promptvars; }\n  3. loop over the relevant test cases twice:  once after calling\n     ps1_expansion_enable and once after calling ps1_expansion_disable\n     (with appropriate adjustments to the expected output)\n  4. move the test cases in t9903 to a separate library file and\n     source it from t9903-bash-prompt.sh\n  5. create two new files:\n       * t/lib-zsh.sh (same as t/lib-bash.sh but tweaked for zsh)\n       * t/t9904-zsh-prompt.sh (same as t/t9903-bash-prompt.sh but\n         tweaked for zsh)\n\nThere are a lot of indendation changes, so I recommend examining the\nchanges via diff -w.\n\n\nRichard Hansen (11):\n  t9903: remove Zsh test from the suite of Bash prompt tests\n  t9903: put the Bash pc mode prompt test cases in a function\n  t9903: move test name prefix to a separate variable\n  t9903: run pc mode tests again with PS1 expansion disabled\n  t9903: include \"Bash\" in test names via new $shellname var\n  t9903: move PS1 color code variable definitions to lib-bash.sh\n  t9903: move prompt tests to a new lib-prompt-tests.sh file\n  lib-prompt-tests.sh: put all tests inside a function\n  lib-prompt-tests.sh: add variable for string that encodes percent in\n    PS1\n  test-lib: make it possible to override how test code is eval'd\n  t9904: new __git_ps1 tests for Zsh\n\n t/lib-bash.sh          |  12 +\n t/lib-prompt-tests.sh  | 654 +++++++++++++++++++++++++++++++++++++++++++++++++\n t/lib-zsh.sh           |  52 ++++\n t/t9903-bash-prompt.sh | 582 +------------------------------------------\n t/t9904-zsh-prompt.sh  |  10 +\n t/test-lib.sh          |   7 +-\n 6 files changed, 736 insertions(+), 581 deletions(-)\n create mode 100644 t/lib-prompt-tests.sh\n create mode 100644 t/lib-zsh.sh\n create mode 100755 t/t9904-zsh-prompt.sh\n\n-- \n2.0.0\n"},{"id":"243346","messageId":"1401915687-8602-2-git-send-email-rhansen@bbn.com","threadId":"36705","inReplyTo":"1401915687-8602-1-git-send-email-rhansen@bbn.com","subject":"[PATCH v2 01/11] t9903: remove Zsh test from the suite of Bash prompt tests","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2014-06-04T21:01:17Z","receivedAt":"2014-06-04T21:01:17Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"This test is about to become redundant:  All of the Bash prompt tests\nwill be moved into a separate library file that will also be used by a\nnew Zsh-specific test script.\n\nSigned-off-by: Richard Hansen <rhansen@bbn.com>\n---\n t/t9903-bash-prompt.sh | 11 -----------\n 1 file changed, 11 deletions(-)\n\ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex 9150984..335383d 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -577,15 +577,4 @@ test_expect_success 'prompt - bash color pc mode - untracked files status indica\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - zsh color pc mode' '\n-\tprintf \"BEFORE: (%%F{green}master%%f):AFTER\" >expected &&\n-\t(\n-\t\tZSH_VERSION=5.0.0 &&\n-\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\tprintf \"%s\" \"$PS1\" >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n test_done\n-- \n2.0.0\n"},{"id":"243345","messageId":"1401915687-8602-3-git-send-email-rhansen@bbn.com","threadId":"36705","inReplyTo":"1401915687-8602-1-git-send-email-rhansen@bbn.com","subject":"[PATCH v2 02/11] t9903: put the Bash pc mode prompt test cases in a function","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2014-06-04T21:01:18Z","receivedAt":"2014-06-04T21:01:18Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"This is a step toward invoking the same pc mode test cases twice:\nonce with PS1 parameter expansion enabled and once with it disabled.\n\nSigned-off-by: Richard Hansen <rhansen@bbn.com>\n---\n t/t9903-bash-prompt.sh | 236 +++++++++++++++++++++++++------------------------\n 1 file changed, 120 insertions(+), 116 deletions(-)\n\ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex 335383d..c691869 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -451,130 +451,134 @@ test_expect_success 'prompt - format string starting with dash' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - pc mode' '\n-\tprintf \"BEFORE: (\\${__git_ps1_branch_name}):AFTER\\\\nmaster\" >expected &&\n-\tprintf \"\" >expected_output &&\n-\t(\n-\t\t__git_ps1 \"BEFORE:\" \":AFTER\" >\"$actual\" &&\n-\t\ttest_cmp expected_output \"$actual\" &&\n-\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+run_pcmode_tests () {\n+\ttest_expect_success 'prompt - pc mode' '\n+\t\tprintf \"BEFORE: (\\${__git_ps1_branch_name}):AFTER\\\\nmaster\" >expected &&\n+\t\tprintf \"\" >expected_output &&\n+\t\t(\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" >\"$actual\" &&\n+\t\t\ttest_cmp expected_output \"$actual\" &&\n+\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success 'prompt - bash color pc mode - branch name' '\n-\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear}):AFTER\\\\nmaster\" >expected &&\n-\t(\n-\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\t__git_ps1 \"BEFORE:\" \":AFTER\" >\"$actual\"\n-\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success 'prompt - bash color pc mode - branch name' '\n+\t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear}):AFTER\\\\nmaster\" >expected &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" >\"$actual\"\n+\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success 'prompt - bash color pc mode - detached head' '\n-\tprintf \"BEFORE: (${c_red}\\${__git_ps1_branch_name}${c_clear}):AFTER\\\\n(%s...)\" $(git log -1 --format=\"%h\" b1^) >expected &&\n-\tgit checkout b1^ &&\n-\ttest_when_finished \"git checkout master\" &&\n-\t(\n-\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success 'prompt - bash color pc mode - detached head' '\n+\t\tprintf \"BEFORE: (${c_red}\\${__git_ps1_branch_name}${c_clear}):AFTER\\\\n(%s...)\" $(git log -1 --format=\"%h\" b1^) >expected &&\n+\t\tgit checkout b1^ &&\n+\t\ttest_when_finished \"git checkout master\" &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n+\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty worktree' '\n-\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_red}*${c_clear}):AFTER\\\\nmaster\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty worktree' '\n+\t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_red}*${c_clear}):AFTER\\\\nmaster\" >expected &&\n+\t\techo \"dirty\" >file &&\n+\t\ttest_when_finished \"git reset --hard\" &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n+\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index' '\n-\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_green}+${c_clear}):AFTER\\\\nmaster\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\tgit add -u &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index' '\n+\t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_green}+${c_clear}):AFTER\\\\nmaster\" >expected &&\n+\t\techo \"dirty\" >file &&\n+\t\ttest_when_finished \"git reset --hard\" &&\n+\t\tgit add -u &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n+\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index and worktree' '\n-\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_red}*${c_green}+${c_clear}):AFTER\\\\nmaster\" >expected &&\n-\techo \"dirty index\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\tgit add -u &&\n-\techo \"dirty worktree\" >file &&\n-\t(\n-\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index and worktree' '\n+\t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_red}*${c_green}+${c_clear}):AFTER\\\\nmaster\" >expected &&\n+\t\techo \"dirty index\" >file &&\n+\t\ttest_when_finished \"git reset --hard\" &&\n+\t\tgit add -u &&\n+\t\techo \"dirty worktree\" >file &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n+\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success 'prompt - bash color pc mode - dirty status indicator - before root commit' '\n-\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_green}#${c_clear}):AFTER\\\\nmaster\" >expected &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\tcd otherrepo &&\n-\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success 'prompt - bash color pc mode - dirty status indicator - before root commit' '\n+\t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_green}#${c_clear}):AFTER\\\\nmaster\" >expected &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t\tcd otherrepo &&\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n+\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success 'prompt - bash color pc mode - inside .git directory' '\n-\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear}):AFTER\\\\nGIT_DIR!\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\tcd .git &&\n-\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success 'prompt - bash color pc mode - inside .git directory' '\n+\t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear}):AFTER\\\\nGIT_DIR!\" >expected &&\n+\t\techo \"dirty\" >file &&\n+\t\ttest_when_finished \"git reset --hard\" &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t\tcd .git &&\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n+\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success 'prompt - bash color pc mode - stash status indicator' '\n-\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_lblue}\\$${c_clear}):AFTER\\\\nmaster\" >expected &&\n-\techo 2 >file &&\n-\tgit stash &&\n-\ttest_when_finished \"git stash drop\" &&\n-\t(\n-\t\tGIT_PS1_SHOWSTASHSTATE=y &&\n-\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success 'prompt - bash color pc mode - stash status indicator' '\n+\t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_lblue}\\$${c_clear}):AFTER\\\\nmaster\" >expected &&\n+\t\techo 2 >file &&\n+\t\tgit stash &&\n+\t\ttest_when_finished \"git stash drop\" &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWSTASHSTATE=y &&\n+\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n+\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success 'prompt - bash color pc mode - untracked files status indicator' '\n-\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_red}%%${c_clear}):AFTER\\\\nmaster\" >expected &&\n-\t(\n-\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n-\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success 'prompt - bash color pc mode - untracked files status indicator' '\n+\t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_red}%%${c_clear}):AFTER\\\\nmaster\" >expected &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n+\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n+\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n+}\n+\n+run_pcmode_tests\n \n test_done\n-- \n2.0.0\n"},{"id":"243343","messageId":"1401915687-8602-4-git-send-email-rhansen@bbn.com","threadId":"36705","inReplyTo":"1401915687-8602-1-git-send-email-rhansen@bbn.com","subject":"[PATCH v2 03/11] t9903: move test name prefix to a separate variable","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2014-06-04T21:01:19Z","receivedAt":"2014-06-04T21:01:19Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"This is a step toward reusing the same test cases after disabling PS1\nparameter expansion.\n\nSigned-off-by: Richard Hansen <rhansen@bbn.com>\n---\n t/t9903-bash-prompt.sh | 20 +++++++++++---------\n 1 file changed, 11 insertions(+), 9 deletions(-)\n\ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex c691869..d29dd2b 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -463,7 +463,9 @@ run_pcmode_tests () {\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n-\ttest_expect_success 'prompt - bash color pc mode - branch name' '\n+\tpfx=\"prompt - bash color pc mode\"\n+\n+\ttest_expect_success \"$pfx - branch name\" '\n \t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear}):AFTER\\\\nmaster\" >expected &&\n \t\t(\n \t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n@@ -473,7 +475,7 @@ run_pcmode_tests () {\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n-\ttest_expect_success 'prompt - bash color pc mode - detached head' '\n+\ttest_expect_success \"$pfx - detached head\" '\n \t\tprintf \"BEFORE: (${c_red}\\${__git_ps1_branch_name}${c_clear}):AFTER\\\\n(%s...)\" $(git log -1 --format=\"%h\" b1^) >expected &&\n \t\tgit checkout b1^ &&\n \t\ttest_when_finished \"git checkout master\" &&\n@@ -485,7 +487,7 @@ run_pcmode_tests () {\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n-\ttest_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty worktree' '\n+\ttest_expect_success \"$pfx - dirty status indicator - dirty worktree\" '\n \t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_red}*${c_clear}):AFTER\\\\nmaster\" >expected &&\n \t\techo \"dirty\" >file &&\n \t\ttest_when_finished \"git reset --hard\" &&\n@@ -498,7 +500,7 @@ run_pcmode_tests () {\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n-\ttest_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index' '\n+\ttest_expect_success \"$pfx - dirty status indicator - dirty index\" '\n \t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_green}+${c_clear}):AFTER\\\\nmaster\" >expected &&\n \t\techo \"dirty\" >file &&\n \t\ttest_when_finished \"git reset --hard\" &&\n@@ -512,7 +514,7 @@ run_pcmode_tests () {\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n-\ttest_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index and worktree' '\n+\ttest_expect_success \"$pfx - dirty status indicator - dirty index and worktree\" '\n \t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_red}*${c_green}+${c_clear}):AFTER\\\\nmaster\" >expected &&\n \t\techo \"dirty index\" >file &&\n \t\ttest_when_finished \"git reset --hard\" &&\n@@ -527,7 +529,7 @@ run_pcmode_tests () {\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n-\ttest_expect_success 'prompt - bash color pc mode - dirty status indicator - before root commit' '\n+\ttest_expect_success \"$pfx - dirty status indicator - before root commit\" '\n \t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_green}#${c_clear}):AFTER\\\\nmaster\" >expected &&\n \t\t(\n \t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n@@ -539,7 +541,7 @@ run_pcmode_tests () {\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n-\ttest_expect_success 'prompt - bash color pc mode - inside .git directory' '\n+\ttest_expect_success \"$pfx - inside .git directory\" '\n \t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear}):AFTER\\\\nGIT_DIR!\" >expected &&\n \t\techo \"dirty\" >file &&\n \t\ttest_when_finished \"git reset --hard\" &&\n@@ -553,7 +555,7 @@ run_pcmode_tests () {\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n-\ttest_expect_success 'prompt - bash color pc mode - stash status indicator' '\n+\ttest_expect_success \"$pfx - stash status indicator\" '\n \t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_lblue}\\$${c_clear}):AFTER\\\\nmaster\" >expected &&\n \t\techo 2 >file &&\n \t\tgit stash &&\n@@ -567,7 +569,7 @@ run_pcmode_tests () {\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n-\ttest_expect_success 'prompt - bash color pc mode - untracked files status indicator' '\n+\ttest_expect_success \"$pfx - untracked files status indicator\" '\n \t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_red}%%${c_clear}):AFTER\\\\nmaster\" >expected &&\n \t\t(\n \t\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n-- \n2.0.0\n"},{"id":"243344","messageId":"1401915687-8602-5-git-send-email-rhansen@bbn.com","threadId":"36705","inReplyTo":"1401915687-8602-1-git-send-email-rhansen@bbn.com","subject":"[PATCH v2 04/11] t9903: run pc mode tests again with PS1 expansion disabled","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2014-06-04T21:01:20Z","receivedAt":"2014-06-04T21:01:20Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"Bash has a shell option that makes it possible to disable parameter\nexpansion in PS1.  Test __git_ps1's ability to detect and react to\ndisabled PS1 expansion by running the \"pc mode\" tests twice:  once\nwith PS1 parameter expansion enabled and once with it disabled.\n\nSigned-off-by: Richard Hansen <rhansen@bbn.com>\n---\n t/lib-bash.sh          |  3 ++\n t/t9903-bash-prompt.sh | 96 ++++++++++++++++++++++++++++++++++++++------------\n 2 files changed, 76 insertions(+), 23 deletions(-)\n\ndiff --git a/t/lib-bash.sh b/t/lib-bash.sh\nindex 2be955f..37a48fd 100644\n--- a/t/lib-bash.sh\n+++ b/t/lib-bash.sh\n@@ -14,4 +14,7 @@ else\n \texit 0\n fi\n \n+ps1_expansion_enable () { shopt -s promptvars; }\n+ps1_expansion_disable () { shopt -u promptvars; }\n+\n . ./test-lib.sh\ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex d29dd2b..eb5a167 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -451,57 +451,97 @@ test_expect_success 'prompt - format string starting with dash' '\n \ttest_cmp expected \"$actual\"\n '\n \n-run_pcmode_tests () {\n-\ttest_expect_success 'prompt - pc mode' '\n-\t\tprintf \"BEFORE: (\\${__git_ps1_branch_name}):AFTER\\\\nmaster\" >expected &&\n+pcmode_expected () {\n+\tcase $ps1expansion in\n+\ton) printf \"$1\" '${__git_ps1_branch_name}' \"$2\";;\n+\toff) printf \"$1\" \"$2\" \"\";;\n+\tesac >expected\n+}\n+\n+pcmode_actual () {\n+\tcase $ps1expansion in\n+\ton) printf %s\\\\n%s \"$PS1\" \"${__git_ps1_branch_name}\";;\n+\toff) printf %s\\\\n \"$PS1\";;\n+\tesac >\"$actual\"\n+}\n+\n+set_ps1expansion () {\n+\tcase $ps1expansion in\n+\ton) ps1_expansion_enable;;\n+\toff) ps1_expansion_disable;;\n+\t*) error \"invalid argument to _run_pcmode_tests: $ps1expansion\";;\n+\tesac\n+}\n+\n+_run_pcmode_tests () {\n+\tps1expansion=$1; shift\n+\n+\t# Test whether the shell supports enabling/disabling PS1\n+\t# expansion by running set_ps1expansion.  If not, quietly skip\n+\t# this set of tests.\n+\t#\n+\t# Even though set_ps1expansion is run here, it must also be\n+\t# run inside each individual test case because the state of\n+\t# the shell might be reset in some fashion before executing\n+\t# the test code.  (Notably, Zsh shell emulation causes the\n+\t# PROMPT_SUBST option to be reset each time a test is run.)\n+\tset_ps1expansion || return 0\n+\n+\ttest_expect_success \"prompt - pc mode (PS1 expansion $ps1expansion)\" '\n+\t\tset_ps1expansion &&\n+\t\tpcmode_expected \"BEFORE: (%s):AFTER\\\\n%s\" master &&\n \t\tprintf \"\" >expected_output &&\n \t\t(\n \t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" >\"$actual\" &&\n \t\t\ttest_cmp expected_output \"$actual\" &&\n-\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t\tpcmode_actual\n \t\t) &&\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n-\tpfx=\"prompt - bash color pc mode\"\n+\tpfx=\"prompt - bash color pc mode (PS1 expansion $ps1expansion)\"\n \n \ttest_expect_success \"$pfx - branch name\" '\n-\t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear}):AFTER\\\\nmaster\" >expected &&\n+\t\tset_ps1expansion &&\n+\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear}):AFTER\\\\n%s\" master &&\n \t\t(\n \t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n \t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" >\"$actual\"\n-\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t\tpcmode_actual\n \t\t) &&\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n \ttest_expect_success \"$pfx - detached head\" '\n-\t\tprintf \"BEFORE: (${c_red}\\${__git_ps1_branch_name}${c_clear}):AFTER\\\\n(%s...)\" $(git log -1 --format=\"%h\" b1^) >expected &&\n+\t\tset_ps1expansion &&\n+\t\tpcmode_expected \"BEFORE: (${c_red}%s${c_clear}):AFTER\\\\n%s\" \"($(git log -1 --format=\"%h\" b1^)...)\" &&\n \t\tgit checkout b1^ &&\n \t\ttest_when_finished \"git checkout master\" &&\n \t\t(\n \t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n \t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t\tpcmode_actual\n \t\t) &&\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n \ttest_expect_success \"$pfx - dirty status indicator - dirty worktree\" '\n-\t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_red}*${c_clear}):AFTER\\\\nmaster\" >expected &&\n+\t\tset_ps1expansion &&\n+\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_red}*${c_clear}):AFTER\\\\n%s\" master &&\n \t\techo \"dirty\" >file &&\n \t\ttest_when_finished \"git reset --hard\" &&\n \t\t(\n \t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n \t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n \t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t\tpcmode_actual\n \t\t) &&\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n \ttest_expect_success \"$pfx - dirty status indicator - dirty index\" '\n-\t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_green}+${c_clear}):AFTER\\\\nmaster\" >expected &&\n+\t\tset_ps1expansion &&\n+\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_green}+${c_clear}):AFTER\\\\n%s\" master &&\n \t\techo \"dirty\" >file &&\n \t\ttest_when_finished \"git reset --hard\" &&\n \t\tgit add -u &&\n@@ -509,13 +549,14 @@ run_pcmode_tests () {\n \t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n \t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n \t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t\tpcmode_actual\n \t\t) &&\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n \ttest_expect_success \"$pfx - dirty status indicator - dirty index and worktree\" '\n-\t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_red}*${c_green}+${c_clear}):AFTER\\\\nmaster\" >expected &&\n+\t\tset_ps1expansion &&\n+\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_red}*${c_green}+${c_clear}):AFTER\\\\n%s\" master &&\n \t\techo \"dirty index\" >file &&\n \t\ttest_when_finished \"git reset --hard\" &&\n \t\tgit add -u &&\n@@ -524,25 +565,27 @@ run_pcmode_tests () {\n \t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n \t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n \t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t\tpcmode_actual\n \t\t) &&\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n \ttest_expect_success \"$pfx - dirty status indicator - before root commit\" '\n-\t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_green}#${c_clear}):AFTER\\\\nmaster\" >expected &&\n+\t\tset_ps1expansion &&\n+\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_green}#${c_clear}):AFTER\\\\n%s\" master &&\n \t\t(\n \t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n \t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n \t\t\tcd otherrepo &&\n \t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t\tpcmode_actual\n \t\t) &&\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n \ttest_expect_success \"$pfx - inside .git directory\" '\n-\t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear}):AFTER\\\\nGIT_DIR!\" >expected &&\n+\t\tset_ps1expansion &&\n+\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear}):AFTER\\\\n%s\" \"GIT_DIR!\" &&\n \t\techo \"dirty\" >file &&\n \t\ttest_when_finished \"git reset --hard\" &&\n \t\t(\n@@ -550,13 +593,14 @@ run_pcmode_tests () {\n \t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n \t\t\tcd .git &&\n \t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t\tpcmode_actual\n \t\t) &&\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n \ttest_expect_success \"$pfx - stash status indicator\" '\n-\t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_lblue}\\$${c_clear}):AFTER\\\\nmaster\" >expected &&\n+\t\tset_ps1expansion &&\n+\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_lblue}\\$${c_clear}):AFTER\\\\n%s\" master &&\n \t\techo 2 >file &&\n \t\tgit stash &&\n \t\ttest_when_finished \"git stash drop\" &&\n@@ -564,23 +608,29 @@ run_pcmode_tests () {\n \t\t\tGIT_PS1_SHOWSTASHSTATE=y &&\n \t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n \t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t\tpcmode_actual\n \t\t) &&\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n \ttest_expect_success \"$pfx - untracked files status indicator\" '\n-\t\tprintf \"BEFORE: (${c_green}\\${__git_ps1_branch_name}${c_clear} ${c_red}%%${c_clear}):AFTER\\\\nmaster\" >expected &&\n+\t\tset_ps1expansion &&\n+\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_red}%%${c_clear}):AFTER\\\\n%s\" master &&\n \t\t(\n \t\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n \t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n \t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\t\tprintf \"%s\\\\n%s\" \"$PS1\" \"${__git_ps1_branch_name}\" >\"$actual\"\n+\t\t\tpcmode_actual\n \t\t) &&\n \t\ttest_cmp expected \"$actual\"\n \t'\n }\n \n+run_pcmode_tests () {\n+\t_run_pcmode_tests on\n+\t_run_pcmode_tests off\n+}\n+\n run_pcmode_tests\n \n test_done\n-- \n2.0.0\n"},{"id":"243348","messageId":"1401915687-8602-6-git-send-email-rhansen@bbn.com","threadId":"36705","inReplyTo":"1401915687-8602-1-git-send-email-rhansen@bbn.com","subject":"[PATCH v2 05/11] t9903: include \"Bash\" in test names via new $shellname var","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2014-06-04T21:01:21Z","receivedAt":"2014-06-04T21:01:21Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"Define a new 'shellname' variable in lib-bash.sh and use it in the\nprompt test names.  This is a step toward moving the shell prompt\ntests to a separate library file so that they can be reused to test\nprompting in Zsh.\n\nSigned-off-by: Richard Hansen <rhansen@bbn.com>\n---\n t/lib-bash.sh          |  2 ++\n t/t9903-bash-prompt.sh | 86 ++++++++++++++++++++++++++------------------------\n 2 files changed, 46 insertions(+), 42 deletions(-)\n\ndiff --git a/t/lib-bash.sh b/t/lib-bash.sh\nindex 37a48fd..a0f4e16 100644\n--- a/t/lib-bash.sh\n+++ b/t/lib-bash.sh\n@@ -14,6 +14,8 @@ else\n \texit 0\n fi\n \n+shellname=Bash\n+\n ps1_expansion_enable () { shopt -s promptvars; }\n ps1_expansion_disable () { shopt -u promptvars; }\n \ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex eb5a167..27135a1 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -15,7 +15,7 @@ c_green='\\\\[\\\\e[32m\\\\]'\n c_lblue='\\\\[\\\\e[1;34m\\\\]'\n c_clear='\\\\[\\\\e[0m\\\\]'\n \n-test_expect_success 'setup for prompt tests' '\n+test_expect_success \"setup for $shellname prompt tests\" '\n \tgit init otherrepo &&\n \techo 1 >file &&\n \tgit add file &&\n@@ -38,13 +38,15 @@ test_expect_success 'setup for prompt tests' '\n \tgit checkout master\n '\n \n-test_expect_success 'prompt - branch name' '\n+pfx=\"$shellname prompt\"\n+\n+test_expect_success \"$pfx - branch name\" '\n \tprintf \" (master)\" >expected &&\n \t__git_ps1 >\"$actual\" &&\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success SYMLINKS 'prompt - branch name - symlink symref' '\n+test_expect_success SYMLINKS \"$pfx - branch name - symlink symref\" '\n \tprintf \" (master)\" >expected &&\n \ttest_when_finished \"git checkout master\" &&\n \ttest_config core.preferSymlinkRefs true &&\n@@ -53,7 +55,7 @@ test_expect_success SYMLINKS 'prompt - branch name - symlink symref' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - unborn branch' '\n+test_expect_success \"$pfx - unborn branch\" '\n \tprintf \" (unborn)\" >expected &&\n \tgit checkout --orphan unborn &&\n \ttest_when_finished \"git checkout master\" &&\n@@ -72,7 +74,7 @@ else\n \tsay 'Your filesystem does not allow newlines in filenames.'\n fi\n \n-test_expect_success FUNNYNAMES 'prompt - with newline in path' '\n+test_expect_success FUNNYNAMES \"$pfx - with newline in path\" '\n \tprintf \" (master)\" >expected &&\n \tgit init \"$repo_with_newline\" &&\n \ttest_when_finished \"rm -rf \\\"$repo_with_newline\\\"\" &&\n@@ -84,7 +86,7 @@ test_expect_success FUNNYNAMES 'prompt - with newline in path' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - detached head' '\n+test_expect_success \"$pfx - detached head\" '\n \tprintf \" ((%s...))\" $(git log -1 --format=\"%h\" --abbrev=13 b1^) >expected &&\n \ttest_config core.abbrev 13 &&\n \tgit checkout b1^ &&\n@@ -93,7 +95,7 @@ test_expect_success 'prompt - detached head' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - describe detached head - contains' '\n+test_expect_success \"$pfx - describe detached head - contains\" '\n \tprintf \" ((t2~1))\" >expected &&\n \tgit checkout b1^ &&\n \ttest_when_finished \"git checkout master\" &&\n@@ -104,7 +106,7 @@ test_expect_success 'prompt - describe detached head - contains' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - describe detached head - branch' '\n+test_expect_success \"$pfx - describe detached head - branch\" '\n \tprintf \" ((b1~1))\" >expected &&\n \tgit checkout b1^ &&\n \ttest_when_finished \"git checkout master\" &&\n@@ -115,7 +117,7 @@ test_expect_success 'prompt - describe detached head - branch' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - describe detached head - describe' '\n+test_expect_success \"$pfx - describe detached head - describe\" '\n \tprintf \" ((t1-1-g%s))\" $(git log -1 --format=\"%h\" b1^) >expected &&\n \tgit checkout b1^ &&\n \ttest_when_finished \"git checkout master\" &&\n@@ -126,7 +128,7 @@ test_expect_success 'prompt - describe detached head - describe' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - describe detached head - default' '\n+test_expect_success \"$pfx - describe detached head - default\" '\n \tprintf \" ((t2))\" >expected &&\n \tgit checkout --detach b1 &&\n \ttest_when_finished \"git checkout master\" &&\n@@ -134,7 +136,7 @@ test_expect_success 'prompt - describe detached head - default' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - inside .git directory' '\n+test_expect_success \"$pfx - inside .git directory\" '\n \tprintf \" (GIT_DIR!)\" >expected &&\n \t(\n \t\tcd .git &&\n@@ -143,7 +145,7 @@ test_expect_success 'prompt - inside .git directory' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - deep inside .git directory' '\n+test_expect_success \"$pfx - deep inside .git directory\" '\n \tprintf \" (GIT_DIR!)\" >expected &&\n \t(\n \t\tcd .git/refs/heads &&\n@@ -152,7 +154,7 @@ test_expect_success 'prompt - deep inside .git directory' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - inside bare repository' '\n+test_expect_success \"$pfx - inside bare repository\" '\n \tprintf \" (BARE:master)\" >expected &&\n \tgit init --bare bare.git &&\n \ttest_when_finished \"rm -rf bare.git\" &&\n@@ -163,7 +165,7 @@ test_expect_success 'prompt - inside bare repository' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - interactive rebase' '\n+test_expect_success \"$pfx - interactive rebase\" '\n \tprintf \" (b1|REBASE-i 2/3)\" >expected\n \twrite_script fake_editor.sh <<-\\EOF &&\n \t\techo \"exec echo\" >\"$1\"\n@@ -180,7 +182,7 @@ test_expect_success 'prompt - interactive rebase' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - rebase merge' '\n+test_expect_success \"$pfx - rebase merge\" '\n \tprintf \" (b2|REBASE-m 1/3)\" >expected &&\n \tgit checkout b2 &&\n \ttest_when_finished \"git checkout master\" &&\n@@ -190,7 +192,7 @@ test_expect_success 'prompt - rebase merge' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - rebase' '\n+test_expect_success \"$pfx - rebase\" '\n \tprintf \" (b2|REBASE 1/3)\" >expected &&\n \tgit checkout b2 &&\n \ttest_when_finished \"git checkout master\" &&\n@@ -200,7 +202,7 @@ test_expect_success 'prompt - rebase' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - merge' '\n+test_expect_success \"$pfx - merge\" '\n \tprintf \" (b1|MERGING)\" >expected &&\n \tgit checkout b1 &&\n \ttest_when_finished \"git checkout master\" &&\n@@ -210,7 +212,7 @@ test_expect_success 'prompt - merge' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - cherry-pick' '\n+test_expect_success \"$pfx - cherry-pick\" '\n \tprintf \" (master|CHERRY-PICKING)\" >expected &&\n \ttest_must_fail git cherry-pick b1 &&\n \ttest_when_finished \"git reset --hard\" &&\n@@ -218,7 +220,7 @@ test_expect_success 'prompt - cherry-pick' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - bisect' '\n+test_expect_success \"$pfx - bisect\" '\n \tprintf \" (master|BISECTING)\" >expected &&\n \tgit bisect start &&\n \ttest_when_finished \"git bisect reset\" &&\n@@ -226,7 +228,7 @@ test_expect_success 'prompt - bisect' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - dirty status indicator - clean' '\n+test_expect_success \"$pfx - dirty status indicator - clean\" '\n \tprintf \" (master)\" >expected &&\n \t(\n \t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n@@ -235,7 +237,7 @@ test_expect_success 'prompt - dirty status indicator - clean' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - dirty status indicator - dirty worktree' '\n+test_expect_success \"$pfx - dirty status indicator - dirty worktree\" '\n \tprintf \" (master *)\" >expected &&\n \techo \"dirty\" >file &&\n \ttest_when_finished \"git reset --hard\" &&\n@@ -246,7 +248,7 @@ test_expect_success 'prompt - dirty status indicator - dirty worktree' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - dirty status indicator - dirty index' '\n+test_expect_success \"$pfx - dirty status indicator - dirty index\" '\n \tprintf \" (master +)\" >expected &&\n \techo \"dirty\" >file &&\n \ttest_when_finished \"git reset --hard\" &&\n@@ -258,7 +260,7 @@ test_expect_success 'prompt - dirty status indicator - dirty index' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - dirty status indicator - dirty index and worktree' '\n+test_expect_success \"$pfx - dirty status indicator - dirty index and worktree\" '\n \tprintf \" (master *+)\" >expected &&\n \techo \"dirty index\" >file &&\n \ttest_when_finished \"git reset --hard\" &&\n@@ -271,7 +273,7 @@ test_expect_success 'prompt - dirty status indicator - dirty index and worktree'\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - dirty status indicator - before root commit' '\n+test_expect_success \"$pfx - dirty status indicator - before root commit\" '\n \tprintf \" (master #)\" >expected &&\n \t(\n \t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n@@ -281,7 +283,7 @@ test_expect_success 'prompt - dirty status indicator - before root commit' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - dirty status indicator - shell variable unset with config disabled' '\n+test_expect_success \"$pfx - dirty status indicator - shell variable unset with config disabled\" '\n \tprintf \" (master)\" >expected &&\n \techo \"dirty\" >file &&\n \ttest_when_finished \"git reset --hard\" &&\n@@ -293,7 +295,7 @@ test_expect_success 'prompt - dirty status indicator - shell variable unset with\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - dirty status indicator - shell variable unset with config enabled' '\n+test_expect_success \"$pfx - dirty status indicator - shell variable unset with config enabled\" '\n \tprintf \" (master)\" >expected &&\n \techo \"dirty\" >file &&\n \ttest_when_finished \"git reset --hard\" &&\n@@ -305,7 +307,7 @@ test_expect_success 'prompt - dirty status indicator - shell variable unset with\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - dirty status indicator - shell variable set with config disabled' '\n+test_expect_success \"$pfx - dirty status indicator - shell variable set with config disabled\" '\n \tprintf \" (master)\" >expected &&\n \techo \"dirty\" >file &&\n \ttest_when_finished \"git reset --hard\" &&\n@@ -317,7 +319,7 @@ test_expect_success 'prompt - dirty status indicator - shell variable set with c\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - dirty status indicator - shell variable set with config enabled' '\n+test_expect_success \"$pfx - dirty status indicator - shell variable set with config enabled\" '\n \tprintf \" (master *)\" >expected &&\n \techo \"dirty\" >file &&\n \ttest_when_finished \"git reset --hard\" &&\n@@ -329,7 +331,7 @@ test_expect_success 'prompt - dirty status indicator - shell variable set with c\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - dirty status indicator - not shown inside .git directory' '\n+test_expect_success \"$pfx - dirty status indicator - not shown inside .git directory\" '\n \tprintf \" (GIT_DIR!)\" >expected &&\n \techo \"dirty\" >file &&\n \ttest_when_finished \"git reset --hard\" &&\n@@ -341,7 +343,7 @@ test_expect_success 'prompt - dirty status indicator - not shown inside .git dir\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - stash status indicator - no stash' '\n+test_expect_success \"$pfx - stash status indicator - no stash\" '\n \tprintf \" (master)\" >expected &&\n \t(\n \t\tGIT_PS1_SHOWSTASHSTATE=y &&\n@@ -350,7 +352,7 @@ test_expect_success 'prompt - stash status indicator - no stash' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - stash status indicator - stash' '\n+test_expect_success \"$pfx - stash status indicator - stash\" '\n \tprintf \" (master $)\" >expected &&\n \techo 2 >file &&\n \tgit stash &&\n@@ -363,7 +365,7 @@ test_expect_success 'prompt - stash status indicator - stash' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - stash status indicator - not shown inside .git directory' '\n+test_expect_success \"$pfx - stash status indicator - not shown inside .git directory\" '\n \tprintf \" (GIT_DIR!)\" >expected &&\n \techo 2 >file &&\n \tgit stash &&\n@@ -376,7 +378,7 @@ test_expect_success 'prompt - stash status indicator - not shown inside .git dir\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - untracked files status indicator - no untracked files' '\n+test_expect_success \"$pfx - untracked files status indicator - no untracked files\" '\n \tprintf \" (master)\" >expected &&\n \t(\n \t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n@@ -386,7 +388,7 @@ test_expect_success 'prompt - untracked files status indicator - no untracked fi\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - untracked files status indicator - untracked files' '\n+test_expect_success \"$pfx - untracked files status indicator - untracked files\" '\n \tprintf \" (master %%)\" >expected &&\n \t(\n \t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n@@ -395,7 +397,7 @@ test_expect_success 'prompt - untracked files status indicator - untracked files\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - untracked files status indicator - shell variable unset with config disabled' '\n+test_expect_success \"$pfx - untracked files status indicator - shell variable unset with config disabled\" '\n \tprintf \" (master)\" >expected &&\n \ttest_config bash.showUntrackedFiles false &&\n \t(\n@@ -405,7 +407,7 @@ test_expect_success 'prompt - untracked files status indicator - shell variable\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - untracked files status indicator - shell variable unset with config enabled' '\n+test_expect_success \"$pfx - untracked files status indicator - shell variable unset with config enabled\" '\n \tprintf \" (master)\" >expected &&\n \ttest_config bash.showUntrackedFiles true &&\n \t(\n@@ -415,7 +417,7 @@ test_expect_success 'prompt - untracked files status indicator - shell variable\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - untracked files status indicator - shell variable set with config disabled' '\n+test_expect_success \"$pfx - untracked files status indicator - shell variable set with config disabled\" '\n \tprintf \" (master)\" >expected &&\n \ttest_config bash.showUntrackedFiles false &&\n \t(\n@@ -425,7 +427,7 @@ test_expect_success 'prompt - untracked files status indicator - shell variable\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - untracked files status indicator - shell variable set with config enabled' '\n+test_expect_success \"$pfx - untracked files status indicator - shell variable set with config enabled\" '\n \tprintf \" (master %%)\" >expected &&\n \ttest_config bash.showUntrackedFiles true &&\n \t(\n@@ -435,7 +437,7 @@ test_expect_success 'prompt - untracked files status indicator - shell variable\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - untracked files status indicator - not shown inside .git directory' '\n+test_expect_success \"$pfx - untracked files status indicator - not shown inside .git directory\" '\n \tprintf \" (GIT_DIR!)\" >expected &&\n \t(\n \t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n@@ -445,7 +447,7 @@ test_expect_success 'prompt - untracked files status indicator - not shown insid\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - format string starting with dash' '\n+test_expect_success \"$pfx - format string starting with dash\" '\n \tprintf -- \"-master\" >expected &&\n \t__git_ps1 \"-%s\" >\"$actual\" &&\n \ttest_cmp expected \"$actual\"\n@@ -487,7 +489,7 @@ _run_pcmode_tests () {\n \t# PROMPT_SUBST option to be reset each time a test is run.)\n \tset_ps1expansion || return 0\n \n-\ttest_expect_success \"prompt - pc mode (PS1 expansion $ps1expansion)\" '\n+\ttest_expect_success \"$shellname prompt - pc mode (PS1 expansion $ps1expansion)\" '\n \t\tset_ps1expansion &&\n \t\tpcmode_expected \"BEFORE: (%s):AFTER\\\\n%s\" master &&\n \t\tprintf \"\" >expected_output &&\n@@ -499,7 +501,7 @@ _run_pcmode_tests () {\n \t\ttest_cmp expected \"$actual\"\n \t'\n \n-\tpfx=\"prompt - bash color pc mode (PS1 expansion $ps1expansion)\"\n+\tpfx=\"$shellname prompt - color pc mode (PS1 expansion $ps1expansion)\"\n \n \ttest_expect_success \"$pfx - branch name\" '\n \t\tset_ps1expansion &&\n-- \n2.0.0\n"},{"id":"243347","messageId":"1401915687-8602-7-git-send-email-rhansen@bbn.com","threadId":"36705","inReplyTo":"1401915687-8602-1-git-send-email-rhansen@bbn.com","subject":"[PATCH v2 06/11] t9903: move PS1 color code variable definitions to lib-bash.sh","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2014-06-04T21:01:22Z","receivedAt":"2014-06-04T21:01:22Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"Define a new 'set_ps1_format_vars' function in lib-bash.sh that sets\nthe c_red, c_green, c_lblue, and c_clear variables.  Call this\nfunction from run_pcmode_tests().  This is a step toward moving the\nshell prompt tests to a separate library file so that they can be\nreused to test prompting in Zsh.\n\nSigned-off-by: Richard Hansen <rhansen@bbn.com>\n---\n t/lib-bash.sh          | 6 ++++++\n t/t9903-bash-prompt.sh | 5 +----\n 2 files changed, 7 insertions(+), 4 deletions(-)\n\ndiff --git a/t/lib-bash.sh b/t/lib-bash.sh\nindex a0f4e16..9d428bd 100644\n--- a/t/lib-bash.sh\n+++ b/t/lib-bash.sh\n@@ -18,5 +18,11 @@ shellname=Bash\n \n ps1_expansion_enable () { shopt -s promptvars; }\n ps1_expansion_disable () { shopt -u promptvars; }\n+set_ps1_format_vars () {\n+\tc_red='\\\\[\\\\e[31m\\\\]'\n+\tc_green='\\\\[\\\\e[32m\\\\]'\n+\tc_lblue='\\\\[\\\\e[1;34m\\\\]'\n+\tc_clear='\\\\[\\\\e[0m\\\\]'\n+}\n \n . ./test-lib.sh\ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex 27135a1..fe60cf9 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -10,10 +10,7 @@ test_description='test git-specific bash prompt functions'\n . \"$GIT_BUILD_DIR/contrib/completion/git-prompt.sh\"\n \n actual=\"$TRASH_DIRECTORY/actual\"\n-c_red='\\\\[\\\\e[31m\\\\]'\n-c_green='\\\\[\\\\e[32m\\\\]'\n-c_lblue='\\\\[\\\\e[1;34m\\\\]'\n-c_clear='\\\\[\\\\e[0m\\\\]'\n+set_ps1_format_vars\n \n test_expect_success \"setup for $shellname prompt tests\" '\n \tgit init otherrepo &&\n-- \n2.0.0\n"},{"id":"243349","messageId":"1401915687-8602-8-git-send-email-rhansen@bbn.com","threadId":"36705","inReplyTo":"1401915687-8602-1-git-send-email-rhansen@bbn.com","subject":"[PATCH v2 07/11] t9903: move prompt tests to a new lib-prompt-tests.sh file","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2014-06-04T21:01:23Z","receivedAt":"2014-06-04T21:01:23Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"This is a step toward creating a new test script that runs the same\nprompt tests as t9903 but with Zsh instead of Bash.\n\nSigned-off-by: Richard Hansen <rhansen@bbn.com>\n---\n t/lib-prompt-tests.sh  | 653 +++++++++++++++++++++++++++++++++++++++++++++++++\n t/t9903-bash-prompt.sh | 626 +----------------------------------------------\n 2 files changed, 654 insertions(+), 625 deletions(-)\n create mode 100644 t/lib-prompt-tests.sh\n\ndiff --git a/t/lib-prompt-tests.sh b/t/lib-prompt-tests.sh\nnew file mode 100644\nindex 0000000..7aaeb8e\n--- /dev/null\n+++ b/t/lib-prompt-tests.sh\n@@ -0,0 +1,653 @@\n+# Copyright (c) 2012 SZEDER Gábor\n+\n+# To use this library:\n+#   1. set the variable shellname to the name of the shell (e.g.,\n+#      \"Bash\")\n+#   2. define functions named ps1_expansion_enable and\n+#      ps1_expansion_disable that, upon return, guarantee that the\n+#      shell will and will not (respectively) perform parameter\n+#      expansion on PS1, if supported by the shell.  If it is not\n+#      possible to configure the shell to disable (enable) PS1\n+#      expansion, ps1_expansion_enable should simply return 0\n+#      (non-zero) and ps1_expansion_disable should simply return\n+#      non-zero (0)\n+#   3. define a function named set_ps1_format_vars that sets the\n+#      variables c_red, c_green, c_lblue, and c_clear to the strings\n+#      that __git_ps1 uses to add color to the prompt.  The values of\n+#      these variables are used in the first argument to the printf\n+#      command, so they must be escaped appropriately.\n+#   4. source this library\n+\n+# sanity checks\n+[ -n \"$shellname\" ] || error \"shellname must be set to the name of the shell\"\n+for i in ps1_expansion_enable ps1_expansion_disable set_ps1_format_vars\n+do\n+\tcommand -v \"$i\" >/dev/null 2>&1 || error \"function $i not defined\"\n+done\n+(ps1_expansion_enable || ps1_expansion_disable) \\\n+\t|| error \"either ps1_expansion_enable or ps1_expansion_disable must return true\"\n+\n+. \"$GIT_BUILD_DIR/contrib/completion/git-prompt.sh\"\n+\n+actual=\"$TRASH_DIRECTORY/actual\"\n+set_ps1_format_vars\n+\n+test_expect_success \"setup for $shellname prompt tests\" '\n+\tgit init otherrepo &&\n+\techo 1 >file &&\n+\tgit add file &&\n+\ttest_tick &&\n+\tgit commit -m initial &&\n+\tgit tag -a -m msg1 t1 &&\n+\tgit checkout -b b1 &&\n+\techo 2 >file &&\n+\tgit commit -m \"second b1\" file &&\n+\techo 3 >file &&\n+\tgit commit -m \"third b1\" file &&\n+\tgit tag -a -m msg2 t2 &&\n+\tgit checkout -b b2 master &&\n+\techo 0 >file &&\n+\tgit commit -m \"second b2\" file &&\n+\techo 00 >file &&\n+\tgit commit -m \"another b2\" file &&\n+\techo 000 >file &&\n+\tgit commit -m \"yet another b2\" file &&\n+\tgit checkout master\n+'\n+\n+pfx=\"$shellname prompt\"\n+\n+test_expect_success \"$pfx - branch name\" '\n+\tprintf \" (master)\" >expected &&\n+\t__git_ps1 >\"$actual\" &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success SYMLINKS \"$pfx - branch name - symlink symref\" '\n+\tprintf \" (master)\" >expected &&\n+\ttest_when_finished \"git checkout master\" &&\n+\ttest_config core.preferSymlinkRefs true &&\n+\tgit checkout master &&\n+\t__git_ps1 >\"$actual\" &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - unborn branch\" '\n+\tprintf \" (unborn)\" >expected &&\n+\tgit checkout --orphan unborn &&\n+\ttest_when_finished \"git checkout master\" &&\n+\t__git_ps1 >\"$actual\" &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+repo_with_newline='repo\n+with\n+newline'\n+\n+if mkdir \"$repo_with_newline\" 2>/dev/null\n+then\n+\ttest_set_prereq FUNNYNAMES\n+else\n+\tsay 'Your filesystem does not allow newlines in filenames.'\n+fi\n+\n+test_expect_success FUNNYNAMES \"$pfx - with newline in path\" '\n+\tprintf \" (master)\" >expected &&\n+\tgit init \"$repo_with_newline\" &&\n+\ttest_when_finished \"rm -rf \\\"$repo_with_newline\\\"\" &&\n+\tmkdir \"$repo_with_newline\"/subdir &&\n+\t(\n+\t\tcd \"$repo_with_newline/subdir\" &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - detached head\" '\n+\tprintf \" ((%s...))\" $(git log -1 --format=\"%h\" --abbrev=13 b1^) >expected &&\n+\ttest_config core.abbrev 13 &&\n+\tgit checkout b1^ &&\n+\ttest_when_finished \"git checkout master\" &&\n+\t__git_ps1 >\"$actual\" &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - describe detached head - contains\" '\n+\tprintf \" ((t2~1))\" >expected &&\n+\tgit checkout b1^ &&\n+\ttest_when_finished \"git checkout master\" &&\n+\t(\n+\t\tGIT_PS1_DESCRIBE_STYLE=contains &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - describe detached head - branch\" '\n+\tprintf \" ((b1~1))\" >expected &&\n+\tgit checkout b1^ &&\n+\ttest_when_finished \"git checkout master\" &&\n+\t(\n+\t\tGIT_PS1_DESCRIBE_STYLE=branch &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - describe detached head - describe\" '\n+\tprintf \" ((t1-1-g%s))\" $(git log -1 --format=\"%h\" b1^) >expected &&\n+\tgit checkout b1^ &&\n+\ttest_when_finished \"git checkout master\" &&\n+\t(\n+\t\tGIT_PS1_DESCRIBE_STYLE=describe &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - describe detached head - default\" '\n+\tprintf \" ((t2))\" >expected &&\n+\tgit checkout --detach b1 &&\n+\ttest_when_finished \"git checkout master\" &&\n+\t__git_ps1 >\"$actual\" &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - inside .git directory\" '\n+\tprintf \" (GIT_DIR!)\" >expected &&\n+\t(\n+\t\tcd .git &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - deep inside .git directory\" '\n+\tprintf \" (GIT_DIR!)\" >expected &&\n+\t(\n+\t\tcd .git/refs/heads &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - inside bare repository\" '\n+\tprintf \" (BARE:master)\" >expected &&\n+\tgit init --bare bare.git &&\n+\ttest_when_finished \"rm -rf bare.git\" &&\n+\t(\n+\t\tcd bare.git &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - interactive rebase\" '\n+\tprintf \" (b1|REBASE-i 2/3)\" >expected\n+\twrite_script fake_editor.sh <<-\\EOF &&\n+\t\techo \"exec echo\" >\"$1\"\n+\t\techo \"edit $(git log -1 --format=\"%h\")\" >>\"$1\"\n+\t\techo \"exec echo\" >>\"$1\"\n+\tEOF\n+\ttest_when_finished \"rm -f fake_editor.sh\" &&\n+\ttest_set_editor \"$TRASH_DIRECTORY/fake_editor.sh\" &&\n+\tgit checkout b1 &&\n+\ttest_when_finished \"git checkout master\" &&\n+\tgit rebase -i HEAD^ &&\n+\ttest_when_finished \"git rebase --abort\"\n+\t__git_ps1 >\"$actual\" &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - rebase merge\" '\n+\tprintf \" (b2|REBASE-m 1/3)\" >expected &&\n+\tgit checkout b2 &&\n+\ttest_when_finished \"git checkout master\" &&\n+\ttest_must_fail git rebase --merge b1 b2 &&\n+\ttest_when_finished \"git rebase --abort\" &&\n+\t__git_ps1 >\"$actual\" &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - rebase\" '\n+\tprintf \" (b2|REBASE 1/3)\" >expected &&\n+\tgit checkout b2 &&\n+\ttest_when_finished \"git checkout master\" &&\n+\ttest_must_fail git rebase b1 b2 &&\n+\ttest_when_finished \"git rebase --abort\" &&\n+\t__git_ps1 >\"$actual\" &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - merge\" '\n+\tprintf \" (b1|MERGING)\" >expected &&\n+\tgit checkout b1 &&\n+\ttest_when_finished \"git checkout master\" &&\n+\ttest_must_fail git merge b2 &&\n+\ttest_when_finished \"git reset --hard\" &&\n+\t__git_ps1 >\"$actual\" &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - cherry-pick\" '\n+\tprintf \" (master|CHERRY-PICKING)\" >expected &&\n+\ttest_must_fail git cherry-pick b1 &&\n+\ttest_when_finished \"git reset --hard\" &&\n+\t__git_ps1 >\"$actual\" &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - bisect\" '\n+\tprintf \" (master|BISECTING)\" >expected &&\n+\tgit bisect start &&\n+\ttest_when_finished \"git bisect reset\" &&\n+\t__git_ps1 >\"$actual\" &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - dirty status indicator - clean\" '\n+\tprintf \" (master)\" >expected &&\n+\t(\n+\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - dirty status indicator - dirty worktree\" '\n+\tprintf \" (master *)\" >expected &&\n+\techo \"dirty\" >file &&\n+\ttest_when_finished \"git reset --hard\" &&\n+\t(\n+\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - dirty status indicator - dirty index\" '\n+\tprintf \" (master +)\" >expected &&\n+\techo \"dirty\" >file &&\n+\ttest_when_finished \"git reset --hard\" &&\n+\tgit add -u &&\n+\t(\n+\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - dirty status indicator - dirty index and worktree\" '\n+\tprintf \" (master *+)\" >expected &&\n+\techo \"dirty index\" >file &&\n+\ttest_when_finished \"git reset --hard\" &&\n+\tgit add -u &&\n+\techo \"dirty worktree\" >file &&\n+\t(\n+\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - dirty status indicator - before root commit\" '\n+\tprintf \" (master #)\" >expected &&\n+\t(\n+\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\tcd otherrepo &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - dirty status indicator - shell variable unset with config disabled\" '\n+\tprintf \" (master)\" >expected &&\n+\techo \"dirty\" >file &&\n+\ttest_when_finished \"git reset --hard\" &&\n+\ttest_config bash.showDirtyState false &&\n+\t(\n+\t\tsane_unset GIT_PS1_SHOWDIRTYSTATE &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - dirty status indicator - shell variable unset with config enabled\" '\n+\tprintf \" (master)\" >expected &&\n+\techo \"dirty\" >file &&\n+\ttest_when_finished \"git reset --hard\" &&\n+\ttest_config bash.showDirtyState true &&\n+\t(\n+\t\tsane_unset GIT_PS1_SHOWDIRTYSTATE &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - dirty status indicator - shell variable set with config disabled\" '\n+\tprintf \" (master)\" >expected &&\n+\techo \"dirty\" >file &&\n+\ttest_when_finished \"git reset --hard\" &&\n+\ttest_config bash.showDirtyState false &&\n+\t(\n+\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - dirty status indicator - shell variable set with config enabled\" '\n+\tprintf \" (master *)\" >expected &&\n+\techo \"dirty\" >file &&\n+\ttest_when_finished \"git reset --hard\" &&\n+\ttest_config bash.showDirtyState true &&\n+\t(\n+\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - dirty status indicator - not shown inside .git directory\" '\n+\tprintf \" (GIT_DIR!)\" >expected &&\n+\techo \"dirty\" >file &&\n+\ttest_when_finished \"git reset --hard\" &&\n+\t(\n+\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\tcd .git &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - stash status indicator - no stash\" '\n+\tprintf \" (master)\" >expected &&\n+\t(\n+\t\tGIT_PS1_SHOWSTASHSTATE=y &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - stash status indicator - stash\" '\n+\tprintf \" (master $)\" >expected &&\n+\techo 2 >file &&\n+\tgit stash &&\n+\ttest_when_finished \"git stash drop\" &&\n+\tgit pack-refs --all &&\n+\t(\n+\t\tGIT_PS1_SHOWSTASHSTATE=y &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - stash status indicator - not shown inside .git directory\" '\n+\tprintf \" (GIT_DIR!)\" >expected &&\n+\techo 2 >file &&\n+\tgit stash &&\n+\ttest_when_finished \"git stash drop\" &&\n+\t(\n+\t\tGIT_PS1_SHOWSTASHSTATE=y &&\n+\t\tcd .git &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - untracked files status indicator - no untracked files\" '\n+\tprintf \" (master)\" >expected &&\n+\t(\n+\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n+\t\tcd otherrepo &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - untracked files status indicator - untracked files\" '\n+\tprintf \" (master %%)\" >expected &&\n+\t(\n+\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - untracked files status indicator - shell variable unset with config disabled\" '\n+\tprintf \" (master)\" >expected &&\n+\ttest_config bash.showUntrackedFiles false &&\n+\t(\n+\t\tsane_unset GIT_PS1_SHOWUNTRACKEDFILES &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - untracked files status indicator - shell variable unset with config enabled\" '\n+\tprintf \" (master)\" >expected &&\n+\ttest_config bash.showUntrackedFiles true &&\n+\t(\n+\t\tsane_unset GIT_PS1_SHOWUNTRACKEDFILES &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - untracked files status indicator - shell variable set with config disabled\" '\n+\tprintf \" (master)\" >expected &&\n+\ttest_config bash.showUntrackedFiles false &&\n+\t(\n+\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - untracked files status indicator - shell variable set with config enabled\" '\n+\tprintf \" (master %%)\" >expected &&\n+\ttest_config bash.showUntrackedFiles true &&\n+\t(\n+\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - untracked files status indicator - not shown inside .git directory\" '\n+\tprintf \" (GIT_DIR!)\" >expected &&\n+\t(\n+\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n+\t\tcd .git &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success \"$pfx - format string starting with dash\" '\n+\tprintf -- \"-master\" >expected &&\n+\t__git_ps1 \"-%s\" >\"$actual\" &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+pcmode_expected () {\n+\tcase $ps1expansion in\n+\ton) printf \"$1\" '${__git_ps1_branch_name}' \"$2\";;\n+\toff) printf \"$1\" \"$2\" \"\";;\n+\tesac >expected\n+}\n+\n+pcmode_actual () {\n+\tcase $ps1expansion in\n+\ton) printf %s\\\\n%s \"$PS1\" \"${__git_ps1_branch_name}\";;\n+\toff) printf %s\\\\n \"$PS1\";;\n+\tesac >\"$actual\"\n+}\n+\n+set_ps1expansion () {\n+\tcase $ps1expansion in\n+\ton) ps1_expansion_enable;;\n+\toff) ps1_expansion_disable;;\n+\t*) error \"invalid argument to _run_pcmode_tests: $ps1expansion\";;\n+\tesac\n+}\n+\n+_run_pcmode_tests () {\n+\tps1expansion=$1; shift\n+\n+\t# Test whether the shell supports enabling/disabling PS1\n+\t# expansion by running set_ps1expansion.  If not, quietly skip\n+\t# this set of tests.\n+\t#\n+\t# Even though set_ps1expansion is run here, it must also be\n+\t# run inside each individual test case because the state of\n+\t# the shell might be reset in some fashion before executing\n+\t# the test code.  (Notably, Zsh shell emulation causes the\n+\t# PROMPT_SUBST option to be reset each time a test is run.)\n+\tset_ps1expansion || return 0\n+\n+\ttest_expect_success \"$shellname prompt - pc mode (PS1 expansion $ps1expansion)\" '\n+\t\tset_ps1expansion &&\n+\t\tpcmode_expected \"BEFORE: (%s):AFTER\\\\n%s\" master &&\n+\t\tprintf \"\" >expected_output &&\n+\t\t(\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" >\"$actual\" &&\n+\t\t\ttest_cmp expected_output \"$actual\" &&\n+\t\t\tpcmode_actual\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n+\n+\tpfx=\"$shellname prompt - color pc mode (PS1 expansion $ps1expansion)\"\n+\n+\ttest_expect_success \"$pfx - branch name\" '\n+\t\tset_ps1expansion &&\n+\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear}):AFTER\\\\n%s\" master &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" >\"$actual\"\n+\t\t\tpcmode_actual\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n+\n+\ttest_expect_success \"$pfx - detached head\" '\n+\t\tset_ps1expansion &&\n+\t\tpcmode_expected \"BEFORE: (${c_red}%s${c_clear}):AFTER\\\\n%s\" \"($(git log -1 --format=\"%h\" b1^)...)\" &&\n+\t\tgit checkout b1^ &&\n+\t\ttest_when_finished \"git checkout master\" &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n+\t\t\tpcmode_actual\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n+\n+\ttest_expect_success \"$pfx - dirty status indicator - dirty worktree\" '\n+\t\tset_ps1expansion &&\n+\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_red}*${c_clear}):AFTER\\\\n%s\" master &&\n+\t\techo \"dirty\" >file &&\n+\t\ttest_when_finished \"git reset --hard\" &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n+\t\t\tpcmode_actual\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n+\n+\ttest_expect_success \"$pfx - dirty status indicator - dirty index\" '\n+\t\tset_ps1expansion &&\n+\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_green}+${c_clear}):AFTER\\\\n%s\" master &&\n+\t\techo \"dirty\" >file &&\n+\t\ttest_when_finished \"git reset --hard\" &&\n+\t\tgit add -u &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n+\t\t\tpcmode_actual\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n+\n+\ttest_expect_success \"$pfx - dirty status indicator - dirty index and worktree\" '\n+\t\tset_ps1expansion &&\n+\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_red}*${c_green}+${c_clear}):AFTER\\\\n%s\" master &&\n+\t\techo \"dirty index\" >file &&\n+\t\ttest_when_finished \"git reset --hard\" &&\n+\t\tgit add -u &&\n+\t\techo \"dirty worktree\" >file &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n+\t\t\tpcmode_actual\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n+\n+\ttest_expect_success \"$pfx - dirty status indicator - before root commit\" '\n+\t\tset_ps1expansion &&\n+\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_green}#${c_clear}):AFTER\\\\n%s\" master &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t\tcd otherrepo &&\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n+\t\t\tpcmode_actual\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n+\n+\ttest_expect_success \"$pfx - inside .git directory\" '\n+\t\tset_ps1expansion &&\n+\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear}):AFTER\\\\n%s\" \"GIT_DIR!\" &&\n+\t\techo \"dirty\" >file &&\n+\t\ttest_when_finished \"git reset --hard\" &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t\tcd .git &&\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n+\t\t\tpcmode_actual\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n+\n+\ttest_expect_success \"$pfx - stash status indicator\" '\n+\t\tset_ps1expansion &&\n+\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_lblue}\\$${c_clear}):AFTER\\\\n%s\" master &&\n+\t\techo 2 >file &&\n+\t\tgit stash &&\n+\t\ttest_when_finished \"git stash drop\" &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWSTASHSTATE=y &&\n+\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n+\t\t\tpcmode_actual\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n+\n+\ttest_expect_success \"$pfx - untracked files status indicator\" '\n+\t\tset_ps1expansion &&\n+\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_red}%%${c_clear}):AFTER\\\\n%s\" master &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n+\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n+\t\t\tpcmode_actual\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n+}\n+\n+run_pcmode_tests () {\n+\t_run_pcmode_tests on\n+\t_run_pcmode_tests off\n+}\n+\n+run_pcmode_tests\ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex fe60cf9..b698fe9 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -6,630 +6,6 @@\n test_description='test git-specific bash prompt functions'\n \n . ./lib-bash.sh\n-\n-. \"$GIT_BUILD_DIR/contrib/completion/git-prompt.sh\"\n-\n-actual=\"$TRASH_DIRECTORY/actual\"\n-set_ps1_format_vars\n-\n-test_expect_success \"setup for $shellname prompt tests\" '\n-\tgit init otherrepo &&\n-\techo 1 >file &&\n-\tgit add file &&\n-\ttest_tick &&\n-\tgit commit -m initial &&\n-\tgit tag -a -m msg1 t1 &&\n-\tgit checkout -b b1 &&\n-\techo 2 >file &&\n-\tgit commit -m \"second b1\" file &&\n-\techo 3 >file &&\n-\tgit commit -m \"third b1\" file &&\n-\tgit tag -a -m msg2 t2 &&\n-\tgit checkout -b b2 master &&\n-\techo 0 >file &&\n-\tgit commit -m \"second b2\" file &&\n-\techo 00 >file &&\n-\tgit commit -m \"another b2\" file &&\n-\techo 000 >file &&\n-\tgit commit -m \"yet another b2\" file &&\n-\tgit checkout master\n-'\n-\n-pfx=\"$shellname prompt\"\n-\n-test_expect_success \"$pfx - branch name\" '\n-\tprintf \" (master)\" >expected &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success SYMLINKS \"$pfx - branch name - symlink symref\" '\n-\tprintf \" (master)\" >expected &&\n-\ttest_when_finished \"git checkout master\" &&\n-\ttest_config core.preferSymlinkRefs true &&\n-\tgit checkout master &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - unborn branch\" '\n-\tprintf \" (unborn)\" >expected &&\n-\tgit checkout --orphan unborn &&\n-\ttest_when_finished \"git checkout master\" &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-repo_with_newline='repo\n-with\n-newline'\n-\n-if mkdir \"$repo_with_newline\" 2>/dev/null\n-then\n-\ttest_set_prereq FUNNYNAMES\n-else\n-\tsay 'Your filesystem does not allow newlines in filenames.'\n-fi\n-\n-test_expect_success FUNNYNAMES \"$pfx - with newline in path\" '\n-\tprintf \" (master)\" >expected &&\n-\tgit init \"$repo_with_newline\" &&\n-\ttest_when_finished \"rm -rf \\\"$repo_with_newline\\\"\" &&\n-\tmkdir \"$repo_with_newline\"/subdir &&\n-\t(\n-\t\tcd \"$repo_with_newline/subdir\" &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - detached head\" '\n-\tprintf \" ((%s...))\" $(git log -1 --format=\"%h\" --abbrev=13 b1^) >expected &&\n-\ttest_config core.abbrev 13 &&\n-\tgit checkout b1^ &&\n-\ttest_when_finished \"git checkout master\" &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - describe detached head - contains\" '\n-\tprintf \" ((t2~1))\" >expected &&\n-\tgit checkout b1^ &&\n-\ttest_when_finished \"git checkout master\" &&\n-\t(\n-\t\tGIT_PS1_DESCRIBE_STYLE=contains &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - describe detached head - branch\" '\n-\tprintf \" ((b1~1))\" >expected &&\n-\tgit checkout b1^ &&\n-\ttest_when_finished \"git checkout master\" &&\n-\t(\n-\t\tGIT_PS1_DESCRIBE_STYLE=branch &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - describe detached head - describe\" '\n-\tprintf \" ((t1-1-g%s))\" $(git log -1 --format=\"%h\" b1^) >expected &&\n-\tgit checkout b1^ &&\n-\ttest_when_finished \"git checkout master\" &&\n-\t(\n-\t\tGIT_PS1_DESCRIBE_STYLE=describe &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - describe detached head - default\" '\n-\tprintf \" ((t2))\" >expected &&\n-\tgit checkout --detach b1 &&\n-\ttest_when_finished \"git checkout master\" &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - inside .git directory\" '\n-\tprintf \" (GIT_DIR!)\" >expected &&\n-\t(\n-\t\tcd .git &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - deep inside .git directory\" '\n-\tprintf \" (GIT_DIR!)\" >expected &&\n-\t(\n-\t\tcd .git/refs/heads &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - inside bare repository\" '\n-\tprintf \" (BARE:master)\" >expected &&\n-\tgit init --bare bare.git &&\n-\ttest_when_finished \"rm -rf bare.git\" &&\n-\t(\n-\t\tcd bare.git &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - interactive rebase\" '\n-\tprintf \" (b1|REBASE-i 2/3)\" >expected\n-\twrite_script fake_editor.sh <<-\\EOF &&\n-\t\techo \"exec echo\" >\"$1\"\n-\t\techo \"edit $(git log -1 --format=\"%h\")\" >>\"$1\"\n-\t\techo \"exec echo\" >>\"$1\"\n-\tEOF\n-\ttest_when_finished \"rm -f fake_editor.sh\" &&\n-\ttest_set_editor \"$TRASH_DIRECTORY/fake_editor.sh\" &&\n-\tgit checkout b1 &&\n-\ttest_when_finished \"git checkout master\" &&\n-\tgit rebase -i HEAD^ &&\n-\ttest_when_finished \"git rebase --abort\"\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - rebase merge\" '\n-\tprintf \" (b2|REBASE-m 1/3)\" >expected &&\n-\tgit checkout b2 &&\n-\ttest_when_finished \"git checkout master\" &&\n-\ttest_must_fail git rebase --merge b1 b2 &&\n-\ttest_when_finished \"git rebase --abort\" &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - rebase\" '\n-\tprintf \" (b2|REBASE 1/3)\" >expected &&\n-\tgit checkout b2 &&\n-\ttest_when_finished \"git checkout master\" &&\n-\ttest_must_fail git rebase b1 b2 &&\n-\ttest_when_finished \"git rebase --abort\" &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - merge\" '\n-\tprintf \" (b1|MERGING)\" >expected &&\n-\tgit checkout b1 &&\n-\ttest_when_finished \"git checkout master\" &&\n-\ttest_must_fail git merge b2 &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - cherry-pick\" '\n-\tprintf \" (master|CHERRY-PICKING)\" >expected &&\n-\ttest_must_fail git cherry-pick b1 &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - bisect\" '\n-\tprintf \" (master|BISECTING)\" >expected &&\n-\tgit bisect start &&\n-\ttest_when_finished \"git bisect reset\" &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - dirty status indicator - clean\" '\n-\tprintf \" (master)\" >expected &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - dirty status indicator - dirty worktree\" '\n-\tprintf \" (master *)\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - dirty status indicator - dirty index\" '\n-\tprintf \" (master +)\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\tgit add -u &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - dirty status indicator - dirty index and worktree\" '\n-\tprintf \" (master *+)\" >expected &&\n-\techo \"dirty index\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\tgit add -u &&\n-\techo \"dirty worktree\" >file &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - dirty status indicator - before root commit\" '\n-\tprintf \" (master #)\" >expected &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\tcd otherrepo &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - dirty status indicator - shell variable unset with config disabled\" '\n-\tprintf \" (master)\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\ttest_config bash.showDirtyState false &&\n-\t(\n-\t\tsane_unset GIT_PS1_SHOWDIRTYSTATE &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - dirty status indicator - shell variable unset with config enabled\" '\n-\tprintf \" (master)\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\ttest_config bash.showDirtyState true &&\n-\t(\n-\t\tsane_unset GIT_PS1_SHOWDIRTYSTATE &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - dirty status indicator - shell variable set with config disabled\" '\n-\tprintf \" (master)\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\ttest_config bash.showDirtyState false &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - dirty status indicator - shell variable set with config enabled\" '\n-\tprintf \" (master *)\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\ttest_config bash.showDirtyState true &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - dirty status indicator - not shown inside .git directory\" '\n-\tprintf \" (GIT_DIR!)\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\tcd .git &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - stash status indicator - no stash\" '\n-\tprintf \" (master)\" >expected &&\n-\t(\n-\t\tGIT_PS1_SHOWSTASHSTATE=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - stash status indicator - stash\" '\n-\tprintf \" (master $)\" >expected &&\n-\techo 2 >file &&\n-\tgit stash &&\n-\ttest_when_finished \"git stash drop\" &&\n-\tgit pack-refs --all &&\n-\t(\n-\t\tGIT_PS1_SHOWSTASHSTATE=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - stash status indicator - not shown inside .git directory\" '\n-\tprintf \" (GIT_DIR!)\" >expected &&\n-\techo 2 >file &&\n-\tgit stash &&\n-\ttest_when_finished \"git stash drop\" &&\n-\t(\n-\t\tGIT_PS1_SHOWSTASHSTATE=y &&\n-\t\tcd .git &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - untracked files status indicator - no untracked files\" '\n-\tprintf \" (master)\" >expected &&\n-\t(\n-\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n-\t\tcd otherrepo &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - untracked files status indicator - untracked files\" '\n-\tprintf \" (master %%)\" >expected &&\n-\t(\n-\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - untracked files status indicator - shell variable unset with config disabled\" '\n-\tprintf \" (master)\" >expected &&\n-\ttest_config bash.showUntrackedFiles false &&\n-\t(\n-\t\tsane_unset GIT_PS1_SHOWUNTRACKEDFILES &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - untracked files status indicator - shell variable unset with config enabled\" '\n-\tprintf \" (master)\" >expected &&\n-\ttest_config bash.showUntrackedFiles true &&\n-\t(\n-\t\tsane_unset GIT_PS1_SHOWUNTRACKEDFILES &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - untracked files status indicator - shell variable set with config disabled\" '\n-\tprintf \" (master)\" >expected &&\n-\ttest_config bash.showUntrackedFiles false &&\n-\t(\n-\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - untracked files status indicator - shell variable set with config enabled\" '\n-\tprintf \" (master %%)\" >expected &&\n-\ttest_config bash.showUntrackedFiles true &&\n-\t(\n-\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - untracked files status indicator - not shown inside .git directory\" '\n-\tprintf \" (GIT_DIR!)\" >expected &&\n-\t(\n-\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n-\t\tcd .git &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - format string starting with dash\" '\n-\tprintf -- \"-master\" >expected &&\n-\t__git_ps1 \"-%s\" >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-pcmode_expected () {\n-\tcase $ps1expansion in\n-\ton) printf \"$1\" '${__git_ps1_branch_name}' \"$2\";;\n-\toff) printf \"$1\" \"$2\" \"\";;\n-\tesac >expected\n-}\n-\n-pcmode_actual () {\n-\tcase $ps1expansion in\n-\ton) printf %s\\\\n%s \"$PS1\" \"${__git_ps1_branch_name}\";;\n-\toff) printf %s\\\\n \"$PS1\";;\n-\tesac >\"$actual\"\n-}\n-\n-set_ps1expansion () {\n-\tcase $ps1expansion in\n-\ton) ps1_expansion_enable;;\n-\toff) ps1_expansion_disable;;\n-\t*) error \"invalid argument to _run_pcmode_tests: $ps1expansion\";;\n-\tesac\n-}\n-\n-_run_pcmode_tests () {\n-\tps1expansion=$1; shift\n-\n-\t# Test whether the shell supports enabling/disabling PS1\n-\t# expansion by running set_ps1expansion.  If not, quietly skip\n-\t# this set of tests.\n-\t#\n-\t# Even though set_ps1expansion is run here, it must also be\n-\t# run inside each individual test case because the state of\n-\t# the shell might be reset in some fashion before executing\n-\t# the test code.  (Notably, Zsh shell emulation causes the\n-\t# PROMPT_SUBST option to be reset each time a test is run.)\n-\tset_ps1expansion || return 0\n-\n-\ttest_expect_success \"$shellname prompt - pc mode (PS1 expansion $ps1expansion)\" '\n-\t\tset_ps1expansion &&\n-\t\tpcmode_expected \"BEFORE: (%s):AFTER\\\\n%s\" master &&\n-\t\tprintf \"\" >expected_output &&\n-\t\t(\n-\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" >\"$actual\" &&\n-\t\t\ttest_cmp expected_output \"$actual\" &&\n-\t\t\tpcmode_actual\n-\t\t) &&\n-\t\ttest_cmp expected \"$actual\"\n-\t'\n-\n-\tpfx=\"$shellname prompt - color pc mode (PS1 expansion $ps1expansion)\"\n-\n-\ttest_expect_success \"$pfx - branch name\" '\n-\t\tset_ps1expansion &&\n-\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear}):AFTER\\\\n%s\" master &&\n-\t\t(\n-\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" >\"$actual\"\n-\t\t\tpcmode_actual\n-\t\t) &&\n-\t\ttest_cmp expected \"$actual\"\n-\t'\n-\n-\ttest_expect_success \"$pfx - detached head\" '\n-\t\tset_ps1expansion &&\n-\t\tpcmode_expected \"BEFORE: (${c_red}%s${c_clear}):AFTER\\\\n%s\" \"($(git log -1 --format=\"%h\" b1^)...)\" &&\n-\t\tgit checkout b1^ &&\n-\t\ttest_when_finished \"git checkout master\" &&\n-\t\t(\n-\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\t\tpcmode_actual\n-\t\t) &&\n-\t\ttest_cmp expected \"$actual\"\n-\t'\n-\n-\ttest_expect_success \"$pfx - dirty status indicator - dirty worktree\" '\n-\t\tset_ps1expansion &&\n-\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_red}*${c_clear}):AFTER\\\\n%s\" master &&\n-\t\techo \"dirty\" >file &&\n-\t\ttest_when_finished \"git reset --hard\" &&\n-\t\t(\n-\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\t\tpcmode_actual\n-\t\t) &&\n-\t\ttest_cmp expected \"$actual\"\n-\t'\n-\n-\ttest_expect_success \"$pfx - dirty status indicator - dirty index\" '\n-\t\tset_ps1expansion &&\n-\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_green}+${c_clear}):AFTER\\\\n%s\" master &&\n-\t\techo \"dirty\" >file &&\n-\t\ttest_when_finished \"git reset --hard\" &&\n-\t\tgit add -u &&\n-\t\t(\n-\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\t\tpcmode_actual\n-\t\t) &&\n-\t\ttest_cmp expected \"$actual\"\n-\t'\n-\n-\ttest_expect_success \"$pfx - dirty status indicator - dirty index and worktree\" '\n-\t\tset_ps1expansion &&\n-\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_red}*${c_green}+${c_clear}):AFTER\\\\n%s\" master &&\n-\t\techo \"dirty index\" >file &&\n-\t\ttest_when_finished \"git reset --hard\" &&\n-\t\tgit add -u &&\n-\t\techo \"dirty worktree\" >file &&\n-\t\t(\n-\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\t\tpcmode_actual\n-\t\t) &&\n-\t\ttest_cmp expected \"$actual\"\n-\t'\n-\n-\ttest_expect_success \"$pfx - dirty status indicator - before root commit\" '\n-\t\tset_ps1expansion &&\n-\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_green}#${c_clear}):AFTER\\\\n%s\" master &&\n-\t\t(\n-\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\t\tcd otherrepo &&\n-\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\t\tpcmode_actual\n-\t\t) &&\n-\t\ttest_cmp expected \"$actual\"\n-\t'\n-\n-\ttest_expect_success \"$pfx - inside .git directory\" '\n-\t\tset_ps1expansion &&\n-\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear}):AFTER\\\\n%s\" \"GIT_DIR!\" &&\n-\t\techo \"dirty\" >file &&\n-\t\ttest_when_finished \"git reset --hard\" &&\n-\t\t(\n-\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\t\tcd .git &&\n-\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\t\tpcmode_actual\n-\t\t) &&\n-\t\ttest_cmp expected \"$actual\"\n-\t'\n-\n-\ttest_expect_success \"$pfx - stash status indicator\" '\n-\t\tset_ps1expansion &&\n-\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_lblue}\\$${c_clear}):AFTER\\\\n%s\" master &&\n-\t\techo 2 >file &&\n-\t\tgit stash &&\n-\t\ttest_when_finished \"git stash drop\" &&\n-\t\t(\n-\t\t\tGIT_PS1_SHOWSTASHSTATE=y &&\n-\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\t\tpcmode_actual\n-\t\t) &&\n-\t\ttest_cmp expected \"$actual\"\n-\t'\n-\n-\ttest_expect_success \"$pfx - untracked files status indicator\" '\n-\t\tset_ps1expansion &&\n-\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_red}%%${c_clear}):AFTER\\\\n%s\" master &&\n-\t\t(\n-\t\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n-\t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\t\t__git_ps1 \"BEFORE:\" \":AFTER\" &&\n-\t\t\tpcmode_actual\n-\t\t) &&\n-\t\ttest_cmp expected \"$actual\"\n-\t'\n-}\n-\n-run_pcmode_tests () {\n-\t_run_pcmode_tests on\n-\t_run_pcmode_tests off\n-}\n-\n-run_pcmode_tests\n+. \"$TEST_DIRECTORY\"/lib-prompt-tests.sh\n \n test_done\n-- \n2.0.0\n"},{"id":"243352","messageId":"1401915687-8602-9-git-send-email-rhansen@bbn.com","threadId":"36705","inReplyTo":"1401915687-8602-1-git-send-email-rhansen@bbn.com","subject":"[PATCH v2 08/11] lib-prompt-tests.sh: put all tests inside a function","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2014-06-04T21:01:24Z","receivedAt":"2014-06-04T21:01:24Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"Modify lib-prompt-tests.sh so that it does nothing when sourced except\ndefine a function for running the prompt tests (plus some \"private\"\nhelper functions).\n\nSigned-off-by: Richard Hansen <rhansen@bbn.com>\n---\n t/lib-prompt-tests.sh  | 802 ++++++++++++++++++++++++-------------------------\n t/t9903-bash-prompt.sh |   2 +\n 2 files changed, 403 insertions(+), 401 deletions(-)\n\ndiff --git a/t/lib-prompt-tests.sh b/t/lib-prompt-tests.sh\nindex 7aaeb8e..ba22acc 100644\n--- a/t/lib-prompt-tests.sh\n+++ b/t/lib-prompt-tests.sh\n@@ -17,6 +17,7 @@\n #      these variables are used in the first argument to the printf\n #      command, so they must be escaped appropriately.\n #   4. source this library\n+#   5. invoke the run_prompt_tests function\n \n # sanity checks\n [ -n \"$shellname\" ] || error \"shellname must be set to the name of the shell\"\n@@ -27,448 +28,445 @@ done\n (ps1_expansion_enable || ps1_expansion_disable) \\\n \t|| error \"either ps1_expansion_enable or ps1_expansion_disable must return true\"\n \n-. \"$GIT_BUILD_DIR/contrib/completion/git-prompt.sh\"\n+_run_non_pcmode_tests () {\n+\ttest_expect_success \"setup for $shellname prompt tests\" '\n+\t\tgit init otherrepo &&\n+\t\techo 1 >file &&\n+\t\tgit add file &&\n+\t\ttest_tick &&\n+\t\tgit commit -m initial &&\n+\t\tgit tag -a -m msg1 t1 &&\n+\t\tgit checkout -b b1 &&\n+\t\techo 2 >file &&\n+\t\tgit commit -m \"second b1\" file &&\n+\t\techo 3 >file &&\n+\t\tgit commit -m \"third b1\" file &&\n+\t\tgit tag -a -m msg2 t2 &&\n+\t\tgit checkout -b b2 master &&\n+\t\techo 0 >file &&\n+\t\tgit commit -m \"second b2\" file &&\n+\t\techo 00 >file &&\n+\t\tgit commit -m \"another b2\" file &&\n+\t\techo 000 >file &&\n+\t\tgit commit -m \"yet another b2\" file &&\n+\t\tgit checkout master\n+\t'\n \n-actual=\"$TRASH_DIRECTORY/actual\"\n-set_ps1_format_vars\n+\tpfx=\"$shellname prompt\"\n \n-test_expect_success \"setup for $shellname prompt tests\" '\n-\tgit init otherrepo &&\n-\techo 1 >file &&\n-\tgit add file &&\n-\ttest_tick &&\n-\tgit commit -m initial &&\n-\tgit tag -a -m msg1 t1 &&\n-\tgit checkout -b b1 &&\n-\techo 2 >file &&\n-\tgit commit -m \"second b1\" file &&\n-\techo 3 >file &&\n-\tgit commit -m \"third b1\" file &&\n-\tgit tag -a -m msg2 t2 &&\n-\tgit checkout -b b2 master &&\n-\techo 0 >file &&\n-\tgit commit -m \"second b2\" file &&\n-\techo 00 >file &&\n-\tgit commit -m \"another b2\" file &&\n-\techo 000 >file &&\n-\tgit commit -m \"yet another b2\" file &&\n-\tgit checkout master\n-'\n+\ttest_expect_success \"$pfx - branch name\" '\n+\t\tprintf \" (master)\" >expected &&\n+\t\t__git_ps1 >\"$actual\" &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-pfx=\"$shellname prompt\"\n+\ttest_expect_success SYMLINKS \"$pfx - branch name - symlink symref\" '\n+\t\tprintf \" (master)\" >expected &&\n+\t\ttest_when_finished \"git checkout master\" &&\n+\t\ttest_config core.preferSymlinkRefs true &&\n+\t\tgit checkout master &&\n+\t\t__git_ps1 >\"$actual\" &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - branch name\" '\n-\tprintf \" (master)\" >expected &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - unborn branch\" '\n+\t\tprintf \" (unborn)\" >expected &&\n+\t\tgit checkout --orphan unborn &&\n+\t\ttest_when_finished \"git checkout master\" &&\n+\t\t__git_ps1 >\"$actual\" &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success SYMLINKS \"$pfx - branch name - symlink symref\" '\n-\tprintf \" (master)\" >expected &&\n-\ttest_when_finished \"git checkout master\" &&\n-\ttest_config core.preferSymlinkRefs true &&\n-\tgit checkout master &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success \"$pfx - unborn branch\" '\n-\tprintf \" (unborn)\" >expected &&\n-\tgit checkout --orphan unborn &&\n-\ttest_when_finished \"git checkout master\" &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-repo_with_newline='repo\n+\trepo_with_newline='repo\n with\n newline'\n \n-if mkdir \"$repo_with_newline\" 2>/dev/null\n-then\n-\ttest_set_prereq FUNNYNAMES\n-else\n-\tsay 'Your filesystem does not allow newlines in filenames.'\n-fi\n+\tif mkdir \"$repo_with_newline\" 2>/dev/null\n+\tthen\n+\t\ttest_set_prereq FUNNYNAMES\n+\telse\n+\t\tsay 'Your filesystem does not allow newlines in filenames.'\n+\tfi\n \n-test_expect_success FUNNYNAMES \"$pfx - with newline in path\" '\n-\tprintf \" (master)\" >expected &&\n-\tgit init \"$repo_with_newline\" &&\n-\ttest_when_finished \"rm -rf \\\"$repo_with_newline\\\"\" &&\n-\tmkdir \"$repo_with_newline\"/subdir &&\n-\t(\n-\t\tcd \"$repo_with_newline/subdir\" &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success FUNNYNAMES \"$pfx - with newline in path\" '\n+\t\tprintf \" (master)\" >expected &&\n+\t\tgit init \"$repo_with_newline\" &&\n+\t\ttest_when_finished \"rm -rf \\\"$repo_with_newline\\\"\" &&\n+\t\tmkdir \"$repo_with_newline\"/subdir &&\n+\t\t(\n+\t\t\tcd \"$repo_with_newline/subdir\" &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - detached head\" '\n-\tprintf \" ((%s...))\" $(git log -1 --format=\"%h\" --abbrev=13 b1^) >expected &&\n-\ttest_config core.abbrev 13 &&\n-\tgit checkout b1^ &&\n-\ttest_when_finished \"git checkout master\" &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - detached head\" '\n+\t\tprintf \" ((%s...))\" $(git log -1 --format=\"%h\" --abbrev=13 b1^) >expected &&\n+\t\ttest_config core.abbrev 13 &&\n+\t\tgit checkout b1^ &&\n+\t\ttest_when_finished \"git checkout master\" &&\n+\t\t__git_ps1 >\"$actual\" &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - describe detached head - contains\" '\n-\tprintf \" ((t2~1))\" >expected &&\n-\tgit checkout b1^ &&\n-\ttest_when_finished \"git checkout master\" &&\n-\t(\n-\t\tGIT_PS1_DESCRIBE_STYLE=contains &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - describe detached head - contains\" '\n+\t\tprintf \" ((t2~1))\" >expected &&\n+\t\tgit checkout b1^ &&\n+\t\ttest_when_finished \"git checkout master\" &&\n+\t\t(\n+\t\t\tGIT_PS1_DESCRIBE_STYLE=contains &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - describe detached head - branch\" '\n-\tprintf \" ((b1~1))\" >expected &&\n-\tgit checkout b1^ &&\n-\ttest_when_finished \"git checkout master\" &&\n-\t(\n-\t\tGIT_PS1_DESCRIBE_STYLE=branch &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - describe detached head - branch\" '\n+\t\tprintf \" ((b1~1))\" >expected &&\n+\t\tgit checkout b1^ &&\n+\t\ttest_when_finished \"git checkout master\" &&\n+\t\t(\n+\t\t\tGIT_PS1_DESCRIBE_STYLE=branch &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - describe detached head - describe\" '\n-\tprintf \" ((t1-1-g%s))\" $(git log -1 --format=\"%h\" b1^) >expected &&\n-\tgit checkout b1^ &&\n-\ttest_when_finished \"git checkout master\" &&\n-\t(\n-\t\tGIT_PS1_DESCRIBE_STYLE=describe &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - describe detached head - describe\" '\n+\t\tprintf \" ((t1-1-g%s))\" $(git log -1 --format=\"%h\" b1^) >expected &&\n+\t\tgit checkout b1^ &&\n+\t\ttest_when_finished \"git checkout master\" &&\n+\t\t(\n+\t\t\tGIT_PS1_DESCRIBE_STYLE=describe &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - describe detached head - default\" '\n-\tprintf \" ((t2))\" >expected &&\n-\tgit checkout --detach b1 &&\n-\ttest_when_finished \"git checkout master\" &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - describe detached head - default\" '\n+\t\tprintf \" ((t2))\" >expected &&\n+\t\tgit checkout --detach b1 &&\n+\t\ttest_when_finished \"git checkout master\" &&\n+\t\t__git_ps1 >\"$actual\" &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - inside .git directory\" '\n-\tprintf \" (GIT_DIR!)\" >expected &&\n-\t(\n-\t\tcd .git &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - inside .git directory\" '\n+\t\tprintf \" (GIT_DIR!)\" >expected &&\n+\t\t(\n+\t\t\tcd .git &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - deep inside .git directory\" '\n-\tprintf \" (GIT_DIR!)\" >expected &&\n-\t(\n-\t\tcd .git/refs/heads &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - deep inside .git directory\" '\n+\t\tprintf \" (GIT_DIR!)\" >expected &&\n+\t\t(\n+\t\t\tcd .git/refs/heads &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - inside bare repository\" '\n-\tprintf \" (BARE:master)\" >expected &&\n-\tgit init --bare bare.git &&\n-\ttest_when_finished \"rm -rf bare.git\" &&\n-\t(\n-\t\tcd bare.git &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - inside bare repository\" '\n+\t\tprintf \" (BARE:master)\" >expected &&\n+\t\tgit init --bare bare.git &&\n+\t\ttest_when_finished \"rm -rf bare.git\" &&\n+\t\t(\n+\t\t\tcd bare.git &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - interactive rebase\" '\n-\tprintf \" (b1|REBASE-i 2/3)\" >expected\n-\twrite_script fake_editor.sh <<-\\EOF &&\n-\t\techo \"exec echo\" >\"$1\"\n-\t\techo \"edit $(git log -1 --format=\"%h\")\" >>\"$1\"\n-\t\techo \"exec echo\" >>\"$1\"\n-\tEOF\n-\ttest_when_finished \"rm -f fake_editor.sh\" &&\n-\ttest_set_editor \"$TRASH_DIRECTORY/fake_editor.sh\" &&\n-\tgit checkout b1 &&\n-\ttest_when_finished \"git checkout master\" &&\n-\tgit rebase -i HEAD^ &&\n-\ttest_when_finished \"git rebase --abort\"\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - interactive rebase\" '\n+\t\tprintf \" (b1|REBASE-i 2/3)\" >expected\n+\t\twrite_script fake_editor.sh <<-\\EOF &&\n+\t\t\techo \"exec echo\" >\"$1\"\n+\t\t\techo \"edit $(git log -1 --format=\"%h\")\" >>\"$1\"\n+\t\t\techo \"exec echo\" >>\"$1\"\n+\t\tEOF\n+\t\ttest_when_finished \"rm -f fake_editor.sh\" &&\n+\t\ttest_set_editor \"$TRASH_DIRECTORY/fake_editor.sh\" &&\n+\t\tgit checkout b1 &&\n+\t\ttest_when_finished \"git checkout master\" &&\n+\t\tgit rebase -i HEAD^ &&\n+\t\ttest_when_finished \"git rebase --abort\"\n+\t\t__git_ps1 >\"$actual\" &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - rebase merge\" '\n-\tprintf \" (b2|REBASE-m 1/3)\" >expected &&\n-\tgit checkout b2 &&\n-\ttest_when_finished \"git checkout master\" &&\n-\ttest_must_fail git rebase --merge b1 b2 &&\n-\ttest_when_finished \"git rebase --abort\" &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - rebase merge\" '\n+\t\tprintf \" (b2|REBASE-m 1/3)\" >expected &&\n+\t\tgit checkout b2 &&\n+\t\ttest_when_finished \"git checkout master\" &&\n+\t\ttest_must_fail git rebase --merge b1 b2 &&\n+\t\ttest_when_finished \"git rebase --abort\" &&\n+\t\t__git_ps1 >\"$actual\" &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - rebase\" '\n-\tprintf \" (b2|REBASE 1/3)\" >expected &&\n-\tgit checkout b2 &&\n-\ttest_when_finished \"git checkout master\" &&\n-\ttest_must_fail git rebase b1 b2 &&\n-\ttest_when_finished \"git rebase --abort\" &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - rebase\" '\n+\t\tprintf \" (b2|REBASE 1/3)\" >expected &&\n+\t\tgit checkout b2 &&\n+\t\ttest_when_finished \"git checkout master\" &&\n+\t\ttest_must_fail git rebase b1 b2 &&\n+\t\ttest_when_finished \"git rebase --abort\" &&\n+\t\t__git_ps1 >\"$actual\" &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - merge\" '\n-\tprintf \" (b1|MERGING)\" >expected &&\n-\tgit checkout b1 &&\n-\ttest_when_finished \"git checkout master\" &&\n-\ttest_must_fail git merge b2 &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - merge\" '\n+\t\tprintf \" (b1|MERGING)\" >expected &&\n+\t\tgit checkout b1 &&\n+\t\ttest_when_finished \"git checkout master\" &&\n+\t\ttest_must_fail git merge b2 &&\n+\t\ttest_when_finished \"git reset --hard\" &&\n+\t\t__git_ps1 >\"$actual\" &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - cherry-pick\" '\n-\tprintf \" (master|CHERRY-PICKING)\" >expected &&\n-\ttest_must_fail git cherry-pick b1 &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - cherry-pick\" '\n+\t\tprintf \" (master|CHERRY-PICKING)\" >expected &&\n+\t\ttest_must_fail git cherry-pick b1 &&\n+\t\ttest_when_finished \"git reset --hard\" &&\n+\t\t__git_ps1 >\"$actual\" &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - bisect\" '\n-\tprintf \" (master|BISECTING)\" >expected &&\n-\tgit bisect start &&\n-\ttest_when_finished \"git bisect reset\" &&\n-\t__git_ps1 >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - bisect\" '\n+\t\tprintf \" (master|BISECTING)\" >expected &&\n+\t\tgit bisect start &&\n+\t\ttest_when_finished \"git bisect reset\" &&\n+\t\t__git_ps1 >\"$actual\" &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - dirty status indicator - clean\" '\n-\tprintf \" (master)\" >expected &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - dirty status indicator - clean\" '\n+\t\tprintf \" (master)\" >expected &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - dirty status indicator - dirty worktree\" '\n-\tprintf \" (master *)\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - dirty status indicator - dirty worktree\" '\n+\t\tprintf \" (master *)\" >expected &&\n+\t\techo \"dirty\" >file &&\n+\t\ttest_when_finished \"git reset --hard\" &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - dirty status indicator - dirty index\" '\n-\tprintf \" (master +)\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\tgit add -u &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - dirty status indicator - dirty index\" '\n+\t\tprintf \" (master +)\" >expected &&\n+\t\techo \"dirty\" >file &&\n+\t\ttest_when_finished \"git reset --hard\" &&\n+\t\tgit add -u &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - dirty status indicator - dirty index and worktree\" '\n-\tprintf \" (master *+)\" >expected &&\n-\techo \"dirty index\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\tgit add -u &&\n-\techo \"dirty worktree\" >file &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - dirty status indicator - dirty index and worktree\" '\n+\t\tprintf \" (master *+)\" >expected &&\n+\t\techo \"dirty index\" >file &&\n+\t\ttest_when_finished \"git reset --hard\" &&\n+\t\tgit add -u &&\n+\t\techo \"dirty worktree\" >file &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - dirty status indicator - before root commit\" '\n-\tprintf \" (master #)\" >expected &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\tcd otherrepo &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - dirty status indicator - before root commit\" '\n+\t\tprintf \" (master #)\" >expected &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t\tcd otherrepo &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - dirty status indicator - shell variable unset with config disabled\" '\n-\tprintf \" (master)\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\ttest_config bash.showDirtyState false &&\n-\t(\n-\t\tsane_unset GIT_PS1_SHOWDIRTYSTATE &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - dirty status indicator - shell variable unset with config disabled\" '\n+\t\tprintf \" (master)\" >expected &&\n+\t\techo \"dirty\" >file &&\n+\t\ttest_when_finished \"git reset --hard\" &&\n+\t\ttest_config bash.showDirtyState false &&\n+\t\t(\n+\t\t\tsane_unset GIT_PS1_SHOWDIRTYSTATE &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - dirty status indicator - shell variable unset with config enabled\" '\n-\tprintf \" (master)\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\ttest_config bash.showDirtyState true &&\n-\t(\n-\t\tsane_unset GIT_PS1_SHOWDIRTYSTATE &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - dirty status indicator - shell variable unset with config enabled\" '\n+\t\tprintf \" (master)\" >expected &&\n+\t\techo \"dirty\" >file &&\n+\t\ttest_when_finished \"git reset --hard\" &&\n+\t\ttest_config bash.showDirtyState true &&\n+\t\t(\n+\t\t\tsane_unset GIT_PS1_SHOWDIRTYSTATE &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - dirty status indicator - shell variable set with config disabled\" '\n-\tprintf \" (master)\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\ttest_config bash.showDirtyState false &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - dirty status indicator - shell variable set with config disabled\" '\n+\t\tprintf \" (master)\" >expected &&\n+\t\techo \"dirty\" >file &&\n+\t\ttest_when_finished \"git reset --hard\" &&\n+\t\ttest_config bash.showDirtyState false &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - dirty status indicator - shell variable set with config enabled\" '\n-\tprintf \" (master *)\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\ttest_config bash.showDirtyState true &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - dirty status indicator - shell variable set with config enabled\" '\n+\t\tprintf \" (master *)\" >expected &&\n+\t\techo \"dirty\" >file &&\n+\t\ttest_when_finished \"git reset --hard\" &&\n+\t\ttest_config bash.showDirtyState true &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - dirty status indicator - not shown inside .git directory\" '\n-\tprintf \" (GIT_DIR!)\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\t(\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n-\t\tcd .git &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - dirty status indicator - not shown inside .git directory\" '\n+\t\tprintf \" (GIT_DIR!)\" >expected &&\n+\t\techo \"dirty\" >file &&\n+\t\ttest_when_finished \"git reset --hard\" &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\n+\t\t\tcd .git &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - stash status indicator - no stash\" '\n-\tprintf \" (master)\" >expected &&\n-\t(\n-\t\tGIT_PS1_SHOWSTASHSTATE=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - stash status indicator - no stash\" '\n+\t\tprintf \" (master)\" >expected &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWSTASHSTATE=y &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - stash status indicator - stash\" '\n-\tprintf \" (master $)\" >expected &&\n-\techo 2 >file &&\n-\tgit stash &&\n-\ttest_when_finished \"git stash drop\" &&\n-\tgit pack-refs --all &&\n-\t(\n-\t\tGIT_PS1_SHOWSTASHSTATE=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - stash status indicator - stash\" '\n+\t\tprintf \" (master $)\" >expected &&\n+\t\techo 2 >file &&\n+\t\tgit stash &&\n+\t\ttest_when_finished \"git stash drop\" &&\n+\t\tgit pack-refs --all &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWSTASHSTATE=y &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - stash status indicator - not shown inside .git directory\" '\n-\tprintf \" (GIT_DIR!)\" >expected &&\n-\techo 2 >file &&\n-\tgit stash &&\n-\ttest_when_finished \"git stash drop\" &&\n-\t(\n-\t\tGIT_PS1_SHOWSTASHSTATE=y &&\n-\t\tcd .git &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - stash status indicator - not shown inside .git directory\" '\n+\t\tprintf \" (GIT_DIR!)\" >expected &&\n+\t\techo 2 >file &&\n+\t\tgit stash &&\n+\t\ttest_when_finished \"git stash drop\" &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWSTASHSTATE=y &&\n+\t\t\tcd .git &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - untracked files status indicator - no untracked files\" '\n-\tprintf \" (master)\" >expected &&\n-\t(\n-\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n-\t\tcd otherrepo &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - untracked files status indicator - no untracked files\" '\n+\t\tprintf \" (master)\" >expected &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n+\t\t\tcd otherrepo &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - untracked files status indicator - untracked files\" '\n-\tprintf \" (master %%)\" >expected &&\n-\t(\n-\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - untracked files status indicator - untracked files\" '\n+\t\tprintf \" (master %%)\" >expected &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - untracked files status indicator - shell variable unset with config disabled\" '\n-\tprintf \" (master)\" >expected &&\n-\ttest_config bash.showUntrackedFiles false &&\n-\t(\n-\t\tsane_unset GIT_PS1_SHOWUNTRACKEDFILES &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - untracked files status indicator - shell variable unset with config disabled\" '\n+\t\tprintf \" (master)\" >expected &&\n+\t\ttest_config bash.showUntrackedFiles false &&\n+\t\t(\n+\t\t\tsane_unset GIT_PS1_SHOWUNTRACKEDFILES &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - untracked files status indicator - shell variable unset with config enabled\" '\n-\tprintf \" (master)\" >expected &&\n-\ttest_config bash.showUntrackedFiles true &&\n-\t(\n-\t\tsane_unset GIT_PS1_SHOWUNTRACKEDFILES &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - untracked files status indicator - shell variable unset with config enabled\" '\n+\t\tprintf \" (master)\" >expected &&\n+\t\ttest_config bash.showUntrackedFiles true &&\n+\t\t(\n+\t\t\tsane_unset GIT_PS1_SHOWUNTRACKEDFILES &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - untracked files status indicator - shell variable set with config disabled\" '\n-\tprintf \" (master)\" >expected &&\n-\ttest_config bash.showUntrackedFiles false &&\n-\t(\n-\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - untracked files status indicator - shell variable set with config disabled\" '\n+\t\tprintf \" (master)\" >expected &&\n+\t\ttest_config bash.showUntrackedFiles false &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - untracked files status indicator - shell variable set with config enabled\" '\n-\tprintf \" (master %%)\" >expected &&\n-\ttest_config bash.showUntrackedFiles true &&\n-\t(\n-\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - untracked files status indicator - shell variable set with config enabled\" '\n+\t\tprintf \" (master %%)\" >expected &&\n+\t\ttest_config bash.showUntrackedFiles true &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - untracked files status indicator - not shown inside .git directory\" '\n-\tprintf \" (GIT_DIR!)\" >expected &&\n-\t(\n-\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n-\t\tcd .git &&\n-\t\t__git_ps1 >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - untracked files status indicator - not shown inside .git directory\" '\n+\t\tprintf \" (GIT_DIR!)\" >expected &&\n+\t\t(\n+\t\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n+\t\t\tcd .git &&\n+\t\t\t__git_ps1 >\"$actual\"\n+\t\t) &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n \n-test_expect_success \"$pfx - format string starting with dash\" '\n-\tprintf -- \"-master\" >expected &&\n-\t__git_ps1 \"-%s\" >\"$actual\" &&\n-\ttest_cmp expected \"$actual\"\n-'\n+\ttest_expect_success \"$pfx - format string starting with dash\" '\n+\t\tprintf -- \"-master\" >expected &&\n+\t\t__git_ps1 \"-%s\" >\"$actual\" &&\n+\t\ttest_cmp expected \"$actual\"\n+\t'\n+}\n \n pcmode_expected () {\n \tcase $ps1expansion in\n@@ -645,9 +643,11 @@ _run_pcmode_tests () {\n \t'\n }\n \n-run_pcmode_tests () {\n+run_prompt_tests () {\n+\t. \"$GIT_BUILD_DIR/contrib/completion/git-prompt.sh\"\n+\tactual=\"$TRASH_DIRECTORY/actual\"\n+\tset_ps1_format_vars\n+\t_run_non_pcmode_tests\n \t_run_pcmode_tests on\n \t_run_pcmode_tests off\n }\n-\n-run_pcmode_tests\ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex b698fe9..858f0cd 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -8,4 +8,6 @@ test_description='test git-specific bash prompt functions'\n . ./lib-bash.sh\n . \"$TEST_DIRECTORY\"/lib-prompt-tests.sh\n \n+run_prompt_tests\n+\n test_done\n-- \n2.0.0\n"},{"id":"243353","messageId":"1401915687-8602-10-git-send-email-rhansen@bbn.com","threadId":"36705","inReplyTo":"1401915687-8602-1-git-send-email-rhansen@bbn.com","subject":"[PATCH v2 09/11] lib-prompt-tests.sh: add variable for string that encodes percent in PS1","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2014-06-04T21:01:25Z","receivedAt":"2014-06-04T21:01:25Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"To add a literal percent character to a Zsh prompt, the string \"%%\" is\nused in PS1.  Bash and POSIX shells simply use \"%\".  To accommodate\nthis difference, use ${percent} where a percent character is expected\nand define the percent variable in the set_ps1_format_vars function.\n\nSigned-off-by: Richard Hansen <rhansen@bbn.com>\n---\n t/lib-bash.sh         |  1 +\n t/lib-prompt-tests.sh | 15 ++++++++-------\n 2 files changed, 9 insertions(+), 7 deletions(-)\n\ndiff --git a/t/lib-bash.sh b/t/lib-bash.sh\nindex 9d428bd..8a030ac 100644\n--- a/t/lib-bash.sh\n+++ b/t/lib-bash.sh\n@@ -19,6 +19,7 @@ shellname=Bash\n ps1_expansion_enable () { shopt -s promptvars; }\n ps1_expansion_disable () { shopt -u promptvars; }\n set_ps1_format_vars () {\n+\tpercent='%%'\n \tc_red='\\\\[\\\\e[31m\\\\]'\n \tc_green='\\\\[\\\\e[32m\\\\]'\n \tc_lblue='\\\\[\\\\e[1;34m\\\\]'\ndiff --git a/t/lib-prompt-tests.sh b/t/lib-prompt-tests.sh\nindex ba22acc..c6226b1 100644\n--- a/t/lib-prompt-tests.sh\n+++ b/t/lib-prompt-tests.sh\n@@ -12,10 +12,11 @@\n #      (non-zero) and ps1_expansion_disable should simply return\n #      non-zero (0)\n #   3. define a function named set_ps1_format_vars that sets the\n-#      variables c_red, c_green, c_lblue, and c_clear to the strings\n-#      that __git_ps1 uses to add color to the prompt.  The values of\n-#      these variables are used in the first argument to the printf\n-#      command, so they must be escaped appropriately.\n+#      variables percent, c_red, c_green, c_lblue, and c_clear to the\n+#      strings that __git_ps1 uses to add percent characters and color\n+#      to the prompt.  The values of these variables are used in the\n+#      first argument to the printf command, so they must be escaped\n+#      appropriately.\n #   4. source this library\n #   5. invoke the run_prompt_tests function\n \n@@ -403,7 +404,7 @@ newline'\n \t'\n \n \ttest_expect_success \"$pfx - untracked files status indicator - untracked files\" '\n-\t\tprintf \" (master %%)\" >expected &&\n+\t\tprintf \" (master ${percent})\" >expected &&\n \t\t(\n \t\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n \t\t\t__git_ps1 >\"$actual\"\n@@ -442,7 +443,7 @@ newline'\n \t'\n \n \ttest_expect_success \"$pfx - untracked files status indicator - shell variable set with config enabled\" '\n-\t\tprintf \" (master %%)\" >expected &&\n+\t\tprintf \" (master ${percent})\" >expected &&\n \t\ttest_config bash.showUntrackedFiles true &&\n \t\t(\n \t\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n@@ -632,7 +633,7 @@ _run_pcmode_tests () {\n \n \ttest_expect_success \"$pfx - untracked files status indicator\" '\n \t\tset_ps1expansion &&\n-\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_red}%%${c_clear}):AFTER\\\\n%s\" master &&\n+\t\tpcmode_expected \"BEFORE: (${c_green}%s${c_clear} ${c_red}${percent}${c_clear}):AFTER\\\\n%s\" master &&\n \t\t(\n \t\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\n \t\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-- \n2.0.0\n"},{"id":"243351","messageId":"1401915687-8602-11-git-send-email-rhansen@bbn.com","threadId":"36705","inReplyTo":"1401915687-8602-1-git-send-email-rhansen@bbn.com","subject":"[PATCH v2 10/11] test-lib: make it possible to override how test code is eval'd","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2014-06-04T21:01:26Z","receivedAt":"2014-06-04T21:01:26Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"If a command named 'test_eval_override' exists, use it instead of\n'eval' to run the test code.\n\nThis is needed to support zsh test cases:  test-lib.sh must be sourced\nin sh emulation mode due to fundamental incompatibilities between the\nPOSIX sh language and the zsh language.  When a function is defined\nwhile zsh is emulating some shell, zsh notes the shell that is being\nemulated and records it along with the function definition.  This\nenables zsh to temporarily re-enable the shell emulation mode whenever\nthe function is called, allowing zsh scripts to mix and match code\nwritten for different shell languages.  (This description of zsh shell\nemulation is not completely accurate, but it's close enough.)\n\nBecause test_eval_ is defined while zsh is in sh emulation mode, the\nshell code passed as an argument to test_expect_success would normally\nbe evaluated in sh emulation mode.  However, with this change, it is\nnow possible to evaluate the test code in zsh mode by adding the\nfollowing line to a zsh-based test script:\n\n    emulate -R zsh -c 'test_eval_override () { eval \"$*\"; }'\n\nWith test_eval_override defined in zsh emulation mode, the call to\ntest_eval_override from test_eval_ will temporarily cause zsh to\nswitch from sh emulation mode to zsh emulation mode.\n\nSigned-off-by: Richard Hansen <rhansen@bbn.com>\n---\n t/test-lib.sh | 7 ++++++-\n 1 file changed, 6 insertions(+), 1 deletion(-)\n\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex c081668..3779634 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -414,7 +414,12 @@ maybe_setup_valgrind () {\n test_eval_ () {\n \t# This is a separate function because some tests use\n \t# \"return\" to end a test_expect_success block early.\n-\teval </dev/null >&3 2>&4 \"$*\"\n+\tif command -v test_eval_override >/dev/null 2>&1\n+\tthen\n+\t\ttest_eval_override \"$*\"\n+\telse\n+\t\teval \"$*\"\n+\tfi </dev/null >&3 2>&4\n }\n \n test_run_ () {\n-- \n2.0.0\n"},{"id":"243350","messageId":"1401915687-8602-12-git-send-email-rhansen@bbn.com","threadId":"36705","inReplyTo":"1401915687-8602-1-git-send-email-rhansen@bbn.com","subject":"[PATCH v2 11/11] t9904: new __git_ps1 tests for Zsh","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2014-06-04T21:01:27Z","receivedAt":"2014-06-04T21:01:27Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"These are the same tests as in t9903, but run in zsh instead of bash.\n\nSigned-off-by: Richard Hansen <rhansen@bbn.com>\n---\n t/lib-zsh.sh          | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++\n t/t9904-zsh-prompt.sh | 10 ++++++++++\n 2 files changed, 62 insertions(+)\n create mode 100644 t/lib-zsh.sh\n create mode 100755 t/t9904-zsh-prompt.sh\n\ndiff --git a/t/lib-zsh.sh b/t/lib-zsh.sh\nnew file mode 100644\nindex 0000000..1fd69fd\n--- /dev/null\n+++ b/t/lib-zsh.sh\n@@ -0,0 +1,52 @@\n+# Shell library sourced instead of ./test-lib.sh by tests that need to\n+# run under Zsh; primarily intended for tests of the git-prompt.sh\n+# script.\n+\n+if test -n \"$ZSH_VERSION\" && test -z \"$POSIXLY_CORRECT\" && [[ ! -o FUNCTION_ARGZERO ]]; then\n+\ttrue\n+elif command -v zsh >/dev/null 2>&1; then\n+\tunset POSIXLY_CORRECT\n+\t# Run Zsh with the FUNCTION_ARGZERO option disabled so that\n+\t# test-lib.sh sees the test script pathname when it examines\n+\t# $0 instead of \"./lib-zsh.sh\".  (This works around a Zsh\n+\t# limitation: 'emulate sh -c' does not restore $0 to the value\n+\t# specified by POSIX.)\n+\texec zsh +o FUNCTION_ARGZERO \"$0\" \"$@\"\n+else\n+\techo '1..0 #SKIP skipping Zsh-specific tests; zsh not available'\n+\texit 0\n+fi\n+\n+# ensure that we are in full-on Zsh mode.  note: this re-enables the\n+# FUNCTION_ARGZERO option\n+emulate -R zsh || exit 1\n+\n+shellname=Zsh\n+\n+ps1_expansion_enable () { setopt PROMPT_SUBST; }\n+ps1_expansion_disable () { unsetopt PROMPT_SUBST; }\n+set_ps1_format_vars () {\n+\tpercent='%%%%'\n+\tc_red='%%F{red}'\n+\tc_green='%%F{green}'\n+\tc_lblue='%%F{blue}'\n+\tc_clear='%%f'\n+}\n+\n+# Due to language incompatibilities between POSIX sh and Zsh,\n+# test-lib.sh must be sourced in sh emulation mode.\n+#\n+# Note: Although the FUNCTION_ARGZERO option is currently enabled, sh\n+# emulation mode temporarily turns it off ($0 is left alone when\n+# sourcing test-lib.sh)\n+emulate -R sh -c '. ./test-lib.sh'\n+\n+# Ensure that the test code is run in Zsh mode.  Because test_eval_()\n+# was defined by test-lib.sh inside the above 'emulate sh -c', the Zsh\n+# shell options that implement sh emulation will be temporarily\n+# toggled when test_eval_() executes.  Normally this would cause the\n+# test code to run in sh emulation mode, not Zsh mode.  By defining\n+# test_eval_override() in zsh emulation mode, the options are\n+# temporarily toggled back to the Zsh defaults when evaluating the\n+# test code.\n+emulate -R zsh -c 'test_eval_override () { eval \"$*\"; }'\ndiff --git a/t/t9904-zsh-prompt.sh b/t/t9904-zsh-prompt.sh\nnew file mode 100755\nindex 0000000..a38a3fd\n--- /dev/null\n+++ b/t/t9904-zsh-prompt.sh\n@@ -0,0 +1,10 @@\n+#!/bin/sh\n+\n+test_description='test git-specific Zsh prompt functions'\n+\n+. ./lib-zsh.sh\n+. \"$TEST_DIRECTORY\"/lib-prompt-tests.sh\n+\n+run_prompt_tests\n+\n+test_done\n-- \n2.0.0\n"},{"id":"243419","messageId":"xmqqk38vrrig.fsf@gitster.dls.corp.google.com","threadId":"36705","inReplyTo":"1401915687-8602-11-git-send-email-rhansen@bbn.com","subject":"Re: [PATCH v2 10/11] test-lib: make it possible to override how test code is eval'd","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-06-05T21:11:19Z","receivedAt":"2014-06-05T21:11:19Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Richard Hansen <rhansen@bbn.com> writes:\n\n> Because test_eval_ is defined while zsh is in sh emulation mode, the\n> shell code passed as an argument to test_expect_success would normally\n> be evaluated in sh emulation mode.  However, with this change, it is\n> now possible to evaluate the test code in zsh mode by adding the\n> following line to a zsh-based test script:\n>\n>     emulate -R zsh -c 'test_eval_override () { eval \"$*\"; }'\n>\n> With test_eval_override defined in zsh emulation mode, the call to\n> test_eval_override from test_eval_ will temporarily cause zsh to\n> switch from sh emulation mode to zsh emulation mode.\n\nMicronit: aren't all \"zsh emulation mode\"s above \"zsh native mode\"s?\n\nIn any case, the above explanation confuses me somewhat.  test_eval_\nis fed a scriptlet defined for various test_expect_success tests,\nand they are written in POSIX shells, not zsh, so wouldn't it be\nwrong to run them as if they are zsh native scripts, following\nnon-POSIX shell syntax rules?\n\nPuzzled...\n\n> Signed-off-by: Richard Hansen <rhansen@bbn.com>\n> ---\n>  t/test-lib.sh | 7 ++++++-\n>  1 file changed, 6 insertions(+), 1 deletion(-)\n>\n> diff --git a/t/test-lib.sh b/t/test-lib.sh\n> index c081668..3779634 100644\n> --- a/t/test-lib.sh\n> +++ b/t/test-lib.sh\n> @@ -414,7 +414,12 @@ maybe_setup_valgrind () {\n>  test_eval_ () {\n>  \t# This is a separate function because some tests use\n>  \t# \"return\" to end a test_expect_success block early.\n> -\teval </dev/null >&3 2>&4 \"$*\"\n> +\tif command -v test_eval_override >/dev/null 2>&1\n> +\tthen\n> +\t\ttest_eval_override \"$*\"\n> +\telse\n> +\t\teval \"$*\"\n> +\tfi </dev/null >&3 2>&4\n>  }\n>  \n>  test_run_ () {\n"},{"id":"243441","messageId":"53911297.9030106@bbn.com","threadId":"36705","inReplyTo":"xmqqk38vrrig.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH v2 10/11] test-lib: make it possible to override how test code is eval'd","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2014-06-06T01:00:07Z","receivedAt":"2014-06-06T01:00:07Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"On 2014-06-05 17:11, Junio C Hamano wrote:\n> Richard Hansen <rhansen@bbn.com> writes:\n> \n>> Because test_eval_ is defined while zsh is in sh emulation mode, the\n>> shell code passed as an argument to test_expect_success would normally\n>> be evaluated in sh emulation mode.  However, with this change, it is\n>> now possible to evaluate the test code in zsh mode by adding the\n>> following line to a zsh-based test script:\n>>\n>>     emulate -R zsh -c 'test_eval_override () { eval \"$*\"; }'\n>>\n>> With test_eval_override defined in zsh emulation mode, the call to\n>> test_eval_override from test_eval_ will temporarily cause zsh to\n>> switch from sh emulation mode to zsh emulation mode.\n> \n> Micronit: aren't all \"zsh emulation mode\"s above \"zsh native mode\"s?\n\nSort of...  Zsh's emulation is under-documented, confusing, and\nawkwardly implemented (in my opinion) so it's hard to precisely describe\nwhat's going on in a few words.\n\nI'll explain it here more precisely (apologies for the length) and you\ncan let me know if I should add more detail to the commit message and/or\ncode comments:\n\nAs far as I understand it, there isn't really such a thing as an\n\"emulation mode\" in Zsh -- the phrase \"emulation mode\" is just a\nconvenient way to refer to the mechanism.  Zsh \"emulates\" other shells\nby simply toggling a particular collection of shell options.  For\nexample, 'emulate sh' turns on the option that controls field splitting\nand turns off the option that updates $0 whenever a function is called\n(among other option changes).\n\nOne might expect 'emulate <shell> -c <code>' to be equivalent to\n'emulate <shell>; <code>; emulate <previous_shell>' but it's not --\nthere's a significant behavior difference.  When '-c <code>' is used,\nand only when '-c <code>' is used, a function defined inside <code> gets\n\"sticky options\":  The shell remembers the state of some (all?) options\nand saves them along with the function definition.  Whenever the\nfunction is called, those sticky options are temporarily restored for\nthe duration of the function call.  (This is not entirely accurate --\nthere are some relatively unimportant cases where the sticky options\naren't restored -- but I don't understand the subtleties of the\nmechanism well enough to provide a perfectly accurate description.)\n\nIf a function with sticky options calls a function without sticky\noptions, the sticky options remain in effect -- Zsh doesn't temporarily\nrevert the sticky options while it calls the non-sticky function.\n\nThus, if a function foo() is declared inside 'emulate sh -c <code>', and\nit calls a function bar() that was declared outside of 'emulate', the\noptions are still set for POSIX sh during bar()'s execution.  This might\ncause bar() to misbehave.  To work around this, bar() must be declared\nlike 'emulate zsh -c \"bar() { stuff... }\"' so that bar() gets its own\nsticky options.\n\nThis commit makes it possible to declare a function that will get sticky\noptions so that we can control the state of the shell when the scriptlet\nis executed.\n\n> \n> In any case, the above explanation confuses me somewhat.  test_eval_\n> is fed a scriptlet defined for various test_expect_success tests,\n> and they are written in POSIX shells, not zsh, so wouldn't it be\n> wrong to run them as if they are zsh native scripts, following\n> non-POSIX shell syntax rules?\n\nThe scriptlets in lib-prompt-tests.sh are not actually written for POSIX\nsh -- they are written in a common subset of the zsh and bash languages\n(I should document this in lib-prompt-tests.sh).\n\nWe want to test how the __git_ps1 code behaves when interpreted in\n\"native\" zsh mode (default options), because that's how it will be used\nin the wild, so the scriptlets must be valid zsh code.  We also want to\ntest how __git_ps1 behaves in native bash mode, so the scriptlets must\nalso be valid bash code.  (Fortunately the similarities between the\nshells make this easy to do.)\n\nAn alternative to this commit -- and I kinda like this idea so I'm\ntempted to rewrite the series -- would be to do change the form of the\ntests in lib-prompt-tests.sh to something like this:\n\n    test_expect_success 'name of test here' '\n        run_in_native_shell_mode '\\''\n            scriptlet code here\n        '\\''\n    '\n\nThen lib-zsh.sh would do this:\n\n    run_in_native_shell_mode () { emulate -R zsh -c \"$*\"; }\n\nand lib-bash.sh would do this:\n\n    run_in_native_shell_mode () { eval \"$*\"; }\n\nThis approach makes it clear to others that the scriptlet code is not\nactually POSIX shell code, but a common subset of multiple shell languages.\n\nWhat do you think?\n\nIgnoring t9902 for a moment, we could even stop doing that messy 'exec\n$SHELL \"$0\" \"$@\"' stuff in lib-*sh.sh and let t9903 and t9904 run under\n/bin/sh.  Then run_in_native_shell_mode() would be defined as follows:\n\n  for zsh:\n\n    # wrap the scriptlet in a function in case it does 'return'\n    run_in_native_shell_mode () { zsh -c \"foo () { $*; }; foo\"; }\n\n  for bash:\n\n    # wrap the scriptlet in a function in case it does 'return'\n    run_in_native_shell_mode () { bash -c \"foo () { $*; }; foo\"; }\n\nRunning the scriptlets in a separate process like this would cause its\nown mess -- the separate processes wouldn't be able to use those\nconvenience shell functions I added (pcmode_expected(), etc.), so either\nthere'd be a lot of code copy+paste or each scriptlet would have to\nsource a helper library.\n\n-Richard\n\n> \n> Puzzled...\n> \n>> Signed-off-by: Richard Hansen <rhansen@bbn.com>\n>> ---\n>>  t/test-lib.sh | 7 ++++++-\n>>  1 file changed, 6 insertions(+), 1 deletion(-)\n>>\n>> diff --git a/t/test-lib.sh b/t/test-lib.sh\n>> index c081668..3779634 100644\n>> --- a/t/test-lib.sh\n>> +++ b/t/test-lib.sh\n>> @@ -414,7 +414,12 @@ maybe_setup_valgrind () {\n>>  test_eval_ () {\n>>  \t# This is a separate function because some tests use\n>>  \t# \"return\" to end a test_expect_success block early.\n>> -\teval </dev/null >&3 2>&4 \"$*\"\n>> +\tif command -v test_eval_override >/dev/null 2>&1\n>> +\tthen\n>> +\t\ttest_eval_override \"$*\"\n>> +\telse\n>> +\t\teval \"$*\"\n>> +\tfi </dev/null >&3 2>&4\n>>  }\n>>  \n>>  test_run_ () {\n"},{"id":"243502","messageId":"xmqqiooeq8sf.fsf@gitster.dls.corp.google.com","threadId":"36705","inReplyTo":"53911297.9030106@bbn.com","subject":"Re: [PATCH v2 10/11] test-lib: make it possible to override how test code is eval'd","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-06-06T16:53:20Z","receivedAt":"2014-06-06T16:53:20Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Richard Hansen <rhansen@bbn.com> writes:\n\n> On 2014-06-05 17:11, Junio C Hamano wrote:\n> ...\n>> In any case, the above explanation confuses me somewhat.  test_eval_\n>> is fed a scriptlet defined for various test_expect_success tests,\n>> and they are written in POSIX shells, not zsh, so wouldn't it be\n>> wrong to run them as if they are zsh native scripts, following\n>> non-POSIX shell syntax rules?\n>\n> The scriptlets in lib-prompt-tests.sh are not actually written for POSIX\n> sh -- they are written in a common subset of the zsh and bash languages\n> (I should document this in lib-prompt-tests.sh).\n>\n> We want to test how the __git_ps1 code behaves when interpreted in\n> \"native\" zsh mode (default options), because that's how it will be used\n> in the wild, so the scriptlets must be valid zsh code.  We also want to\n> test how __git_ps1 behaves in native bash mode, so the scriptlets must\n> also be valid bash code.  (Fortunately the similarities between the\n> shells make this easy to do.)\n\nOK.  The above all makes sense, but I think we would prefer a\nsolution with changes limited to lib-prompt-tests and lib-zsh\nwithout touching lib-test-functions at all if that is the case.\n\n> An alternative to this commit -- and I kinda like this idea so I'm\n> tempted to rewrite the series -- would be to do change the form of the\n> tests in lib-prompt-tests.sh to something like this:\n>\n>     test_expect_success 'name of test here' '\n>         run_in_native_shell_mode '\\''\n>             scriptlet code here\n>         '\\''\n>     '\n\nYeah, or even:\n\n\tprompt_test_expect success 'name of test' '\n        \tscriptlet code here\n\t'\n\nwith a helper prompt_test_expect that wraps whatever logic you will\nhave in run-in-native-shell-mode.\n\n> ...\n> This approach makes it clear to others that the scriptlet code is not\n> actually POSIX shell code, but a common subset of multiple shell languages.\n>\n> What do you think?\n\n;-)\n\n> Ignoring t9902 for a moment, we could even stop doing that messy 'exec\n> $SHELL \"$0\" \"$@\"' stuff in lib-*sh.sh and let t9903 and t9904 run under\n> /bin/sh.  Then run_in_native_shell_mode() would be defined as follows:\n\nNo, let's not go there (and you stated the reason why we do not want\nto yourself already ;-).\n"},{"id":"243762","messageId":"53976563.5020905@web.de","threadId":"36705","inReplyTo":"1401915687-8602-1-git-send-email-rhansen@bbn.com","subject":"Re: [PATCH v2 00/11] Zsh prompt tests","fromName":"Torsten Bögershausen","fromEmail":"tboegi@web.de","sentAt":"2014-06-10T20:06:59Z","receivedAt":"2014-06-10T20:06:59Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"On 2014-06-04 23.01, Richard Hansen wrote:\n[]\nI haven't digged too deep, but this is what I get on pu:\n\n./t9904-zsh-prompt.sh \n./lib-zsh.sh:emulate:42: too many arguments\n./lib-zsh.sh:emulate:52: too many arguments\n/lib-prompt-tests.sh:.:6: no such file or directory: /lib-prompt-tests.sh\n##\n\n zsh --version\nzsh 4.3.9 (i386-apple-darwin10.0)\n\nI'm not a zsh expert, but I can offer to do more tests/debugging if needed \n"},{"id":"243772","messageId":"53976A7E.8010001@bbn.com","threadId":"36705","inReplyTo":"53976563.5020905@web.de","subject":"Re: [PATCH v2 00/11] Zsh prompt tests","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2014-06-10T20:28:46Z","receivedAt":"2014-06-10T20:28:46Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"On 2014-06-10 16:06, Torsten Bögershausen wrote:\n> On 2014-06-04 23.01, Richard Hansen wrote:\n> []\n> I haven't digged too deep, but this is what I get on pu:\n> \n> ./t9904-zsh-prompt.sh \n> ./lib-zsh.sh:emulate:42: too many arguments\n> ./lib-zsh.sh:emulate:52: too many arguments\n> /lib-prompt-tests.sh:.:6: no such file or directory: /lib-prompt-tests.sh\n> ##\n\nThank you for trying these patches and reporting your findings!\n\n> \n>  zsh --version\n> zsh 4.3.9 (i386-apple-darwin10.0)\n\nzsh 4.3.9 is over 5 years old (2008-11-03).  Is that young enough that\nwe should still try to support it?\n\n> \n> I'm not a zsh expert, but I can offer to do more tests/debugging if needed \n\nI'm not a zsh expert either (I just got a crash course over the past\ncouple of weeks), but if I were to guess I'd say that the 'emulate -c'\noption is new to zsh 5.0 (2012-07-21).  When I next have time I'll try\ntesting with a bunch of different versions of zsh.\n\nThanks,\nRichard\n"},{"id":"243867","messageId":"20140611011617.GB368384@vauxhall.crustytoothpaste.net","threadId":"36705","inReplyTo":"53976A7E.8010001@bbn.com","subject":"Re: [PATCH v2 00/11] Zsh prompt tests","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2014-06-11T01:16:18Z","receivedAt":"2014-06-11T01:16:18Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Tue, Jun 10, 2014 at 04:28:46PM -0400, Richard Hansen wrote:\n> On 2014-06-10 16:06, Torsten Bögershausen wrote:\n> > On 2014-06-04 23.01, Richard Hansen wrote:\n> > []\n> > I haven't digged too deep, but this is what I get on pu:\n> > \n> > ./t9904-zsh-prompt.sh \n> > ./lib-zsh.sh:emulate:42: too many arguments\n> > ./lib-zsh.sh:emulate:52: too many arguments\n> > /lib-prompt-tests.sh:.:6: no such file or directory: /lib-prompt-tests.sh\n> > ##\n> \n> Thank you for trying these patches and reporting your findings!\n> \n> > \n> >  zsh --version\n> > zsh 4.3.9 (i386-apple-darwin10.0)\n> \n> zsh 4.3.9 is over 5 years old (2008-11-03).  Is that young enough that\n> we should still try to support it?\n\nzsh 4.3.10 is the version in RHEL/CentOS 6, and people are still using\nCentOS 5.  At $DAYJOB we build git on both, so it would be nice if at\nleast the tests didn't fail.  Skipping them on older versions (maybe\nusing is-at-least) would be fine by me.\n\n-- \nbrian m. carlson / brian with sandals: Houston, Texas, US\n+1 832 623 2791 | http://www.crustytoothpaste.net/~bmc | My opinion only\nOpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187\n"},{"id":"243911","messageId":"5398755B.4050601@bbn.com","threadId":"36705","inReplyTo":"20140611011617.GB368384@vauxhall.crustytoothpaste.net","subject":"Re: [PATCH v2 00/11] Zsh prompt tests","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2014-06-11T15:27:23Z","receivedAt":"2014-06-11T15:27:23Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"On 2014-06-10 21:16, brian m. carlson wrote:\n> On Tue, Jun 10, 2014 at 04:28:46PM -0400, Richard Hansen wrote:\n>> On 2014-06-10 16:06, Torsten Bögershausen wrote:\n>>>  zsh --version\n>>> zsh 4.3.9 (i386-apple-darwin10.0)\n>>\n>> zsh 4.3.9 is over 5 years old (2008-11-03).  Is that young enough that\n>> we should still try to support it?\n> \n> zsh 4.3.10 is the version in RHEL/CentOS 6, and people are still using\n> CentOS 5.  At $DAYJOB we build git on both, so it would be nice if at\n> least the tests didn't fail.\n\nLooks like CentOS 5 has zsh 4.2.6, so when I rewrite the patch series\nI'll test zsh versions that are at least that old.\n\n> Skipping them on older versions (maybe using is-at-least) would be\n> fine by me.\n\nI don't think we'll need to skip the tests on old zsh versions --\nrunning 'zsh -c' should still work even if 'emulate zsh -c' doesn't.\n\nThanks,\nRichard\n"},{"id":"243932","messageId":"20140611234620.GC368384@vauxhall.crustytoothpaste.net","threadId":"36705","inReplyTo":"5398755B.4050601@bbn.com","subject":"Re: [PATCH v2 00/11] Zsh prompt tests","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2014-06-11T23:46:21Z","receivedAt":"2014-06-11T23:46:21Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Wed, Jun 11, 2014 at 11:27:23AM -0400, Richard Hansen wrote:\n> On 2014-06-10 21:16, brian m. carlson wrote:\n> > Skipping them on older versions (maybe using is-at-least) would be\n> > fine by me.\n> \n> I don't think we'll need to skip the tests on old zsh versions --\n> running 'zsh -c' should still work even if 'emulate zsh -c' doesn't.\n\nOkay.  I honestly don't support CentOS 5 in my personal projects because\nit's very old, so I didn't want you to have to do a lot of extra work if\nyou felt that the age didn't justify it.  Most git users on CentOS 5\nalready deal with some minor reduced functionality anyways.\n\n-- \nbrian m. carlson / brian with sandals: Houston, Texas, US\n+1 832 623 2791 | http://www.crustytoothpaste.net/~bmc | My opinion only\nOpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187\n"}]}