{"thread":{"id":"37693","subject":"[PATCH] git-prompt.sh: Omit prompt for ignored directories","startedAt":"2014-10-08T19:04:00Z","lastAt":"2015-01-14T11:45:00Z","messageCount":18,"participants":["Jess Austin","Richard Hansen","Johannes Sixt","Junio C Hamano","SZEDER Gábor"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"250385","messageId":"1412795040-19267-1-git-send-email-jess.austin@gmail.com","threadId":"37693","inReplyTo":null,"subject":"[PATCH] git-prompt.sh: Omit prompt for ignored directories","fromName":"Jess Austin","fromEmail":"jess.austin@gmail.com","sentAt":"2014-10-08T19:04:00Z","receivedAt":"2014-10-08T19:04:00Z","isPatch":true,"sender":{"key":"jess.austin@gmail.com","avatar":"https://avatars.githubusercontent.com/u/295056?v=4"},"body":"Introduce a new environmental variable, GIT_PS1_OMITIGNORED, which\ntells __git_ps1 to display nothing when the current directory is\nset (e.g. via .gitignore) to be ignored by git. In the absence of\nGIT_PS1_OMITIGNORED this change has no effect.\n\nMany people manage e.g. dotfiles in their home directory with git.\nThis causes the prompt generated by __git_ps1 to refer to that \"top\nlevel\" repo while working in any descendant directory. That can be\ndistracting, so this patch helps one shut off that noise.\n\nSigned-off-by: Jess Austin <jess.austin@gmail.com>\n---\n contrib/completion/git-prompt.sh |  9 +++++++++\n t/t9903-bash-prompt.sh           | 21 +++++++++++++++++++++\n 2 files changed, 30 insertions(+)\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex c5473dc..6a26cb4 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -84,6 +84,10 @@\n # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on\n # the colored output of \"git status -sb\" and are available only when\n # using __git_ps1 for PROMPT_COMMAND or precmd.\n+#\n+# If you would like __git_ps1 to do nothing in the case when the current\n+# directory is set up to be ignored by git, then set GIT_PS1_OMITIGNORED\n+# to a nonempty value.\n \n # check whether printf supports -v\n __git_printf_supports_v=\n@@ -501,6 +505,11 @@ __git_ps1 ()\n \tlocal f=\"$w$i$s$u\"\n \tlocal gitstring=\"$c$b${f:+$z$f}$r$p\"\n \n+\tif [ -n \"$(git check-ignore .)\" ] && [ -n \"${GIT_PS1_OMITIGNORED}\" ]\n+\tthen\n+\t\tprintf_format=\"\"\n+\tfi\n+\n \tif [ $pcmode = yes ]; then\n \t\tif [ \"${__git_printf_supports_v-}\" != yes ]; then\n \t\t\tgitstring=$(printf -- \"$printf_format\" \"$gitstring\")\ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex 9150984..55bcb6b 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -35,6 +35,8 @@ test_expect_success 'setup for prompt tests' '\n \tgit commit -m \"another b2\" file &&\n \techo 000 >file &&\n \tgit commit -m \"yet another b2\" file &&\n+\tmkdir ignored_dir &&\n+\techo \"ignored_dir/\" >> .gitignore &&\n \tgit checkout master\n '\n \n@@ -588,4 +590,23 @@ test_expect_success 'prompt - zsh color pc mode' '\n \ttest_cmp expected \"$actual\"\n '\n \n+test_expect_success 'prompt - prompt omitted in ignored directory' '\n+\tprintf \"\" >expected &&\n+\t(\n+\t\tcd ignored_dir &&\n+\t\tGIT_PS1_OMITIGNORED=y &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success 'prompt - prompt not omitted without GIT_PS1_OMITIGNORED' '\n+\tprintf \" (master)\" >expected &&\n+\t(\n+\t\tcd ignored_dir &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n test_done\n-- \n1.9.1\n"},{"id":"250397","messageId":"5435A8A7.2030008@bbn.com","threadId":"37693","inReplyTo":"1412795040-19267-1-git-send-email-jess.austin@gmail.com","subject":"Re: [PATCH] git-prompt.sh: Omit prompt for ignored directories","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2014-10-08T21:12:07Z","receivedAt":"2014-10-08T21:12:07Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"On 2014-10-08 15:04, Jess Austin wrote:\n> Introduce a new environmental variable, GIT_PS1_OMITIGNORED, which\n> tells __git_ps1 to display nothing when the current directory is\n> set (e.g. via .gitignore) to be ignored by git. In the absence of\n> GIT_PS1_OMITIGNORED this change has no effect.\n> \n> Many people manage e.g. dotfiles in their home directory with git.\n> This causes the prompt generated by __git_ps1 to refer to that \"top\n> level\" repo while working in any descendant directory. That can be\n> distracting, so this patch helps one shut off that noise.\n\nInteresting idea, though I would prefer this to be configurable on a\nper-repository basis.  (I wouldn't want to hide the prompt in any\nrepository besides my home repository.)\n\nI'm not a big fan of the name \"OMITIGNORED\" (it's not immediately\nobvious what this means), but I can't think of anything better off the\ntop of my head...\n\n-Richard\n\n\n> \n> Signed-off-by: Jess Austin <jess.austin@gmail.com>\n> ---\n>  contrib/completion/git-prompt.sh |  9 +++++++++\n>  t/t9903-bash-prompt.sh           | 21 +++++++++++++++++++++\n>  2 files changed, 30 insertions(+)\n> \n> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\n> index c5473dc..6a26cb4 100644\n> --- a/contrib/completion/git-prompt.sh\n> +++ b/contrib/completion/git-prompt.sh\n> @@ -84,6 +84,10 @@\n>  # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on\n>  # the colored output of \"git status -sb\" and are available only when\n>  # using __git_ps1 for PROMPT_COMMAND or precmd.\n> +#\n> +# If you would like __git_ps1 to do nothing in the case when the current\n> +# directory is set up to be ignored by git, then set GIT_PS1_OMITIGNORED\n> +# to a nonempty value.\n>  \n>  # check whether printf supports -v\n>  __git_printf_supports_v=\n> @@ -501,6 +505,11 @@ __git_ps1 ()\n>  \tlocal f=\"$w$i$s$u\"\n>  \tlocal gitstring=\"$c$b${f:+$z$f}$r$p\"\n>  \n> +\tif [ -n \"$(git check-ignore .)\" ] && [ -n \"${GIT_PS1_OMITIGNORED}\" ]\n> +\tthen\n> +\t\tprintf_format=\"\"\n> +\tfi\n> +\n>  \tif [ $pcmode = yes ]; then\n>  \t\tif [ \"${__git_printf_supports_v-}\" != yes ]; then\n>  \t\t\tgitstring=$(printf -- \"$printf_format\" \"$gitstring\")\n> diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\n> index 9150984..55bcb6b 100755\n> --- a/t/t9903-bash-prompt.sh\n> +++ b/t/t9903-bash-prompt.sh\n> @@ -35,6 +35,8 @@ test_expect_success 'setup for prompt tests' '\n>  \tgit commit -m \"another b2\" file &&\n>  \techo 000 >file &&\n>  \tgit commit -m \"yet another b2\" file &&\n> +\tmkdir ignored_dir &&\n> +\techo \"ignored_dir/\" >> .gitignore &&\n>  \tgit checkout master\n>  '\n>  \n> @@ -588,4 +590,23 @@ test_expect_success 'prompt - zsh color pc mode' '\n>  \ttest_cmp expected \"$actual\"\n>  '\n>  \n> +test_expect_success 'prompt - prompt omitted in ignored directory' '\n> +\tprintf \"\" >expected &&\n> +\t(\n> +\t\tcd ignored_dir &&\n> +\t\tGIT_PS1_OMITIGNORED=y &&\n> +\t\t__git_ps1 >\"$actual\"\n> +\t) &&\n> +\ttest_cmp expected \"$actual\"\n> +'\n> +\n> +test_expect_success 'prompt - prompt not omitted without GIT_PS1_OMITIGNORED' '\n> +\tprintf \" (master)\" >expected &&\n> +\t(\n> +\t\tcd ignored_dir &&\n> +\t\t__git_ps1 >\"$actual\"\n> +\t) &&\n> +\ttest_cmp expected \"$actual\"\n> +'\n> +\n>  test_done\n> \n"},{"id":"250398","messageId":"CANp8Xb9MUbQCVZRNYibFBibzTFF=56BqNFFC1G2iTF7WGBNi7g@mail.gmail.com","threadId":"37693","inReplyTo":"CANp8Xb8ETG-ZFCqrOk=f-RbxtRxehBmAR1O5ozLH80zimWq_Gw@mail.gmail.com","subject":"Fwd: [PATCH] git-prompt.sh: Omit prompt for ignored directories","fromName":"Jess Austin","fromEmail":"jess.austin@gmail.com","sentAt":"2014-10-08T21:37:23Z","receivedAt":"2014-10-08T21:37:23Z","isPatch":true,"sender":{"key":"jess.austin@gmail.com","avatar":"https://avatars.githubusercontent.com/u/295056?v=4"},"body":"On Wed, Oct 8, 2014 at 4:12 PM, Richard Hansen <rhansen@bbn.com> wrote:\n>\n> On 2014-10-08 15:04, Jess Austin wrote:\n> > Introduce a new environmental variable, GIT_PS1_OMITIGNORED, which\n> > tells __git_ps1 to display nothing when the current directory is\n> > set (e.g. via .gitignore) to be ignored by git. In the absence of\n> > GIT_PS1_OMITIGNORED this change has no effect.\n> >\n> > Many people manage e.g. dotfiles in their home directory with git.\n> > This causes the prompt generated by __git_ps1 to refer to that \"top\n> > level\" repo while working in any descendant directory. That can be\n> > distracting, so this patch helps one shut off that noise.\n>\n> Interesting idea, though I would prefer this to be configurable on a\n> per-repository basis.  (I wouldn't want to hide the prompt in any\n> repository besides my home repository.)\n\nSorry my description was unclear. Let's say you have a repo in \"~\",\nand another in \"~/projects/foo\". Also, the file \"~/.gitignore\" has the line\n\"projects/\" in it. In this case, you'd see repo info in your prompt while\nin \"~\" or in \"~/projects/foo\", but not if you were in \"~/projects\". In that\nsense, the prompt is not distracting you with the status of the top-level\nrepo when you're not looking at anything in that repo.\n\n>\n> I'm not a big fan of the name \"OMITIGNORED\" (it's not immediately\n> obvious what this means), but I can't think of anything better off the\n> top of my head...\n\nI'm definitely open to suggestions.\n\ncheers,\nJess\n\nps. sorry for the html before\n\n> > Signed-off-by: Jess Austin <jess.austin@gmail.com>\n> > ---\n> >  contrib/completion/git-prompt.sh |  9 +++++++++\n> >  t/t9903-bash-prompt.sh           | 21 +++++++++++++++++++++\n> >  2 files changed, 30 insertions(+)\n> >\n> > diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\n> > index c5473dc..6a26cb4 100644\n> > --- a/contrib/completion/git-prompt.sh\n> > +++ b/contrib/completion/git-prompt.sh\n> > @@ -84,6 +84,10 @@\n> >  # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on\n> >  # the colored output of \"git status -sb\" and are available only when\n> >  # using __git_ps1 for PROMPT_COMMAND or precmd.\n> > +#\n> > +# If you would like __git_ps1 to do nothing in the case when the current\n> > +# directory is set up to be ignored by git, then set GIT_PS1_OMITIGNORED\n> > +# to a nonempty value.\n> >\n> >  # check whether printf supports -v\n> >  __git_printf_supports_v=\n> > @@ -501,6 +505,11 @@ __git_ps1 ()\n> >       local f=\"$w$i$s$u\"\n> >       local gitstring=\"$c$b${f:+$z$f}$r$p\"\n> >\n> > +     if [ -n \"$(git check-ignore .)\" ] && [ -n \"${GIT_PS1_OMITIGNORED}\" ]\n> > +     then\n> > +             printf_format=\"\"\n> > +     fi\n> > +\n> >       if [ $pcmode = yes ]; then\n> >               if [ \"${__git_printf_supports_v-}\" != yes ]; then\n> >                       gitstring=$(printf -- \"$printf_format\" \"$gitstring\")\n> > diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\n> > index 9150984..55bcb6b 100755\n> > --- a/t/t9903-bash-prompt.sh\n> > +++ b/t/t9903-bash-prompt.sh\n> > @@ -35,6 +35,8 @@ test_expect_success 'setup for prompt tests' '\n> >       git commit -m \"another b2\" file &&\n> >       echo 000 >file &&\n> >       git commit -m \"yet another b2\" file &&\n> > +     mkdir ignored_dir &&\n> > +     echo \"ignored_dir/\" >> .gitignore &&\n> >       git checkout master\n> >  '\n> >\n> > @@ -588,4 +590,23 @@ test_expect_success 'prompt - zsh color pc mode' '\n> >       test_cmp expected \"$actual\"\n> >  '\n> >\n> > +test_expect_success 'prompt - prompt omitted in ignored directory' '\n> > +     printf \"\" >expected &&\n> > +     (\n> > +             cd ignored_dir &&\n> > +             GIT_PS1_OMITIGNORED=y &&\n> > +             __git_ps1 >\"$actual\"\n> > +     ) &&\n> > +     test_cmp expected \"$actual\"\n> > +'\n> > +\n> > +test_expect_success 'prompt - prompt not omitted without GIT_PS1_OMITIGNORED' '\n> > +     printf \" (master)\" >expected &&\n> > +     (\n> > +             cd ignored_dir &&\n> > +             __git_ps1 >\"$actual\"\n> > +     ) &&\n> > +     test_cmp expected \"$actual\"\n> > +'\n> > +\n> >  test_done\n> >\n>\n"},{"id":"250411","messageId":"54361F30.8020603@bbn.com","threadId":"37693","inReplyTo":"CANp8Xb9MUbQCVZRNYibFBibzTFF=56BqNFFC1G2iTF7WGBNi7g@mail.gmail.com","subject":"Re: [PATCH] git-prompt.sh: Omit prompt for ignored directories","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2014-10-09T05:37:52Z","receivedAt":"2014-10-09T05:37:52Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"On 2014-10-08 17:37, Jess Austin wrote:\n> On Wed, Oct 8, 2014 at 4:12 PM, Richard Hansen <rhansen@bbn.com> wrote:\n>> On 2014-10-08 15:04, Jess Austin wrote:\n>>> Introduce a new environmental variable, GIT_PS1_OMITIGNORED, which\n>>> tells __git_ps1 to display nothing when the current directory is\n>>> set (e.g. via .gitignore) to be ignored by git. In the absence of\n>>> GIT_PS1_OMITIGNORED this change has no effect.\n>>>\n>>> Many people manage e.g. dotfiles in their home directory with git.\n>>> This causes the prompt generated by __git_ps1 to refer to that \"top\n>>> level\" repo while working in any descendant directory. That can be\n>>> distracting, so this patch helps one shut off that noise.\n>>\n>> Interesting idea, though I would prefer this to be configurable on a\n>> per-repository basis.  (I wouldn't want to hide the prompt in any\n>> repository besides my home repository.)\n> \n> Sorry my description was unclear. Let's say you have a repo in \"~\",\n> and another in \"~/projects/foo\". Also, the file \"~/.gitignore\" has the line\n> \"projects/\" in it. In this case, you'd see repo info in your prompt while\n> in \"~\" or in \"~/projects/foo\", but not if you were in \"~/projects\". In that\n> sense, the prompt is not distracting you with the status of the top-level\n> repo when you're not looking at anything in that repo.\n\nI understand; I was concerned about this case:\n\n$ PS1='\\n\\w$(__git_ps1 \" (%s)\")\\n\\$ '\n\n/home/rhansen/projects (dotfiles)\n$ GIT_PS1_OMITIGNORED=y\n\n/home/rhansen/projects              <-- Git prompt goes away as desired\n$ cd foo\n\n/home/rhansen/projects/foo (master) <-- Git prompt back as expected\n$ echo ignored/ >>.gitignore && mkdir -p ignored && cd ignored\n\n/home/rhansen/projects/foo/ignored  <-- I want the Git prompt here\n$\n\nIn other words:  If I were to use this feature, I'd want to be able to\nhide the prompt when I'm in an ignored directory in my dotfiles work\ntree, but show the prompt when I'm in an ignored directory in any other\nwork tree.\n\n-Richard\n"},{"id":"250422","messageId":"CANp8Xb_kdpzYjWZxoWFtT+UWwMPpFD0znkoEKVpdukGf61Preg@mail.gmail.com","threadId":"37693","inReplyTo":"54361F30.8020603@bbn.com","subject":"Re: [PATCH] git-prompt.sh: Omit prompt for ignored directories","fromName":"Jess Austin","fromEmail":"jess.austin@gmail.com","sentAt":"2014-10-09T10:27:16Z","receivedAt":"2014-10-09T10:27:16Z","isPatch":true,"sender":{"key":"jess.austin@gmail.com","avatar":"https://avatars.githubusercontent.com/u/295056?v=4"},"body":"On Thu, Oct 9, 2014 at 12:37 AM, Richard Hansen <rhansen@bbn.com> wrote:\n> On 2014-10-08 17:37, Jess Austin wrote:\n>> On Wed, Oct 8, 2014 at 4:12 PM, Richard Hansen <rhansen@bbn.com> wrote:\n>>> On 2014-10-08 15:04, Jess Austin wrote:\n>>>> Introduce a new environmental variable, GIT_PS1_OMITIGNORED, which\n>>>> tells __git_ps1 to display nothing when the current directory is\n>>>> set (e.g. via .gitignore) to be ignored by git. In the absence of\n>>>> GIT_PS1_OMITIGNORED this change has no effect.\n>>>>\n>>>> Many people manage e.g. dotfiles in their home directory with git.\n>>>> This causes the prompt generated by __git_ps1 to refer to that \"top\n>>>> level\" repo while working in any descendant directory. That can be\n>>>> distracting, so this patch helps one shut off that noise.\n>>>\n>>> Interesting idea, though I would prefer this to be configurable on a\n>>> per-repository basis.  (I wouldn't want to hide the prompt in any\n>>> repository besides my home repository.)\n>>\n>> Sorry my description was unclear. Let's say you have a repo in \"~\",\n>> and another in \"~/projects/foo\". Also, the file \"~/.gitignore\" has the line\n>> \"projects/\" in it. In this case, you'd see repo info in your prompt while\n>> in \"~\" or in \"~/projects/foo\", but not if you were in \"~/projects\". In that\n>> sense, the prompt is not distracting you with the status of the top-level\n>> repo when you're not looking at anything in that repo.\n>\n> I understand; I was concerned about this case:\n>\n> $ PS1='\\n\\w$(__git_ps1 \" (%s)\")\\n\\$ '\n>\n> /home/rhansen/projects (dotfiles)\n> $ GIT_PS1_OMITIGNORED=y\n>\n> /home/rhansen/projects              <-- Git prompt goes away as desired\n> $ cd foo\n>\n> /home/rhansen/projects/foo (master) <-- Git prompt back as expected\n> $ echo ignored/ >>.gitignore && mkdir -p ignored && cd ignored\n>\n> /home/rhansen/projects/foo/ignored  <-- I want the Git prompt here\n> $\n>\n> In other words:  If I were to use this feature, I'd want to be able to\n> hide the prompt when I'm in an ignored directory in my dotfiles work\n> tree, but show the prompt when I'm in an ignored directory in any other\n> work tree.\n\nWould you want this configured in each repo (i.e. via a line in \".git/config\"),\nor would you prefer something global so that it only need be set in one\nplace? I'm not sure how the latter technique would work, so if that seems\nbetter please advise on how to go about that.\n\ncheers,\nJess\n"},{"id":"250460","messageId":"5437078B.6020307@bbn.com","threadId":"37693","inReplyTo":"CANp8Xb_kdpzYjWZxoWFtT+UWwMPpFD0znkoEKVpdukGf61Preg@mail.gmail.com","subject":"Re: [PATCH] git-prompt.sh: Omit prompt for ignored directories","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2014-10-09T22:09:15Z","receivedAt":"2014-10-09T22:09:15Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"On 2014-10-09 06:27, Jess Austin wrote:\n> On Thu, Oct 9, 2014 at 12:37 AM, Richard Hansen <rhansen@bbn.com> wrote:\n>> On 2014-10-08 17:37, Jess Austin wrote:\n>>> On Wed, Oct 8, 2014 at 4:12 PM, Richard Hansen <rhansen@bbn.com> wrote:\n>>>> On 2014-10-08 15:04, Jess Austin wrote:\n>>>>> Introduce a new environmental variable, GIT_PS1_OMITIGNORED, which\n>>>>> tells __git_ps1 to display nothing when the current directory is\n>>>>> set (e.g. via .gitignore) to be ignored by git. In the absence of\n>>>>> GIT_PS1_OMITIGNORED this change has no effect.\n>>>>>\n>>>>> Many people manage e.g. dotfiles in their home directory with git.\n>>>>> This causes the prompt generated by __git_ps1 to refer to that \"top\n>>>>> level\" repo while working in any descendant directory. That can be\n>>>>> distracting, so this patch helps one shut off that noise.\n...\n>>\n>> $ PS1='\\n\\w$(__git_ps1 \" (%s)\")\\n\\$ '\n>>\n>> /home/rhansen/projects (dotfiles)\n>> $ GIT_PS1_OMITIGNORED=y\n>>\n>> /home/rhansen/projects              <-- Git prompt goes away as desired\n>> $ cd foo\n>>\n>> /home/rhansen/projects/foo (master) <-- Git prompt back as expected\n>> $ echo ignored/ >>.gitignore && mkdir -p ignored && cd ignored\n>>\n>> /home/rhansen/projects/foo/ignored  <-- I want the Git prompt here\n>> $\n>>\n>> In other words:  If I were to use this feature, I'd want to be able to\n>> hide the prompt when I'm in an ignored directory in my dotfiles work\n>> tree, but show the prompt when I'm in an ignored directory in any other\n>> work tree.\n> \n> Would you want this configured in each repo (i.e. via a line in \".git/config\"),\n> or would you prefer something global so that it only need be set in one\n> place? I'm not sure how the latter technique would work, so if that seems\n> better please advise on how to go about that.\n\nA 'git config' variable is fine.  The bash.showDirtyState,\nbash.showUntrackedFiles, and bash.showUpstream config variables seem\nlike good examples to follow.\n\n-Richard\n"},{"id":"250597","messageId":"1413253924-8065-1-git-send-email-jess.austin@gmail.com","threadId":"37693","inReplyTo":"5437078B.6020307@bbn.com","subject":"[PATCH] git-prompt.sh: Hide prompt for ignored pwd","fromName":"Jess Austin","fromEmail":"jess.austin@gmail.com","sentAt":"2014-10-14T02:32:04Z","receivedAt":"2014-10-14T02:32:04Z","isPatch":true,"sender":{"key":"jess.austin@gmail.com","avatar":"https://avatars.githubusercontent.com/u/295056?v=4"},"body":"Set __git_ps1 to display nothing when present working directory is\nignored, triggered by either the new environmental variable\nGIT_PS1_HIDE_ON_IGNORED_PWD or the new repository configuration\nvariable bash.hideOnIgnoredPwd (or both). In the absence of these\nsettings this change has no effect.\n\nMany people manage e.g. dotfiles in their home directory with git.\nThis causes the prompt generated by __git_ps1 to refer to that \"top\nlevel\" repo while working in any descendant directory. That can be\ndistracting, so this patch helps one shut off that noise.\n\nSigned-off-by: Jess Austin <jess.austin@gmail.com>\n---\nOn Thu, Oct 9, 2014 at 5:09 PM, Richard Hansen <rhansen@bbn.com> wrote:\n> On 2014-10-09 06:27, Jess Austin wrote:\n>> Would you want this configured in each repo (i.e. via a line in \".git/config\"),\n>> or would you prefer something global so that it only need be set in one\n>> place? I'm not sure how the latter technique would work, so if that seems\n>> better please advise on how to go about that.\n>\n> A 'git config' variable is fine.  The bash.showDirtyState,\n> bash.showUntrackedFiles, and bash.showUpstream config variables seem\n> like good examples to follow.\n\nI think this is what you meant. I changed the name of the envvar. Now the\nvariables are GIT_PS1_HIDE_ON_IGNORED_PWD and bash.hideOnIgnoredPwd. I\nadmit these are still kind of unwieldy, but maybe now they're more descriptive?\n\nPlease advise!\n\ncheers,\nJess\n\n contrib/completion/git-prompt.sh | 12 ++++++++++++\n t/t9903-bash-prompt.sh           | 42 ++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 54 insertions(+)\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex c5473dc..d7559ff 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -84,6 +84,11 @@\n # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on\n # the colored output of \"git status -sb\" and are available only when\n # using __git_ps1 for PROMPT_COMMAND or precmd.\n+#\n+# If you would like __git_ps1 to do nothing in the case when the current\n+# directory is set up to be ignored by git, then set\n+# GIT_PS1_HIDE_ON_IGNORED_PWD to a nonempty value, or set\n+# bash.hideOnIgnoredPwd to true in the repository configuration.\n \n # check whether printf supports -v\n __git_printf_supports_v=\n@@ -501,6 +506,13 @@ __git_ps1 ()\n \tlocal f=\"$w$i$s$u\"\n \tlocal gitstring=\"$c$b${f:+$z$f}$r$p\"\n \n+\tif [ -n \"$(git check-ignore .)\" ] &&\n+\t   ( [ -n \"${GIT_PS1_HIDE_ON_IGNORED_PWD}\" ] ||\n+\t     [ \"$(git config --bool bash.hideOnIgnoredPwd)\" = \"true\" ] )\n+\tthen\n+\t\tprintf_format=\"\"\n+\tfi\n+\n \tif [ $pcmode = yes ]; then\n \t\tif [ \"${__git_printf_supports_v-}\" != yes ]; then\n \t\t\tgitstring=$(printf -- \"$printf_format\" \"$gitstring\")\ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex 9150984..a8ef8a3 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -35,6 +35,8 @@ test_expect_success 'setup for prompt tests' '\n \tgit commit -m \"another b2\" file &&\n \techo 000 >file &&\n \tgit commit -m \"yet another b2\" file &&\n+\tmkdir ignored_dir &&\n+\techo \"ignored_dir/\" >> .gitignore &&\n \tgit checkout master\n '\n \n@@ -588,4 +590,44 @@ test_expect_success 'prompt - zsh color pc mode' '\n \ttest_cmp expected \"$actual\"\n '\n \n+test_expect_success 'prompt - hide on ignored pwd - shell variable unset with config disabled' '\n+\tprintf \" (master)\" >expected &&\n+\t(\n+\t\tcd ignored_dir &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success 'prompt - hide on ignored pwd - shell variable unset with config enabled' '\n+\tprintf \"\" >expected &&\n+\ttest_config bash.hideOnIgnoredPwd true &&\n+\t(\n+\t\tcd ignored_dir &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success 'prompt - hide on ignored pwd - shell variable set with config disabled' '\n+\tprintf \"\" >expected &&\n+\t(\n+\t\tcd ignored_dir &&\n+\t\tGIT_PS1_HIDE_ON_IGNORED_PWD=y &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success 'prompt - hide on ignored pwd - shell variable set with config enabled' '\n+\tprintf \"\" >expected &&\n+\ttest_config bash.hideOnIgnoredPwd true &&\n+\t(\n+\t\tcd ignored_dir &&\n+\t\tGIT_PS1_HIDE_ON_IGNORED_PWD=y &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n test_done\n-- \n1.9.1\n"},{"id":"250621","messageId":"543D6FD7.3090306@kdbg.org","threadId":"37693","inReplyTo":"1413253924-8065-1-git-send-email-jess.austin@gmail.com","subject":"Re: [PATCH] git-prompt.sh: Hide prompt for ignored pwd","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2014-10-14T18:47:51Z","receivedAt":"2014-10-14T18:47:51Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 14.10.2014 um 04:32 schrieb Jess Austin:\n> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\n> index c5473dc..d7559ff 100644\n> --- a/contrib/completion/git-prompt.sh\n> +++ b/contrib/completion/git-prompt.sh\n> @@ -84,6 +84,11 @@\n>  # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on\n>  # the colored output of \"git status -sb\" and are available only when\n>  # using __git_ps1 for PROMPT_COMMAND or precmd.\n> +#\n> +# If you would like __git_ps1 to do nothing in the case when the current\n> +# directory is set up to be ignored by git, then set\n> +# GIT_PS1_HIDE_ON_IGNORED_PWD to a nonempty value, or set\n> +# bash.hideOnIgnoredPwd to true in the repository configuration.\n>  \n>  # check whether printf supports -v\n>  __git_printf_supports_v=\n> @@ -501,6 +506,13 @@ __git_ps1 ()\n>  \tlocal f=\"$w$i$s$u\"\n>  \tlocal gitstring=\"$c$b${f:+$z$f}$r$p\"\n>  \n> +\tif [ -n \"$(git check-ignore .)\" ] &&\n> +\t   ( [ -n \"${GIT_PS1_HIDE_ON_IGNORED_PWD}\" ] ||\n> +\t     [ \"$(git config --bool bash.hideOnIgnoredPwd)\" = \"true\" ] )\n\nAhem, no. Please do not punish users who are not interested in the new\nfeature with two new processes every time __git_ps() is run. Think of\nWindows where fork() is really, *really* expensive.\n\nBTW, you can write '{ foo || bar; }' to bracket a || chain without a\nsub-process.\n\n> +\tthen\n> +\t\tprintf_format=\"\"\n> +\tfi\n> +\n>  \tif [ $pcmode = yes ]; then\n>  \t\tif [ \"${__git_printf_supports_v-}\" != yes ]; then\n>  \t\t\tgitstring=$(printf -- \"$printf_format\" \"$gitstring\")\n\n-- Hannes\n"},{"id":"250622","messageId":"543D7497.2020001@bbn.com","threadId":"37693","inReplyTo":"543D6FD7.3090306@kdbg.org","subject":"Re: [PATCH] git-prompt.sh: Hide prompt for ignored pwd","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2014-10-14T19:08:07Z","receivedAt":"2014-10-14T19:08:07Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"On 2014-10-14 14:47, Johannes Sixt wrote:\n> Am 14.10.2014 um 04:32 schrieb Jess Austin:\n>> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\n>> index c5473dc..d7559ff 100644\n>> --- a/contrib/completion/git-prompt.sh\n>> +++ b/contrib/completion/git-prompt.sh\n>> @@ -84,6 +84,11 @@\n>>  # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on\n>>  # the colored output of \"git status -sb\" and are available only when\n>>  # using __git_ps1 for PROMPT_COMMAND or precmd.\n>> +#\n>> +# If you would like __git_ps1 to do nothing in the case when the current\n>> +# directory is set up to be ignored by git, then set\n>> +# GIT_PS1_HIDE_ON_IGNORED_PWD to a nonempty value, or set\n>> +# bash.hideOnIgnoredPwd to true in the repository configuration.\n>>  \n>>  # check whether printf supports -v\n>>  __git_printf_supports_v=\n>> @@ -501,6 +506,13 @@ __git_ps1 ()\n>>  \tlocal f=\"$w$i$s$u\"\n>>  \tlocal gitstring=\"$c$b${f:+$z$f}$r$p\"\n>>  \n>> +\tif [ -n \"$(git check-ignore .)\" ] &&\n>> +\t   ( [ -n \"${GIT_PS1_HIDE_ON_IGNORED_PWD}\" ] ||\n>> +\t     [ \"$(git config --bool bash.hideOnIgnoredPwd)\" = \"true\" ] )\n> \n> Ahem, no. Please do not punish users who are not interested in the new\n> feature with two new processes every time __git_ps() is run. Think of\n> Windows where fork() is really, *really* expensive.\n\nIs this why bash.showDirtyState and friends aren't checked unless the\ncorresponding environment variable is set to a non-empty value?\n\nRegardless, it would be nice if the behavior matched the other bash.*\nvariables (only check the bash.* variable if the corresponding\nenvironment variable is set, and default to true).  The following should\nfix it:\n\n    if [ -n \"${GIT_PS1_HIDE_ON_IGNORED_PWD}\" ] &&\n       [ \"$(git config --bool bash.hideOnIgnoredPwd)\" != \"false\" ] &&\n       [ \"$(git check-ignore .)\" ]\n    then\n            ...\n\n-Richard\n\n> \n> BTW, you can write '{ foo || bar; }' to bracket a || chain without a\n> sub-process.\n> \n>> +\tthen\n>> +\t\tprintf_format=\"\"\n>> +\tfi\n>> +\n>>  \tif [ $pcmode = yes ]; then\n>>  \t\tif [ \"${__git_printf_supports_v-}\" != yes ]; then\n>>  \t\t\tgitstring=$(printf -- \"$printf_format\" \"$gitstring\")\n> \n> -- Hannes\n> \n"},{"id":"250624","messageId":"543D77CC.8060803@bbn.com","threadId":"37693","inReplyTo":"1413253924-8065-1-git-send-email-jess.austin@gmail.com","subject":"Re: [PATCH] git-prompt.sh: Hide prompt for ignored pwd","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2014-10-14T19:21:48Z","receivedAt":"2014-10-14T19:21:48Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"On 2014-10-13 22:32, Jess Austin wrote:\n> Set __git_ps1 to display nothing when present working directory is\n> ignored, triggered by either the new environmental variable\n> GIT_PS1_HIDE_ON_IGNORED_PWD or the new repository configuration\n> variable bash.hideOnIgnoredPwd (or both). In the absence of these\n> settings this change has no effect.\n> \n> Many people manage e.g. dotfiles in their home directory with git.\n> This causes the prompt generated by __git_ps1 to refer to that \"top\n> level\" repo while working in any descendant directory. That can be\n> distracting, so this patch helps one shut off that noise.\n> \n> Signed-off-by: Jess Austin <jess.austin@gmail.com>\n> ---\n> On Thu, Oct 9, 2014 at 5:09 PM, Richard Hansen <rhansen@bbn.com> wrote:\n>> On 2014-10-09 06:27, Jess Austin wrote:\n>>> Would you want this configured in each repo (i.e. via a line in \".git/config\"),\n>>> or would you prefer something global so that it only need be set in one\n>>> place? I'm not sure how the latter technique would work, so if that seems\n>>> better please advise on how to go about that.\n>>\n>> A 'git config' variable is fine.  The bash.showDirtyState,\n>> bash.showUntrackedFiles, and bash.showUpstream config variables seem\n>> like good examples to follow.\n> \n> I think this is what you meant. I changed the name of the envvar. Now the\n> variables are GIT_PS1_HIDE_ON_IGNORED_PWD and bash.hideOnIgnoredPwd. I\n> admit these are still kind of unwieldy, but maybe now they're more descriptive?\n\nI do prefer the new names.  They are long, but how often will someone\nhave to type it?  In this case it's better to be descriptive than to be\nshort.  (I wonder if adding two letters would improve readability\nfurther:  GIT_PS1_HIDE_WHEN_PWD_IGNORED and bash.hideWhenPwdIgnored.)\n\nTo avoid scaring people who might not want this feature enabled, I\nrecommend changing the subject line to something like this:\n\n    git-prompt.sh: Option to hide prompt for ignored pwd\n\n> \n> Please advise!\n> \n> cheers,\n> Jess\n> \n>  contrib/completion/git-prompt.sh | 12 ++++++++++++\n>  t/t9903-bash-prompt.sh           | 42 ++++++++++++++++++++++++++++++++++++++++\n>  2 files changed, 54 insertions(+)\n> \n> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\n> index c5473dc..d7559ff 100644\n> --- a/contrib/completion/git-prompt.sh\n> +++ b/contrib/completion/git-prompt.sh\n> @@ -84,6 +84,11 @@\n>  # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on\n>  # the colored output of \"git status -sb\" and are available only when\n>  # using __git_ps1 for PROMPT_COMMAND or precmd.\n> +#\n> +# If you would like __git_ps1 to do nothing in the case when the current\n> +# directory is set up to be ignored by git, then set\n> +# GIT_PS1_HIDE_ON_IGNORED_PWD to a nonempty value, or set\n> +# bash.hideOnIgnoredPwd to true in the repository configuration.\n\nAs mentioned in my previous email, I would prefer the code to follow the\nbehavior of the other config variables (the environment variable has to\nbe set *and* the config variable has to be non-false).\n\n>  \n>  # check whether printf supports -v\n>  __git_printf_supports_v=\n> @@ -501,6 +506,13 @@ __git_ps1 ()\n>  \tlocal f=\"$w$i$s$u\"\n>  \tlocal gitstring=\"$c$b${f:+$z$f}$r$p\"\n>  \n> +\tif [ -n \"$(git check-ignore .)\" ] &&\n\nRather than:\n\n    [ -n \"$(git check-ignore .)\" ]\n\nI would prefer:\n\n    git check-ignore -q .\n\nFor example:\n\n    if [ -n \"${GIT_PS1_HIDE_ON_IGNORED_PWD}\" ] &&\n       [ \"$(git config --bool bash.hideOnIgnoredPwd)\" != \"false\" ] &&\n       git check-ignore -q .\n    then\n            ...\n\n-Richard\n\n\n> +\t   ( [ -n \"${GIT_PS1_HIDE_ON_IGNORED_PWD}\" ] ||\n> +\t     [ \"$(git config --bool bash.hideOnIgnoredPwd)\" = \"true\" ] )\n> +\tthen\n> +\t\tprintf_format=\"\"\n> +\tfi\n> +\n>  \tif [ $pcmode = yes ]; then\n>  \t\tif [ \"${__git_printf_supports_v-}\" != yes ]; then\n>  \t\t\tgitstring=$(printf -- \"$printf_format\" \"$gitstring\")\n> diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\n> index 9150984..a8ef8a3 100755\n> --- a/t/t9903-bash-prompt.sh\n> +++ b/t/t9903-bash-prompt.sh\n> @@ -35,6 +35,8 @@ test_expect_success 'setup for prompt tests' '\n>  \tgit commit -m \"another b2\" file &&\n>  \techo 000 >file &&\n>  \tgit commit -m \"yet another b2\" file &&\n> +\tmkdir ignored_dir &&\n> +\techo \"ignored_dir/\" >> .gitignore &&\n>  \tgit checkout master\n>  '\n>  \n> @@ -588,4 +590,44 @@ test_expect_success 'prompt - zsh color pc mode' '\n>  \ttest_cmp expected \"$actual\"\n>  '\n>  \n> +test_expect_success 'prompt - hide on ignored pwd - shell variable unset with config disabled' '\n> +\tprintf \" (master)\" >expected &&\n> +\t(\n> +\t\tcd ignored_dir &&\n> +\t\t__git_ps1 >\"$actual\"\n> +\t) &&\n> +\ttest_cmp expected \"$actual\"\n> +'\n> +\n> +test_expect_success 'prompt - hide on ignored pwd - shell variable unset with config enabled' '\n> +\tprintf \"\" >expected &&\n> +\ttest_config bash.hideOnIgnoredPwd true &&\n> +\t(\n> +\t\tcd ignored_dir &&\n> +\t\t__git_ps1 >\"$actual\"\n> +\t) &&\n> +\ttest_cmp expected \"$actual\"\n> +'\n> +\n> +test_expect_success 'prompt - hide on ignored pwd - shell variable set with config disabled' '\n> +\tprintf \"\" >expected &&\n> +\t(\n> +\t\tcd ignored_dir &&\n> +\t\tGIT_PS1_HIDE_ON_IGNORED_PWD=y &&\n> +\t\t__git_ps1 >\"$actual\"\n> +\t) &&\n> +\ttest_cmp expected \"$actual\"\n> +'\n> +\n> +test_expect_success 'prompt - hide on ignored pwd - shell variable set with config enabled' '\n> +\tprintf \"\" >expected &&\n> +\ttest_config bash.hideOnIgnoredPwd true &&\n> +\t(\n> +\t\tcd ignored_dir &&\n> +\t\tGIT_PS1_HIDE_ON_IGNORED_PWD=y &&\n> +\t\t__git_ps1 >\"$actual\"\n> +\t) &&\n> +\ttest_cmp expected \"$actual\"\n> +'\n> +\n>  test_done\n> \n"},{"id":"250661","messageId":"1413345993-14393-1-git-send-email-jess.austin@gmail.com","threadId":"37693","inReplyTo":"543D77CC.8060803@bbn.com","subject":"[PATCH] git-prompt.sh: Option to hide prompt for ignored pwd","fromName":"Jess Austin","fromEmail":"jess.austin@gmail.com","sentAt":"2014-10-15T04:06:33Z","receivedAt":"2014-10-15T04:06:33Z","isPatch":true,"sender":{"key":"jess.austin@gmail.com","avatar":"https://avatars.githubusercontent.com/u/295056?v=4"},"body":"Optionally set __git_ps1 to display nothing when present working\ndirectory is ignored, triggered by the new environmental variable\nGIT_PS1_HIDE_IF_PWD_IGNORED. This environmental variable may be\noverridden on any repository by setting bash.hideIfPwdIgnored to\n\"false\". In the absence of GIT_PS1_HIDE_IF_PWD_IGNORED this change\nhas no effect.\n\nMany people manage e.g. dotfiles in their home directory with git.\nThis causes the prompt generated by __git_ps1 to refer to that \"top\nlevel\" repo while working in any descendant directory. That can be\ndistracting, so this patch helps one shut off that noise.\n\nSigned-off-by: Jess Austin <jess.austin@gmail.com>\n---\nOn Tue, Oct 14, 2014 at 2:08 PM, Richard Hansen <rhansen@bbn.com> wrote:\n> On 2014-10-14 14:47, Johannes Sixt wrote:\n>> Ahem, no. Please do not punish users who are not interested in the new\n>> feature with two new processes every time __git_ps() is run. Think of\n>> Windows where fork() is really, *really* expensive.\n> Regardless, it would be nice if the behavior matched the other bash.*\n> variables (only check the bash.* variable if the corresponding\n> environment variable is set, and default to true).  The following should\n> fix it:\n>\n>     if [ -n \"${GIT_PS1_HIDE_ON_IGNORED_PWD}\" ] &&\n>        [ \"$(git config --bool bash.hideOnIgnoredPwd)\" != \"false\" ] &&\n>        [ \"$(git check-ignore .)\" ]\n>     then\nThanks for helping me understand this! I think I have it correct now.\n\n\nOn Tue, Oct 14, 2014 at 2:21 PM, Richard Hansen <rhansen@bbn.com> wrote:\n> I do prefer the new names.  They are long, but how often will someone\n> have to type it?  In this case it's better to be descriptive than to be\n> short.  (I wonder if adding two letters would improve readability\n> further:  GIT_PS1_HIDE_WHEN_PWD_IGNORED and bash.hideWhenPwdIgnored.)\n\nWe got those two letters back with GIT_PS1_HIDE_IF_PWD_IGNORED and\nbash.hideIfPwdIgnored.\n\n> To avoid scaring people who might not want this feature enabled, I\n> recommend changing the subject line to something like this:\n>\n>     git-prompt.sh: Option to hide prompt for ignored pwd\n\nGood idea!\n\n\n contrib/completion/git-prompt.sh | 12 ++++++++++++\n t/t9903-bash-prompt.sh           | 42 ++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 54 insertions(+)\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex c5473dc..151218b 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -84,6 +84,11 @@\n # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on\n # the colored output of \"git status -sb\" and are available only when\n # using __git_ps1 for PROMPT_COMMAND or precmd.\n+#\n+# If you would like __git_ps1 to do nothing in the case when the current\n+# directory is set up to be ignored by git, then set\n+# GIT_PS1_HIDE_IF_PWD_IGNORED to a nonempty value. Override this on the\n+# repository level by setting bash.hideIfPwdIgnored to \"false\".\n \n # check whether printf supports -v\n __git_printf_supports_v=\n@@ -501,6 +506,13 @@ __git_ps1 ()\n \tlocal f=\"$w$i$s$u\"\n \tlocal gitstring=\"$c$b${f:+$z$f}$r$p\"\n \n+\tif [ -n \"${GIT_PS1_HIDE_IF_PWD_IGNORED}\" ] &&\n+\t   [ \"$(git config --bool bash.hideIfPwdIgnored)\" != \"false\" ] &&\n+\t   git check-ignore -q .\n+\tthen\n+\t\tprintf_format=\"\"\n+\tfi\n+\n \tif [ $pcmode = yes ]; then\n \t\tif [ \"${__git_printf_supports_v-}\" != yes ]; then\n \t\t\tgitstring=$(printf -- \"$printf_format\" \"$gitstring\")\ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex 9150984..88a75cf 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -35,6 +35,8 @@ test_expect_success 'setup for prompt tests' '\n \tgit commit -m \"another b2\" file &&\n \techo 000 >file &&\n \tgit commit -m \"yet another b2\" file &&\n+\tmkdir ignored_dir &&\n+\techo \"ignored_dir/\" >> .gitignore &&\n \tgit checkout master\n '\n \n@@ -588,4 +590,44 @@ test_expect_success 'prompt - zsh color pc mode' '\n \ttest_cmp expected \"$actual\"\n '\n \n+test_expect_success 'prompt - hide if pwd ignored - shell variable unset with config disabled' '\n+\tprintf \" (master)\" >expected &&\n+\ttest_config bash.hideIfPwdIgnored false &&\n+\t(\n+\t\tcd ignored_dir &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success 'prompt - hide if pwd ignored - shell variable unset with config unset' '\n+\tprintf \" (master)\" >expected &&\n+\t(\n+\t\tcd ignored_dir &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success 'prompt - hide if pwd ignored - shell variable set with config disabled' '\n+\tprintf \" (master)\" >expected &&\n+\ttest_config bash.hideIfPwdIgnored false &&\n+\t(\n+\t\tcd ignored_dir &&\n+\t\tGIT_PS1_HIDE_IF_PWD_IGNORED=y &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success 'prompt - hide if pwd ignored - shell variable set with config unset' '\n+\tprintf \"\" >expected &&\n+\t(\n+\t\tcd ignored_dir &&\n+\t\tGIT_PS1_HIDE_IF_PWD_IGNORED=y &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n test_done\n-- \n1.9.1\n"},{"id":"250702","messageId":"543ED906.403@bbn.com","threadId":"37693","inReplyTo":"1413345993-14393-1-git-send-email-jess.austin@gmail.com","subject":"Re: [PATCH] git-prompt.sh: Option to hide prompt for ignored pwd","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2014-10-15T20:28:54Z","receivedAt":"2014-10-15T20:28:54Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"On 2014-10-15 00:06, Jess Austin wrote:\n> @@ -501,6 +506,13 @@ __git_ps1 ()\n>  \tlocal f=\"$w$i$s$u\"\n>  \tlocal gitstring=\"$c$b${f:+$z$f}$r$p\"\n>  \n> +\tif [ -n \"${GIT_PS1_HIDE_IF_PWD_IGNORED}\" ] &&\n> +\t   [ \"$(git config --bool bash.hideIfPwdIgnored)\" != \"false\" ] &&\n> +\t   git check-ignore -q .\n> +\tthen\n> +\t\tprintf_format=\"\"\n> +\tfi\n> +\n>  \tif [ $pcmode = yes ]; then\n>  \t\tif [ \"${__git_printf_supports_v-}\" != yes ]; then\n>  \t\t\tgitstring=$(printf -- \"$printf_format\" \"$gitstring\")\n\nThis is broken in pcmode due to a Bash bug.  The command:\n    printf -v foo \"\" asdf\nis a no-op in Bash.  The variable foo is never changed in any way --\nit is neither unset nor set to the empty string.\n\nAlso, I noticed that I get an error message if I cd into .git:\n    fatal: This operation must be run in a work tree\n\nI think the following change will fix the above issues, and it has the\nadvantage of avoiding unnecessary work if the directory is ignored:\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex 6a4ce53..68ac82a 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -374,6 +374,17 @@ __git_ps1 ()\n \tlocal inside_gitdir=\"${repo_info##*$'\\n'}\"\n \tlocal g=\"${repo_info%$'\\n'*}\"\n \n+\tif [ \"true\" = \"$inside_worktree\" ] &&\n+\t   [ -n \"${GIT_PS1_HIDE_IF_PWD_IGNORED}\" ] &&\n+\t   [ \"$(git config --bool bash.hideIfPwdIgnored)\" != \"false\" ] &&\n+\t   git check-ignore -q .\n+\tthen\n+\t\tif [ $pcmode = yes ]; then\n+\t\t\tPS1=\"$ps1pc_start$ps1pc_end\"\n+\t\tfi\n+\t\treturn\n+\tfi\n+\n \tlocal r=\"\"\n \tlocal b=\"\"\n \tlocal step=\"\"\n@@ -506,13 +517,6 @@ __git_ps1 ()\n \tlocal f=\"$w$i$s$u\"\n \tlocal gitstring=\"$c$b${f:+$z$f}$r$p\"\n \n-\tif [ -n \"${GIT_PS1_HIDE_IF_PWD_IGNORED}\" ] &&\n-\t   [ \"$(git config --bool bash.hideIfPwdIgnored)\" != \"false\" ] &&\n-\t   git check-ignore -q .\n-\tthen\n-\t\tprintf_format=\"\"\n-\tfi\n-\n \tif [ $pcmode = yes ]; then\n \t\tif [ \"${__git_printf_supports_v-}\" != yes ]; then\n \t\t\tgitstring=$(printf -- \"$printf_format\" \"$gitstring\")\n\nIt would be good to add additional test cases for pcmode (two or three\narguments to __git_ps1) and 'cd .git' so that the above issues don't\nreappear.\n\nThanks,\nRichard\n"},{"id":"254288","messageId":"1420441418-12511-1-git-send-email-rhansen@bbn.com","threadId":"37693","inReplyTo":"543ED906.403@bbn.com","subject":"[PATCH v4] git-prompt.sh: Option to hide prompt for ignored pwd","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2015-01-05T07:03:38Z","receivedAt":"2015-01-05T07:03:38Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"From: Jess Austin <jess.austin@gmail.com>\n\nOptionally set __git_ps1 to display nothing when present working\ndirectory is ignored, triggered by the new environmental variable\nGIT_PS1_HIDE_IF_PWD_IGNORED. This environmental variable may be\noverridden on any repository by setting bash.hideIfPwdIgnored to\n\"false\". In the absence of GIT_PS1_HIDE_IF_PWD_IGNORED this change\nhas no effect.\n\nMany people manage e.g. dotfiles in their home directory with git.\nThis causes the prompt generated by __git_ps1 to refer to that \"top\nlevel\" repo while working in any descendant directory. That can be\ndistracting, so this patch helps one shut off that noise.\n\nSigned-off-by: Jess Austin <jess.austin@gmail.com>\nSigned-off-by: Richard Hansen <rhansen@bbn.com>\nReviewed-by: Richard Hansen <rhansen@bbn.com>\n---\nThis is the patch from:\n\n  http://article.gmane.org/gmane.comp.version-control.git/258313\n\nmodified to include the changes I suggested in:\n\n  http://article.gmane.org/gmane.comp.version-control.git/258355\n\nI never heard back regarding my suggested changes.  The feature was so\nclose to ready and I thought it would be a shame for the feature to\nsilently die, so I'm submitting a re-roll with my suggested changes on\nbehalf of the original author.\n\n-Richard\n\n\n contrib/completion/git-prompt.sh |  16 ++++++\n t/t9903-bash-prompt.sh           | 106 +++++++++++++++++++++++++++++++++++++++\n 2 files changed, 122 insertions(+)\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex 729f769..cb78c79 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -84,6 +84,11 @@\n # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on\n # the colored output of \"git status -sb\" and are available only when\n # using __git_ps1 for PROMPT_COMMAND or precmd.\n+#\n+# If you would like __git_ps1 to do nothing in the case when the current\n+# directory is set up to be ignored by git, then set\n+# GIT_PS1_HIDE_IF_PWD_IGNORED to a nonempty value. Override this on the\n+# repository level by setting bash.hideIfPwdIgnored to \"false\".\n \n # check whether printf supports -v\n __git_printf_supports_v=\n@@ -369,6 +374,17 @@ __git_ps1 ()\n \tlocal inside_gitdir=\"${repo_info##*$'\\n'}\"\n \tlocal g=\"${repo_info%$'\\n'*}\"\n \n+\tif [ \"true\" = \"$inside_worktree\" ] &&\n+\t   [ -n \"${GIT_PS1_HIDE_IF_PWD_IGNORED}\" ] &&\n+\t   [ \"$(git config --bool bash.hideIfPwdIgnored)\" != \"false\" ] &&\n+\t   git check-ignore -q .\n+\tthen\n+\t\tif [ $pcmode = yes ]; then\n+\t\t\tPS1=\"$ps1pc_start$ps1pc_end\"\n+\t\tfi\n+\t\treturn\n+\tfi\n+\n \tlocal r=\"\"\n \tlocal b=\"\"\n \tlocal step=\"\"\ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex 9150984..37953c8 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -35,6 +35,8 @@ test_expect_success 'setup for prompt tests' '\n \tgit commit -m \"another b2\" file &&\n \techo 000 >file &&\n \tgit commit -m \"yet another b2\" file &&\n+\tmkdir ignored_dir &&\n+\techo \"ignored_dir/\" >> .gitignore &&\n \tgit checkout master\n '\n \n@@ -588,4 +590,108 @@ test_expect_success 'prompt - zsh color pc mode' '\n \ttest_cmp expected \"$actual\"\n '\n \n+test_expect_success 'prompt - hide if pwd ignored - env var unset, config disabled' '\n+\tprintf \" (master)\" >expected &&\n+\ttest_config bash.hideIfPwdIgnored false &&\n+\t(\n+\t\tcd ignored_dir &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success 'prompt - hide if pwd ignored - env var unset, config disabled, pc mode' '\n+\tprintf \"BEFORE: (\\${__git_ps1_branch_name}):AFTER\" >expected &&\n+\ttest_config bash.hideIfPwdIgnored false &&\n+\t(\n+\t\tcd ignored_dir &&\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 - hide if pwd ignored - env var unset, config unset' '\n+\tprintf \" (master)\" >expected &&\n+\t(\n+\t\tcd ignored_dir &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success 'prompt - hide if pwd ignored - env var unset, config unset, pc mode' '\n+\tprintf \"BEFORE: (\\${__git_ps1_branch_name}):AFTER\" >expected &&\n+\t(\n+\t\tcd ignored_dir &&\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 - hide if pwd ignored - env var set, config disabled' '\n+\tprintf \" (master)\" >expected &&\n+\ttest_config bash.hideIfPwdIgnored false &&\n+\t(\n+\t\tcd ignored_dir &&\n+\t\tGIT_PS1_HIDE_IF_PWD_IGNORED=y &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success 'prompt - hide if pwd ignored - env var set, config disabled, pc mode' '\n+\tprintf \"BEFORE: (\\${__git_ps1_branch_name}):AFTER\" >expected &&\n+\ttest_config bash.hideIfPwdIgnored false &&\n+\t(\n+\t\tcd ignored_dir &&\n+\t\tGIT_PS1_HIDE_IF_PWD_IGNORED=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 - hide if pwd ignored - env var set, config unset' '\n+\tprintf \"\" >expected &&\n+\t(\n+\t\tcd ignored_dir &&\n+\t\tGIT_PS1_HIDE_IF_PWD_IGNORED=y &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success 'prompt - hide if pwd ignored - env var set, config unset, pc mode' '\n+\tprintf \"BEFORE::AFTER\" >expected &&\n+\t(\n+\t\tcd ignored_dir &&\n+\t\tGIT_PS1_HIDE_IF_PWD_IGNORED=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 - hide if pwd ignored - inside gitdir (stdout)' '\n+\tprintf \" (GIT_DIR!)\" >expected &&\n+\t(\n+\t\tGIT_PS1_HIDE_IF_PWD_IGNORED=y &&\n+\t\tcd .git &&\n+\t\t__git_ps1 >\"$actual\" 2>/dev/null\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success 'prompt - hide if pwd ignored - inside gitdir (stderr)' '\n+\tprintf \"\" >expected &&\n+\t(\n+\t\tGIT_PS1_HIDE_IF_PWD_IGNORED=y &&\n+\t\tcd .git &&\n+\t\t__git_ps1 >/dev/null 2>\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n test_done\n-- \n2.2.1\n"},{"id":"254381","messageId":"xmqqwq4zmqpt.fsf@gitster.dls.corp.google.com","threadId":"37693","inReplyTo":"1420441418-12511-1-git-send-email-rhansen@bbn.com","subject":"Re: [PATCH v4] git-prompt.sh: Option to hide prompt for ignored pwd","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-01-06T23:31:10Z","receivedAt":"2015-01-06T23:31:10Z","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> This is the patch from:\n>\n>   http://article.gmane.org/gmane.comp.version-control.git/258313\n>\n> modified to include the changes I suggested in:\n>\n>   http://article.gmane.org/gmane.comp.version-control.git/258355\n>\n> I never heard back regarding my suggested changes.  The feature was so\n> close to ready and I thought it would be a shame for the feature to\n> silently die, so I'm submitting a re-roll with my suggested changes on\n> behalf of the original author.\n\n> +# If you would like __git_ps1 to do nothing in the case when the current\n> +# directory is set up to be ignored by git, then set\n> +# GIT_PS1_HIDE_IF_PWD_IGNORED to a nonempty value. Override this on the\n> +# repository level by setting bash.hideIfPwdIgnored to \"false\".\n\nPerhaps nobody had much interest in the original or the update.\nOccassionally resending with improvements like this is a good way to\nshow it to more people who may have missed it the last time to\nsolicit comments and supports.\n\nI am personally not very interested, as you and the original made it\nsound as if this is primarily for those who keep track of $HOME/.dot\nfiles in $HOME/.git, which is one of the ways I would never use Git.\n\nBut I do not have to be the target of each and every new feature ;-).\n\n>  # check whether printf supports -v\n>  __git_printf_supports_v=\n> @@ -369,6 +374,17 @@ __git_ps1 ()\n>  \tlocal inside_gitdir=\"${repo_info##*$'\\n'}\"\n>  \tlocal g=\"${repo_info%$'\\n'*}\"\n>  \n> +\tif [ \"true\" = \"$inside_worktree\" ] &&\n> +\t   [ -n \"${GIT_PS1_HIDE_IF_PWD_IGNORED}\" ] &&\n\nMany existing checks on variables are written this way with the\n\"subsitutute with default value\" syntax\n\n        if [ -n \"${GIT_PS1_SHOWDIRTYSTATE-}\" ] &&\n\nto make sure that people with non-standard settings to report\nreferences to unset variables as errors will not have to suffer.\nDon't you need to do something similar here?\n\n> +\t   [ \"$(git config --bool bash.hideIfPwdIgnored)\" != \"false\" ] &&\n> +\t   git check-ignore -q .\n> +\tthen\n> +\t\tif [ $pcmode = yes ]; then\n> +\t\t\tPS1=\"$ps1pc_start$ps1pc_end\"\n> +\t\tfi\n> +\t\treturn\n\nThere are already two places where \"under pcmode, we need to set PS1\nto this empty thing\" is known, and this patch adds yet another.\nWould it be sensible to refactor that into a helper function, or\nopen coding them this way is necessary for performance or some other\nreasons?\n\n> +\tfi\n> +\n>  \tlocal r=\"\"\n>  \tlocal b=\"\"\n>  \tlocal step=\"\"\n> diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\n> index 9150984..37953c8 100755\n> --- a/t/t9903-bash-prompt.sh\n> +++ b/t/t9903-bash-prompt.sh\n> @@ -35,6 +35,8 @@ test_expect_success 'setup for prompt tests' '\n>  \tgit commit -m \"another b2\" file &&\n>  \techo 000 >file &&\n>  \tgit commit -m \"yet another b2\" file &&\n> +\tmkdir ignored_dir &&\n> +\techo \"ignored_dir/\" >> .gitignore &&\n\nDrop the SP after (but not before) redirection operator >>.\n"},{"id":"254392","messageId":"1420593747-24110-1-git-send-email-rhansen@bbn.com","threadId":"37693","inReplyTo":"xmqqwq4zmqpt.fsf@gitster.dls.corp.google.com","subject":"[PATCH v5 0/2] git-prompt.sh: Option to hide prompt for ignored pwd","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2015-01-07T01:22:25Z","receivedAt":"2015-01-07T01:22:25Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"On 2015-01-06T15:31-08:00, Junio C Hamano wrote:\n>> This is the patch from:\n>>\n>>   http://article.gmane.org/gmane.comp.version-control.git/258313\n>>\n>> modified to include the changes I suggested in:\n>>\n>>   http://article.gmane.org/gmane.comp.version-control.git/258355\n>>\n>> I never heard back regarding my suggested changes.  The feature was so\n>> close to ready and I thought it would be a shame for the feature to\n>> silently die, so I'm submitting a re-roll with my suggested changes on\n>> behalf of the original author.\n> \n>> +# If you would like __git_ps1 to do nothing in the case when the current\n>> +# directory is set up to be ignored by git, then set\n>> +# GIT_PS1_HIDE_IF_PWD_IGNORED to a nonempty value. Override this on the\n>> +# repository level by setting bash.hideIfPwdIgnored to \"false\".\n> \n> Perhaps nobody had much interest in the original or the update.\n> Occassionally resending with improvements like this is a good way to\n> show it to more people who may have missed it the last time to\n> solicit comments and supports.\n> \n> I am personally not very interested, as you and the original made it\n> sound as if this is primarily for those who keep track of $HOME/.dot\n> files in $HOME/.git, which is one of the ways I would never use Git.\n\nI do keep my dotfiles in a Git repository (~/.git exists), yet I\nwouldn't use this feature either.  (I just use refs/heads/dotfiles as\nHEAD so that my prompt is unique when I'm not in some project working\ndirectory.)\n\nHowever, it doesn't seem like a very invasive change to me, and at\nleast one person wants this feature (evidenced by Jess Austin going to\nthe trouble of submitting a patch), so I thought I'd help it along.\n\nIf someone has a reasonable objection to this feature, or even if\nthere's not enough positive interest, I wouldn't be too sad to see it\nnot get adopted.\n\n>> +\t   [ -n \"${GIT_PS1_HIDE_IF_PWD_IGNORED}\" ] &&\n> \n> Many existing checks on variables are written this way with the\n> \"subsitutute with default value\" syntax\n> \n>         if [ -n \"${GIT_PS1_SHOWDIRTYSTATE-}\" ] &&\n> \n> to make sure that people with non-standard settings to report\n> references to unset variables as errors will not have to suffer.\n> Don't you need to do something similar here?\n\nYes; fixed.\n\n>> +\t   [ \"$(git config --bool bash.hideIfPwdIgnored)\" != \"false\" ] &&\n>> +\t   git check-ignore -q .\n>> +\tthen\n>> +\t\tif [ $pcmode = yes ]; then\n>> +\t\t\tPS1=\"$ps1pc_start$ps1pc_end\"\n>> +\t\tfi\n>> +\t\treturn\n> \n> There are already two places where \"under pcmode, we need to set PS1\n> to this empty thing\" is known, and this patch adds yet another.\n> Would it be sensible to refactor that into a helper function, or\n> open coding them this way is necessary for performance or some other\n> reasons?\n\nI thought about factoring it out, but didn't because defining a\nfunction with just three lines seemed awkward.  But I thought of a\nbetter way to eliminate the duplicate code without defining a helper\nfunction; see the new prequel patch.\n\n>> +\techo \"ignored_dir/\" >> .gitignore &&\n> \n> Drop the SP after (but not before) redirection operator >>.\n\nDone.\n\nThanks for the review,\nRichard\n\n\nJess Austin (1):\n  git-prompt.sh: Option to hide prompt for ignored pwd\n\nRichard Hansen (1):\n  git-prompt.sh: if pc mode, immediately set PS1 to a plain prompt\n\n contrib/completion/git-prompt.sh |  24 ++++++---\n t/t9903-bash-prompt.sh           | 106 +++++++++++++++++++++++++++++++++++++++\n 2 files changed, 123 insertions(+), 7 deletions(-)\n\n-- \n2.2.1\n"},{"id":"254393","messageId":"1420593747-24110-2-git-send-email-rhansen@bbn.com","threadId":"37693","inReplyTo":"1420593747-24110-1-git-send-email-rhansen@bbn.com","subject":"[PATCH v5 1/2] git-prompt.sh: if pc mode, immediately set PS1 to a plain prompt","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2015-01-07T01:22:26Z","receivedAt":"2015-01-07T01:22:26Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"At the beginning of __git_ps1, right after determining that the\nfunction is running in pc mode, set PS1 to a plain (undecorated)\nprompt.  This makes it possible to simply return early without having\nto set PS1 if the prompt should not be decorated.\n\nSigned-off-by: Richard Hansen <rhansen@bbn.com>\n---\n contrib/completion/git-prompt.sh | 11 ++++-------\n 1 file changed, 4 insertions(+), 7 deletions(-)\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex 729f769..b0de082 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -299,6 +299,10 @@ __git_ps1 ()\n \t\t\tps1pc_start=\"$1\"\n \t\t\tps1pc_end=\"$2\"\n \t\t\tprintf_format=\"${3:-$printf_format}\"\n+\t\t\t# set PS1 to a plain prompt so that we can\n+\t\t\t# simply return early if the prompt should not\n+\t\t\t# be decorated\n+\t\t\tPS1=\"$ps1pc_start$ps1pc_end\"\n \t\t;;\n \t\t0|1)\tprintf_format=\"${1:-$printf_format}\"\n \t\t;;\n@@ -350,10 +354,6 @@ __git_ps1 ()\n \trev_parse_exit_code=\"$?\"\n \n \tif [ -z \"$repo_info\" ]; then\n-\t\tif [ $pcmode = yes ]; then\n-\t\t\t#In PC mode PS1 always needs to be set\n-\t\t\tPS1=\"$ps1pc_start$ps1pc_end\"\n-\t\tfi\n \t\treturn\n \tfi\n \n@@ -412,9 +412,6 @@ __git_ps1 ()\n \t\telse\n \t\t\tlocal head=\"\"\n \t\t\tif ! __git_eread \"$g/HEAD\" head; then\n-\t\t\t\tif [ $pcmode = yes ]; then\n-\t\t\t\t\tPS1=\"$ps1pc_start$ps1pc_end\"\n-\t\t\t\tfi\n \t\t\t\treturn\n \t\t\tfi\n \t\t\t# is it a symbolic ref?\n-- \n2.2.1\n"},{"id":"254391","messageId":"1420593747-24110-3-git-send-email-rhansen@bbn.com","threadId":"37693","inReplyTo":"1420593747-24110-1-git-send-email-rhansen@bbn.com","subject":"[PATCH v5 2/2] git-prompt.sh: Option to hide prompt for ignored pwd","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2015-01-07T01:22:27Z","receivedAt":"2015-01-07T01:22:27Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"From: Jess Austin <jess.austin@gmail.com>\n\nOptionally set __git_ps1 to display nothing when present working\ndirectory is ignored, triggered by the new environmental variable\nGIT_PS1_HIDE_IF_PWD_IGNORED. This environmental variable may be\noverridden on any repository by setting bash.hideIfPwdIgnored to\n\"false\". In the absence of GIT_PS1_HIDE_IF_PWD_IGNORED this change\nhas no effect.\n\nMany people manage e.g. dotfiles in their home directory with git.\nThis causes the prompt generated by __git_ps1 to refer to that \"top\nlevel\" repo while working in any descendant directory. That can be\ndistracting, so this patch helps one shut off that noise.\n\nSigned-off-by: Jess Austin <jess.austin@gmail.com>\nSigned-off-by: Richard Hansen <rhansen@bbn.com>\nReviewed-by: Richard Hansen <rhansen@bbn.com>\n---\n contrib/completion/git-prompt.sh |  13 +++++\n t/t9903-bash-prompt.sh           | 106 +++++++++++++++++++++++++++++++++++++++\n 2 files changed, 119 insertions(+)\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex b0de082..75c3f0f 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -84,6 +84,11 @@\n # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on\n # the colored output of \"git status -sb\" and are available only when\n # using __git_ps1 for PROMPT_COMMAND or precmd.\n+#\n+# If you would like __git_ps1 to do nothing in the case when the current\n+# directory is set up to be ignored by git, then set\n+# GIT_PS1_HIDE_IF_PWD_IGNORED to a nonempty value. Override this on the\n+# repository level by setting bash.hideIfPwdIgnored to \"false\".\n \n # check whether printf supports -v\n __git_printf_supports_v=\n@@ -369,6 +374,14 @@ __git_ps1 ()\n \tlocal inside_gitdir=\"${repo_info##*$'\\n'}\"\n \tlocal g=\"${repo_info%$'\\n'*}\"\n \n+\tif [ \"true\" = \"$inside_worktree\" ] &&\n+\t   [ -n \"${GIT_PS1_HIDE_IF_PWD_IGNORED-}\" ] &&\n+\t   [ \"$(git config --bool bash.hideIfPwdIgnored)\" != \"false\" ] &&\n+\t   git check-ignore -q .\n+\tthen\n+\t\treturn\n+\tfi\n+\n \tlocal r=\"\"\n \tlocal b=\"\"\n \tlocal step=\"\"\ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex 9150984..51ecd3e 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -35,6 +35,8 @@ test_expect_success 'setup for prompt tests' '\n \tgit commit -m \"another b2\" file &&\n \techo 000 >file &&\n \tgit commit -m \"yet another b2\" file &&\n+\tmkdir ignored_dir &&\n+\techo \"ignored_dir/\" >>.gitignore &&\n \tgit checkout master\n '\n \n@@ -588,4 +590,108 @@ test_expect_success 'prompt - zsh color pc mode' '\n \ttest_cmp expected \"$actual\"\n '\n \n+test_expect_success 'prompt - hide if pwd ignored - env var unset, config disabled' '\n+\tprintf \" (master)\" >expected &&\n+\ttest_config bash.hideIfPwdIgnored false &&\n+\t(\n+\t\tcd ignored_dir &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success 'prompt - hide if pwd ignored - env var unset, config disabled, pc mode' '\n+\tprintf \"BEFORE: (\\${__git_ps1_branch_name}):AFTER\" >expected &&\n+\ttest_config bash.hideIfPwdIgnored false &&\n+\t(\n+\t\tcd ignored_dir &&\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 - hide if pwd ignored - env var unset, config unset' '\n+\tprintf \" (master)\" >expected &&\n+\t(\n+\t\tcd ignored_dir &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success 'prompt - hide if pwd ignored - env var unset, config unset, pc mode' '\n+\tprintf \"BEFORE: (\\${__git_ps1_branch_name}):AFTER\" >expected &&\n+\t(\n+\t\tcd ignored_dir &&\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 - hide if pwd ignored - env var set, config disabled' '\n+\tprintf \" (master)\" >expected &&\n+\ttest_config bash.hideIfPwdIgnored false &&\n+\t(\n+\t\tcd ignored_dir &&\n+\t\tGIT_PS1_HIDE_IF_PWD_IGNORED=y &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success 'prompt - hide if pwd ignored - env var set, config disabled, pc mode' '\n+\tprintf \"BEFORE: (\\${__git_ps1_branch_name}):AFTER\" >expected &&\n+\ttest_config bash.hideIfPwdIgnored false &&\n+\t(\n+\t\tcd ignored_dir &&\n+\t\tGIT_PS1_HIDE_IF_PWD_IGNORED=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 - hide if pwd ignored - env var set, config unset' '\n+\tprintf \"\" >expected &&\n+\t(\n+\t\tcd ignored_dir &&\n+\t\tGIT_PS1_HIDE_IF_PWD_IGNORED=y &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success 'prompt - hide if pwd ignored - env var set, config unset, pc mode' '\n+\tprintf \"BEFORE::AFTER\" >expected &&\n+\t(\n+\t\tcd ignored_dir &&\n+\t\tGIT_PS1_HIDE_IF_PWD_IGNORED=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 - hide if pwd ignored - inside gitdir (stdout)' '\n+\tprintf \" (GIT_DIR!)\" >expected &&\n+\t(\n+\t\tGIT_PS1_HIDE_IF_PWD_IGNORED=y &&\n+\t\tcd .git &&\n+\t\t__git_ps1 >\"$actual\" 2>/dev/null\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success 'prompt - hide if pwd ignored - inside gitdir (stderr)' '\n+\tprintf \"\" >expected &&\n+\t(\n+\t\tGIT_PS1_HIDE_IF_PWD_IGNORED=y &&\n+\t\tcd .git &&\n+\t\t__git_ps1 >/dev/null 2>\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n test_done\n-- \n2.2.1\n"},{"id":"254641","messageId":"20150114124500.Horde.yfl7_QOVJQq0-zVzaAY52g6@webmail.informatik.kit.edu","threadId":"37693","inReplyTo":"1420593747-24110-2-git-send-email-rhansen@bbn.com","subject":"Re: [PATCH v5 1/2] git-prompt.sh: if pc mode, immediately set PS1","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2015-01-14T11:45:00Z","receivedAt":"2015-01-14T11:45:00Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Hi,\n\n\nQuoting Richard Hansen <rhansen@bbn.com>:\n> At the beginning of __git_ps1, right after determining that the\n> function is running in pc mode, set PS1 to a plain (undecorated)\n> prompt.  This makes it possible to simply return early without having\n> to set PS1 if the prompt should not be decorated.\n>\n> Signed-off-by: Richard Hansen <rhansen@bbn.com>\n> ---\n>   contrib/completion/git-prompt.sh | 11 ++++-------\n>   1 file changed, 4 insertions(+), 7 deletions(-)\n>\n> diff --git a/contrib/completion/git-prompt.sh\n> b/contrib/completion/git-prompt.sh\n> index 729f769..b0de082 100644\n> --- a/contrib/completion/git-prompt.sh\n> +++ b/contrib/completion/git-prompt.sh\n> @@ -299,6 +299,10 @@ __git_ps1 ()\n>   \t\t\tps1pc_start=\"$1\"\n>   \t\t\tps1pc_end=\"$2\"\n>   \t\t\tprintf_format=\"${3:-$printf_format}\"\n> +\t\t\t# set PS1 to a plain prompt so that we can\n> +\t\t\t# simply return early if the prompt should not\n> +\t\t\t# be decorated\n> +\t\t\tPS1=\"$ps1pc_start$ps1pc_end\"\n>   \t\t;;\n>   \t\t0|1)\tprintf_format=\"${1:-$printf_format}\"\n>   \t\t;;\n> @@ -350,10 +354,6 @@ __git_ps1 ()\n>   \trev_parse_exit_code=\"$?\"\n>\n>   \tif [ -z \"$repo_info\" ]; then\n> -\t\tif [ $pcmode = yes ]; then\n> -\t\t\t#In PC mode PS1 always needs to be set\n> -\t\t\tPS1=\"$ps1pc_start$ps1pc_end\"\n> -\t\tfi\n>   \t\treturn\n>   \tfi\n>\n> @@ -412,9 +412,6 @@ __git_ps1 ()\n>   \t\telse\n>   \t\t\tlocal head=\"\"\n>   \t\t\tif ! __git_eread \"$g/HEAD\" head; then\n> -\t\t\t\tif [ $pcmode = yes ]; then\n> -\t\t\t\t\tPS1=\"$ps1pc_start$ps1pc_end\"\n> -\t\t\t\tfi\n>   \t\t\t\treturn\n>   \t\t\tfi\n>   \t\t\t# is it a symbolic ref?\n> --\n> 2.2.1\n\nAs the one responsible for the last hunk I really like this change.\n\nThanks,\nGábor\n"}]}