{"thread":{"id":"34278","subject":"[PATCH v2 0/5] git-prompt: cleaning and improvement","startedAt":"2013-06-26T03:05:12Z","lastAt":"2013-06-28T17:13:33Z","messageCount":10,"participants":["Eduardo R. D'Avila","Junio C Hamano","SZEDER Gábor"],"isPatch":true,"patchVersion":2,"patchTotal":5},"messages":[{"id":"221999","messageId":"cover.1372211661.git.erdavila@gmail.com","threadId":"34278","inReplyTo":null,"subject":"[PATCH v2 0/5] git-prompt: cleaning and improvement","fromName":"Eduardo R. D'Avila","fromEmail":"erdavila@gmail.com","sentAt":"2013-06-26T03:05:12Z","receivedAt":"2013-06-26T03:05:12Z","isPatch":true,"sender":{"key":"erdavila@gmail.com","avatar":"https://avatars.githubusercontent.com/u/341488?v=4"},"body":"Changes since the first version [1]:\n - During refactorization in 2/5, mention what the lack of \\[...\\] can affect.\n - New patch 3/5 that removes redundant tests (noticed by SZEDER Gábor [2])\n - Rephrasing in 5/5:\n   - rephrasing suggested by SZEDER Gábor [3]\n   - rephrase some parts that mention only the \"current branch name\" being\n     displayed in the prompt by stating that the \"repository status\"\n     is displayed.\n   - explain the color codes in the ZSH precmd example (there was an\n     explanation that applied only for the Bash example, but it was not\n     clear that it did not apply to ZSH).\n\nFollowing Gábor's example, I merged his patches series [4] to mine\nand published at:\n\n  https://github.com/erdavila/git.git bash-prompt-speedup-and-color-refactorization\n\nBoth Gábor's and my series were rebased/applied on top of the\ncurrent master 9832cb9d4d.\n\nThanks,\n\nEduardo\n\n[1] http://thread.gmane.org/gmane.comp.version-control.git/228566\n[2] http://article.gmane.org/gmane.comp.version-control.git/228705\n[3] http://article.gmane.org/gmane.comp.version-control.git/228707\n[4] http://thread.gmane.org/gmane.comp.version-control.git/228851\n\nEduardo R. D'Avila (5):\n  t9903: add tests for git-prompt pcmode\n  git-prompt.sh: refactor colored prompt code\n  t9903: remove redundant tests\n  git-prompt.sh: do not print duplicate clean color code\n  git-prompt.sh: add missing information in comments\n\n contrib/completion/git-prompt.sh | 111 ++++++++++++------------------\n t/t9903-bash-prompt.sh           | 141 +++++++++++++++++++++++++++++++++++++++\n 2 files changed, 182 insertions(+), 70 deletions(-)\n\n-- \n1.8.3.1.590.g42a98dd\n"},{"id":"222000","messageId":"76906ef44cb50773cd4965ee83cfd62255640553.1372211661.git.erdavila@gmail.com","threadId":"34278","inReplyTo":"cover.1372211661.git.erdavila@gmail.com","subject":"[PATCH v2 1/5] t9903: add tests for git-prompt pcmode","fromName":"Eduardo R. D'Avila","fromEmail":"erdavila@gmail.com","sentAt":"2013-06-26T03:05:13Z","receivedAt":"2013-06-26T03:05:13Z","isPatch":true,"sender":{"key":"erdavila@gmail.com","avatar":"https://avatars.githubusercontent.com/u/341488?v=4"},"body":"git-prompt.sh lacks tests for PROMPT_COMMAND mode.\n\nAdd tests for:\n* pcmode prompt without colors\n* pcmode prompt with colors for bash\n* pcmode prompt with colors for zsh\n\nHaving these tests enables an upcoming refactor in\na safe way.\n\nSigned-off-by: Eduardo R. D'Avila <erdavila@gmail.com>\n---\n254\t0\tt/t9903-bash-prompt.sh\n t/t9903-bash-prompt.sh | 254 +++++++++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 254 insertions(+)\n\ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex 15521cc..6a88778 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -10,6 +10,10 @@ 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 \n test_expect_success 'setup for prompt tests' '\n \tmkdir -p subdir/subsubdir &&\n@@ -535,4 +539,254 @@ 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: (master):AFTER\" >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\" \"$PS1\" >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success 'prompt - bash color pc mode - branch name' '\n+\tprintf \"BEFORE: (${c_green}master${c_clear}${c_clear}):AFTER\" >expected &&\n+\t(\n+\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\t__git_ps1 \"BEFORE:\" \":AFTER\" >\"$actual\"\n+\t\tprintf \"%s\" \"$PS1\" >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success 'prompt - bash color pc mode - detached head' '\n+\tprintf \"BEFORE: (${c_red}(%s...)${c_clear}${c_clear}):AFTER\" $(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\" \"$PS1\" >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty worktree' '\n+\tprintf \"BEFORE: (${c_green}master${c_clear} ${c_red}*${c_clear}):AFTER\" >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\" \"$PS1\" >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index' '\n+\tprintf \"BEFORE: (${c_green}master${c_clear} ${c_green}+${c_clear}):AFTER\" >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\" \"$PS1\" >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index and worktree' '\n+\tprintf \"BEFORE: (${c_green}master${c_clear} ${c_red}*${c_green}+${c_clear}):AFTER\" >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\" \"$PS1\" >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success 'prompt - bash color pc mode - dirty status indicator - before root commit' '\n+\tprintf \"BEFORE: (${c_green}master${c_clear} ${c_green}#${c_clear}):AFTER\" >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\" \"$PS1\" >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success 'prompt - bash color pc mode - inside .git directory' '\n+\tprintf \"BEFORE: (${c_green}GIT_DIR!${c_clear}${c_clear}):AFTER\" >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\" \"$PS1\" >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success 'prompt - bash color pc mode - stash status indicator' '\n+\tprintf \"BEFORE: (${c_green}master${c_clear} ${c_lblue}\\$${c_clear}):AFTER\" >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\" \"$PS1\" >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success 'prompt - bash color pc mode - untracked files status indicator' '\n+\tprintf \"BEFORE: (${c_green}master${c_clear} ${c_red}%%${c_clear}):AFTER\" >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\" \"$PS1\" >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success 'prompt - zsh color pc mode - branch name' '\n+\tprintf \"BEFORE: (%%F{green}master%%f%%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\" \"$PS1\" >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success 'prompt - zsh color pc mode - detached head' '\n+\tprintf \"BEFORE: (%%F{red}(%s...)%%f%%f):AFTER\" $(git log -1 --format=\"%h\" b1^) >expected &&\n+\tgit checkout b1^ &&\n+\ttest_when_finished \"git checkout master\" &&\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_expect_success 'prompt - zsh color pc mode - dirty status indicator - dirty worktree' '\n+\tprintf \"BEFORE: (%%F{green}master%%f %%F{red}*%%f):AFTER\" >expected &&\n+\techo \"dirty\" >file &&\n+\ttest_when_finished \"git reset --hard\" &&\n+\t(\n+\t\tZSH_VERSION=5.0.0 &&\n+\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\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_expect_success 'prompt - zsh color pc mode - dirty status indicator - dirty index' '\n+\tprintf \"BEFORE: (%%F{green}master%%f %%F{green}+%%f):AFTER\" >expected &&\n+\techo \"dirty\" >file &&\n+\ttest_when_finished \"git reset --hard\" &&\n+\tgit add -u &&\n+\t(\n+\t\tZSH_VERSION=5.0.0 &&\n+\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\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_expect_success 'prompt - zsh color pc mode - dirty status indicator - dirty index and worktree' '\n+\tprintf \"BEFORE: (%%F{green}master%%f %%F{red}*%%F{green}+%%f):AFTER\" >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\tZSH_VERSION=5.0.0 &&\n+\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n+\t\tGIT_PS1_SHOWDIRTYSTATE=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_expect_success 'prompt - zsh color pc mode - dirty status indicator - before root commit' '\n+\tprintf \"BEFORE: (%%F{green}master%%f %%F{green}#%%f):AFTER\" >expected &&\n+\t(\n+\t\tZSH_VERSION=5.0.0 &&\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\" \"$PS1\" >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success 'prompt - zsh color pc mode - inside .git directory' '\n+\tprintf \"BEFORE: (%%F{green}GIT_DIR!%%f%%f):AFTER\" >expected &&\n+\techo \"dirty\" >file &&\n+\ttest_when_finished \"git reset --hard\" &&\n+\t(\n+\t\tZSH_VERSION=5.0.0 &&\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\" \"$PS1\" >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success 'prompt - zsh color pc mode - stash status indicator' '\n+\tprintf \"BEFORE: (%%F{green}master%%f %%F{blue}$%%f):AFTER\" >expected &&\n+\techo 2 >file &&\n+\tgit stash &&\n+\ttest_when_finished \"git stash drop\" &&\n+\t(\n+\t\tZSH_VERSION=5.0.0 &&\n+\t\tGIT_PS1_SHOWSTASHSTATE=y &&\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_expect_success 'prompt - zsh color pc mode - untracked files status indicator' '\n+\tprintf \"BEFORE: (%%F{green}master%%f %%F{red}%%%%%%f):AFTER\" >expected &&\n+\t(\n+\t\tZSH_VERSION=5.0.0 &&\n+\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\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.8.3.1.590.g42a98dd\n"},{"id":"222001","messageId":"7ecb9a0f24499fd6dd8ddf51514cadfb9f559bf6.1372211661.git.erdavila@gmail.com","threadId":"34278","inReplyTo":"cover.1372211661.git.erdavila@gmail.com","subject":"[PATCH v2 2/5] git-prompt.sh: refactor colored prompt code","fromName":"Eduardo R. D'Avila","fromEmail":"erdavila@gmail.com","sentAt":"2013-06-26T03:05:14Z","receivedAt":"2013-06-26T03:05:14Z","isPatch":true,"sender":{"key":"erdavila@gmail.com","avatar":"https://avatars.githubusercontent.com/u/341488?v=4"},"body":"__git_ps1_colorize_gitstring() sets color codes and\nbuilds the prompt gitstring. It has duplicated code\nto handle color codes for bash and zsh shells.\n__git_ps1() also has duplicated logic to build the\nprompt gitstring.\n\nRemove duplication of logic to build gitstring in\n__git_ps1_colorize_gitstring() and __git_ps1().\n\nLeave in __git_ps1_colorize_gitstring() only logic\nto set color codes.\n\nSigned-off-by: Eduardo R. D'Avila <erdavila@gmail.com>\n---\n26\t59\tcontrib/completion/git-prompt.sh\n contrib/completion/git-prompt.sh | 85 ++++++++++++----------------------------\n 1 file changed, 26 insertions(+), 59 deletions(-)\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex 07a6218..fdedb45 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -225,8 +225,8 @@ __git_ps1_show_upstream ()\n }\n \n # Helper function that is meant to be called from __git_ps1.  It\n-# builds up a gitstring injecting color codes into the appropriate\n-# places.\n+# injects color codes into the appropriate gitstring variables used\n+# to build a gitstring.\n __git_ps1_colorize_gitstring ()\n {\n \tif [[ -n ${ZSH_VERSION-} ]]; then\n@@ -234,74 +234,40 @@ __git_ps1_colorize_gitstring ()\n \t\tlocal c_green='%F{green}'\n \t\tlocal c_lblue='%F{blue}'\n \t\tlocal c_clear='%f'\n-\t\tlocal bad_color=$c_red\n-\t\tlocal ok_color=$c_green\n-\t\tlocal branch_color=\"$c_clear\"\n-\t\tlocal flags_color=\"$c_lblue\"\n-\t\tlocal branchstring=\"$c${b##refs/heads/}\"\n-\n-\t\tif [ $detached = no ]; then\n-\t\t\tbranch_color=\"$ok_color\"\n-\t\telse\n-\t\t\tbranch_color=\"$bad_color\"\n-\t\tfi\n-\n-\t\tgitstring=\"$branch_color$branchstring$c_clear\"\n-\n-\t\tif [ -n \"$w$i$s$u$r$p\" ]; then\n-\t\t\tgitstring=\"$gitstring$z\"\n-\t\tfi\n-\t\tif [ \"$w\" = \"*\" ]; then\n-\t\t\tgitstring=\"$gitstring$bad_color$w\"\n-\t\tfi\n-\t\tif [ -n \"$i\" ]; then\n-\t\t\tgitstring=\"$gitstring$ok_color$i\"\n-\t\tfi\n-\t\tif [ -n \"$s\" ]; then\n-\t\t\tgitstring=\"$gitstring$flags_color$s\"\n-\t\tfi\n-\t\tif [ -n \"$u\" ]; then\n-\t\t\tgitstring=\"$gitstring$bad_color$u\"\n-\t\tfi\n-\t\tgitstring=\"$gitstring$c_clear$r$p\"\n-\t\treturn\n+\telse\n+\t\t# Using \\[ and \\] around colors is necessary to prevent\n+\t\t# issues with command line editing/browsing/completion!\n+\t\tlocal c_red='\\[\\e[31m\\]'\n+\t\tlocal c_green='\\[\\e[32m\\]'\n+\t\tlocal c_lblue='\\[\\e[1;34m\\]'\n+\t\tlocal c_clear='\\[\\e[0m\\]'\n \tfi\n-\tlocal c_red='\\e[31m'\n-\tlocal c_green='\\e[32m'\n-\tlocal c_lblue='\\e[1;34m'\n-\tlocal c_clear='\\e[0m'\n \tlocal bad_color=$c_red\n \tlocal ok_color=$c_green\n-\tlocal branch_color=\"$c_clear\"\n \tlocal flags_color=\"$c_lblue\"\n-\tlocal branchstring=\"$c${b##refs/heads/}\"\n \n+\tlocal branch_color=\"\"\n \tif [ $detached = no ]; then\n \t\tbranch_color=\"$ok_color\"\n \telse\n \t\tbranch_color=\"$bad_color\"\n \tfi\n+\tc=\"$branch_color$c\"\n+\tb=\"$b$c_clear\"\n \n-\t# Setting gitstring directly with \\[ and \\] around colors\n-\t# is necessary to prevent wrapping issues!\n-\tgitstring=\"\\[$branch_color\\]$branchstring\\[$c_clear\\]\"\n-\n-\tif [ -n \"$w$i$s$u$r$p\" ]; then\n-\t\tgitstring=\"$gitstring$z\"\n-\tfi\n \tif [ \"$w\" = \"*\" ]; then\n-\t\tgitstring=\"$gitstring\\[$bad_color\\]$w\"\n+\t\tw=\"$bad_color$w\"\n \tfi\n \tif [ -n \"$i\" ]; then\n-\t\tgitstring=\"$gitstring\\[$ok_color\\]$i\"\n+\t\ti=\"$ok_color$i\"\n \tfi\n \tif [ -n \"$s\" ]; then\n-\t\tgitstring=\"$gitstring\\[$flags_color\\]$s\"\n+\t\ts=\"$flags_color$s\"\n \tfi\n \tif [ -n \"$u\" ]; then\n-\t\tgitstring=\"$gitstring\\[$bad_color\\]$u\"\n+\t\tu=\"$bad_color$u\"\n \tfi\n-\tgitstring=\"$gitstring\\[$c_clear\\]$r$p\"\n+\tr=\"$c_clear$r\"\n }\n \n # __git_ps1 accepts 0 or 1 arguments (i.e., format string)\n@@ -443,19 +409,20 @@ __git_ps1 ()\n \t\tfi\n \n \t\tlocal z=\"${GIT_PS1_STATESEPARATOR-\" \"}\"\n+\n+\t\t# NO color option unless in PROMPT_COMMAND mode\n+\t\tif [ $pcmode = yes ] && [ -n \"${GIT_PS1_SHOWCOLORHINTS-}\" ]; then\n+\t\t\t__git_ps1_colorize_gitstring\n+\t\tfi\n+\n \t\tlocal f=\"$w$i$s$u\"\n+\t\tlocal gitstring=\"$c${b##refs/heads/}${f:+$z$f}$r$p\"\n+\n \t\tif [ $pcmode = yes ]; then\n-\t\t\tlocal gitstring=\n-\t\t\tif [ -n \"${GIT_PS1_SHOWCOLORHINTS-}\" ]; then\n-\t\t\t\t__git_ps1_colorize_gitstring\n-\t\t\telse\n-\t\t\t\tgitstring=\"$c${b##refs/heads/}${f:+$z$f}$r$p\"\n-\t\t\tfi\n \t\t\tgitstring=$(printf -- \"$printf_format\" \"$gitstring\")\n \t\t\tPS1=\"$ps1pc_start$gitstring$ps1pc_end\"\n \t\telse\n-\t\t\t# NO color option unless in PROMPT_COMMAND mode\n-\t\t\tprintf -- \"$printf_format\" \"$c${b##refs/heads/}${f:+$z$f}$r$p\"\n+\t\t\tprintf -- \"$printf_format\" \"$gitstring\"\n \t\tfi\n \tfi\n }\n-- \n1.8.3.1.590.g42a98dd\n"},{"id":"222002","messageId":"5f56853a746189ccb03b929d472b5a5e721f8fb7.1372211661.git.erdavila@gmail.com","threadId":"34278","inReplyTo":"cover.1372211661.git.erdavila@gmail.com","subject":"[PATCH v2 3/5] t9903: remove redundant tests","fromName":"Eduardo R. D'Avila","fromEmail":"erdavila@gmail.com","sentAt":"2013-06-26T03:05:15Z","receivedAt":"2013-06-26T03:05:15Z","isPatch":true,"sender":{"key":"erdavila@gmail.com","avatar":"https://avatars.githubusercontent.com/u/341488?v=4"},"body":"After refactoring __git_ps1_colorize_gitstring, codepaths for bash and zsh\nbecame mostly common and tests for bash and zsh became redundant.\n\nRemove tests for zsh. Keep one minimal test that stress the difference\nin codepaths for bash and zsh.\n\nSuggested-by: SZEDER Gábor <szeder@ira.uka.de>\nSigned-off-by: Eduardo R. D'Avila <erdavila@gmail.com>\n---\n1\t114\tt/t9903-bash-prompt.sh\n t/t9903-bash-prompt.sh | 115 +------------------------------------------------\n 1 file changed, 1 insertion(+), 114 deletions(-)\n\ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex 6a88778..f250dfc 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -665,7 +665,7 @@ 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 - branch name' '\n+test_expect_success 'prompt - zsh color pc mode' '\n \tprintf \"BEFORE: (%%F{green}master%%f%%f):AFTER\" >expected &&\n \t(\n \t\tZSH_VERSION=5.0.0 &&\n@@ -676,117 +676,4 @@ test_expect_success 'prompt - zsh color pc mode - branch name' '\n \ttest_cmp expected \"$actual\"\n '\n \n-test_expect_success 'prompt - zsh color pc mode - detached head' '\n-\tprintf \"BEFORE: (%%F{red}(%s...)%%f%%f):AFTER\" $(git log -1 --format=\"%h\" b1^) >expected &&\n-\tgit checkout b1^ &&\n-\ttest_when_finished \"git checkout master\" &&\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_expect_success 'prompt - zsh color pc mode - dirty status indicator - dirty worktree' '\n-\tprintf \"BEFORE: (%%F{green}master%%f %%F{red}*%%f):AFTER\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\t(\n-\t\tZSH_VERSION=5.0.0 &&\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\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_expect_success 'prompt - zsh color pc mode - dirty status indicator - dirty index' '\n-\tprintf \"BEFORE: (%%F{green}master%%f %%F{green}+%%f):AFTER\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\tgit add -u &&\n-\t(\n-\t\tZSH_VERSION=5.0.0 &&\n-\t\tGIT_PS1_SHOWDIRTYSTATE=y &&\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_expect_success 'prompt - zsh color pc mode - dirty status indicator - dirty index and worktree' '\n-\tprintf \"BEFORE: (%%F{green}master%%f %%F{red}*%%F{green}+%%f):AFTER\" >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\tZSH_VERSION=5.0.0 &&\n-\t\tGIT_PS1_SHOWCOLORHINTS=y &&\n-\t\tGIT_PS1_SHOWDIRTYSTATE=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_expect_success 'prompt - zsh color pc mode - dirty status indicator - before root commit' '\n-\tprintf \"BEFORE: (%%F{green}master%%f %%F{green}#%%f):AFTER\" >expected &&\n-\t(\n-\t\tZSH_VERSION=5.0.0 &&\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\" \"$PS1\" >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success 'prompt - zsh color pc mode - inside .git directory' '\n-\tprintf \"BEFORE: (%%F{green}GIT_DIR!%%f%%f):AFTER\" >expected &&\n-\techo \"dirty\" >file &&\n-\ttest_when_finished \"git reset --hard\" &&\n-\t(\n-\t\tZSH_VERSION=5.0.0 &&\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\" \"$PS1\" >\"$actual\"\n-\t) &&\n-\ttest_cmp expected \"$actual\"\n-'\n-\n-test_expect_success 'prompt - zsh color pc mode - stash status indicator' '\n-\tprintf \"BEFORE: (%%F{green}master%%f %%F{blue}$%%f):AFTER\" >expected &&\n-\techo 2 >file &&\n-\tgit stash &&\n-\ttest_when_finished \"git stash drop\" &&\n-\t(\n-\t\tZSH_VERSION=5.0.0 &&\n-\t\tGIT_PS1_SHOWSTASHSTATE=y &&\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_expect_success 'prompt - zsh color pc mode - untracked files status indicator' '\n-\tprintf \"BEFORE: (%%F{green}master%%f %%F{red}%%%%%%f):AFTER\" >expected &&\n-\t(\n-\t\tZSH_VERSION=5.0.0 &&\n-\t\tGIT_PS1_SHOWUNTRACKEDFILES=y &&\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.8.3.1.590.g42a98dd\n"},{"id":"222003","messageId":"6dc7fc8c8033186b296616238481a86946ee36f0.1372211661.git.erdavila@gmail.com","threadId":"34278","inReplyTo":"cover.1372211661.git.erdavila@gmail.com","subject":"[PATCH v2 4/5] git-prompt.sh: do not print duplicate clean color code","fromName":"Eduardo R. D'Avila","fromEmail":"erdavila@gmail.com","sentAt":"2013-06-26T03:05:16Z","receivedAt":"2013-06-26T03:05:16Z","isPatch":true,"sender":{"key":"erdavila@gmail.com","avatar":"https://avatars.githubusercontent.com/u/341488?v=4"},"body":"Do not print a duplicate clean color code when there\nis no other indicators other than the current branch\nin colored prompt.\n\nAcked-by: SZEDER Gábor <szeder@ira.uka.de>\nSigned-off-by: Eduardo R. D'Avila <erdavila@gmail.com>\n---\n1\t1\tcontrib/completion/git-prompt.sh\n4\t4\tt/t9903-bash-prompt.sh\n contrib/completion/git-prompt.sh | 2 +-\n t/t9903-bash-prompt.sh           | 8 ++++----\n 2 files changed, 5 insertions(+), 5 deletions(-)\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex fdedb45..545518a 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -253,8 +253,8 @@ __git_ps1_colorize_gitstring ()\n \t\tbranch_color=\"$bad_color\"\n \tfi\n \tc=\"$branch_color$c\"\n-\tb=\"$b$c_clear\"\n \n+\tz=\"$c_clear$z\"\n \tif [ \"$w\" = \"*\" ]; then\n \t\tw=\"$bad_color$w\"\n \tfi\ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex f250dfc..5cd138e 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -551,7 +551,7 @@ test_expect_success 'prompt - pc mode' '\n '\n \n test_expect_success 'prompt - bash color pc mode - branch name' '\n-\tprintf \"BEFORE: (${c_green}master${c_clear}${c_clear}):AFTER\" >expected &&\n+\tprintf \"BEFORE: (${c_green}master${c_clear}):AFTER\" >expected &&\n \t(\n \t\tGIT_PS1_SHOWCOLORHINTS=y &&\n \t\t__git_ps1 \"BEFORE:\" \":AFTER\" >\"$actual\"\n@@ -561,7 +561,7 @@ test_expect_success 'prompt - bash color pc mode - branch name' '\n '\n \n test_expect_success 'prompt - bash color pc mode - detached head' '\n-\tprintf \"BEFORE: (${c_red}(%s...)${c_clear}${c_clear}):AFTER\" $(git log -1 --format=\"%h\" b1^) >expected &&\n+\tprintf \"BEFORE: (${c_red}(%s...)${c_clear}):AFTER\" $(git log -1 --format=\"%h\" b1^) >expected &&\n \tgit checkout b1^ &&\n \ttest_when_finished \"git checkout master\" &&\n \t(\n@@ -627,7 +627,7 @@ test_expect_success 'prompt - bash color pc mode - dirty status indicator - befo\n '\n \n test_expect_success 'prompt - bash color pc mode - inside .git directory' '\n-\tprintf \"BEFORE: (${c_green}GIT_DIR!${c_clear}${c_clear}):AFTER\" >expected &&\n+\tprintf \"BEFORE: (${c_green}GIT_DIR!${c_clear}):AFTER\" >expected &&\n \techo \"dirty\" >file &&\n \ttest_when_finished \"git reset --hard\" &&\n \t(\n@@ -666,7 +666,7 @@ 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}master%%f%%f):AFTER\" >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-- \n1.8.3.1.590.g42a98dd\n"},{"id":"222004","messageId":"06da7dd706334feb1ce04bea8e1c494a7a0797c1.1372211661.git.erdavila@gmail.com","threadId":"34278","inReplyTo":"cover.1372211661.git.erdavila@gmail.com","subject":"[PATCH v2 5/5] git-prompt.sh: add missing information in comments","fromName":"Eduardo R. D'Avila","fromEmail":"erdavila@gmail.com","sentAt":"2013-06-26T03:05:17Z","receivedAt":"2013-06-26T03:05:17Z","isPatch":true,"sender":{"key":"erdavila@gmail.com","avatar":"https://avatars.githubusercontent.com/u/341488?v=4"},"body":"Mention that the command below is needed for prompt\nin ZSH with PS1:\n  setopt PROMPT_SUBST\n\nRephrase some parts that mention only the \"current branch name\"\nbeing displayed in the prompt. Replace it by stating that\nthe \"repository status\" is displayed.\n\nMake it clear that colored prompt is only available\nin PROMPT_COMMAND/precmd mode.\n\nWith-suggestions-by: SZEDER Gábor <szeder@ira.uka.de>\nSigned-off-by: Eduardo R. D'Avila <erdavila@gmail.com>\n---\n15\t11\tcontrib/completion/git-prompt.sh\n contrib/completion/git-prompt.sh | 26 +++++++++++++++-----------\n 1 file changed, 15 insertions(+), 11 deletions(-)\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex 545518a..b3f39e8 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -3,7 +3,7 @@\n # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>\n # Distributed under the GNU General Public License, version 2.0.\n #\n-# This script allows you to see the current branch in your prompt.\n+# This script allows you to see repository status in your prompt.\n #\n # To enable:\n #\n@@ -13,24 +13,27 @@\n #    3a) Change your PS1 to call __git_ps1 as\n #        command-substitution:\n #        Bash: PS1='[\\u@\\h \\W$(__git_ps1 \" (%s)\")]\\$ '\n-#        ZSH:  PS1='[%n@%m %c$(__git_ps1 \" (%s)\")]\\$ '\n+#        ZSH:  setopt PROMPT_SUBST ; PS1='[%n@%m %c$(__git_ps1 \" (%s)\")]\\$ '\n #        the optional argument will be used as format string.\n-#    3b) Alternatively, if you are using bash, __git_ps1 can be\n-#        used for PROMPT_COMMAND with two parameters, <pre> and\n+#    3b) Alternatively, __git_ps1 can be used for PROMPT_COMMAND in\n+#        Bash or for precmd() in ZSH with two parameters, <pre> and\n #        <post>, which are strings you would put in $PS1 before\n #        and after the status string generated by the git-prompt\n #        machinery.  e.g.\n #        Bash: PROMPT_COMMAND='__git_ps1 \"\\u@\\h:\\w\" \"\\\\\\$ \"'\n+#          will show username, at-sign, host, colon, cwd, then\n+#          various status string, followed by dollar and SP, as\n+#          your prompt.\n #        ZSH:  precmd () { __git_ps1 \"%n\" \":%~$ \" \"|%s\" }\n-#        will show username, at-sign, host, colon, cwd, then\n-#        various status string, followed by dollar and SP, as\n-#        your prompt.\n+#          will show username, pipe, then various status string,\n+#          followed by colon, cwd, dollar and SP, as your prompt.\n #        Optionally, you can supply a third argument with a printf\n #        format string to finetune the output of the branch status\n #\n-# The argument to __git_ps1 will be displayed only if you are currently\n-# in a git repository.  The %s token will be the name of the current\n-# branch.\n+# The repository status will be displayed only if you are currently in a\n+# git repository. The %s token is the placeholder for the shown status.\n+#\n+# The prompt status always includes the current branch name.\n #\n # In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty value,\n # unstaged (*) and staged (+) changes will be shown next to the branch\n@@ -78,7 +81,8 @@\n #\n # If you would like a colored hint about the current dirty state, set\n # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on\n-# the colored output of \"git status -sb\".\n+# the colored output of \"git status -sb\" and are available only when\n+# using __git_ps1 for PROMPT_COMMAND or precmd.\n \n # __gitdir accepts 0 or 1 arguments (i.e., location)\n # returns location of .git repo\n-- \n1.8.3.1.590.g42a98dd\n"},{"id":"222088","messageId":"7v8v1vvash.fsf@alter.siamese.dyndns.org","threadId":"34278","inReplyTo":"cover.1372211661.git.erdavila@gmail.com","subject":"Re: [PATCH v2 0/5] git-prompt: cleaning and improvement","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-06-27T15:22:06Z","receivedAt":"2013-06-27T15:22:06Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Queued, and merged to 'pu' without the previous merge with the older\niteration.  If you two can double check the merged result, it would\nbe very much appreciated.\n\nThanks.\n"},{"id":"222147","messageId":"CAOz-D1JE2YkoJErY_yjvBC-YSTC=7RycB3svnQ0t3c4RMVOJPw@mail.gmail.com","threadId":"34278","inReplyTo":"7v8v1vvash.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH v2 0/5] git-prompt: cleaning and improvement","fromName":"Eduardo R. D'Avila","fromEmail":"erdavila@gmail.com","sentAt":"2013-06-28T01:31:57Z","receivedAt":"2013-06-28T01:31:57Z","isPatch":true,"sender":{"key":"erdavila@gmail.com","avatar":"https://avatars.githubusercontent.com/u/341488?v=4"},"body":"Hi Junio,\n\nThe merged result is ok!\n\nThanks,\n\nEduardo\n"},{"id":"222158","messageId":"20130628094221.GA15436@goldbirke","threadId":"34278","inReplyTo":"CAOz-D1JE2YkoJErY_yjvBC-YSTC=7RycB3svnQ0t3c4RMVOJPw@mail.gmail.com","subject":"Re: [PATCH v2 0/5] git-prompt: cleaning and improvement","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2013-06-28T09:42:21Z","receivedAt":"2013-06-28T09:42:21Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Hi,\n\n\nOn Thu, Jun 27, 2013 at 10:31:57PM -0300, Eduardo R. D'Avila wrote:\n> The merged result is ok!\n\nYeah, it look good, thanks.\n\n\nGábor\n"},{"id":"222192","messageId":"7vsj02p39e.fsf@alter.siamese.dyndns.org","threadId":"34278","inReplyTo":"20130628094221.GA15436@goldbirke","subject":"Re: [PATCH v2 0/5] git-prompt: cleaning and improvement","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-06-28T17:13:33Z","receivedAt":"2013-06-28T17:13:33Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"SZEDER Gábor <szeder@ira.uka.de> writes:\n\n> On Thu, Jun 27, 2013 at 10:31:57PM -0300, Eduardo R. D'Avila wrote:\n>> The merged result is ok!\n>\n> Yeah, it look good, thanks.\n\nThanks, both, for double checking (and thank you for preparing the\npre-merged results).\n"}]}