All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] git-prompt.sh: Omit prompt for ignored directories
@ 2014-10-08 19:04 Jess Austin
  2014-10-08 21:12 ` Richard Hansen
  0 siblings, 1 reply; 18+ messages in thread
From: Jess Austin @ 2014-10-08 19:04 UTC (permalink / raw)
  To: git; +Cc: Jess Austin, szeder, rhansen

Introduce a new environmental variable, GIT_PS1_OMITIGNORED, which
tells __git_ps1 to display nothing when the current directory is
set (e.g. via .gitignore) to be ignored by git. In the absence of
GIT_PS1_OMITIGNORED this change has no effect.

Many people manage e.g. dotfiles in their home directory with git.
This causes the prompt generated by __git_ps1 to refer to that "top
level" repo while working in any descendant directory. That can be
distracting, so this patch helps one shut off that noise.

Signed-off-by: Jess Austin <jess.austin@gmail.com>
---
 contrib/completion/git-prompt.sh |  9 +++++++++
 t/t9903-bash-prompt.sh           | 21 +++++++++++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index c5473dc..6a26cb4 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -84,6 +84,10 @@
 # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on
 # the colored output of "git status -sb" and are available only when
 # using __git_ps1 for PROMPT_COMMAND or precmd.
+#
+# If you would like __git_ps1 to do nothing in the case when the current
+# directory is set up to be ignored by git, then set GIT_PS1_OMITIGNORED
+# to a nonempty value.
 
 # check whether printf supports -v
 __git_printf_supports_v=
@@ -501,6 +505,11 @@ __git_ps1 ()
 	local f="$w$i$s$u"
 	local gitstring="$c$b${f:+$z$f}$r$p"
 
+	if [ -n "$(git check-ignore .)" ] && [ -n "${GIT_PS1_OMITIGNORED}" ]
+	then
+		printf_format=""
+	fi
+
 	if [ $pcmode = yes ]; then
 		if [ "${__git_printf_supports_v-}" != yes ]; then
 			gitstring=$(printf -- "$printf_format" "$gitstring")
diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh
index 9150984..55bcb6b 100755
--- a/t/t9903-bash-prompt.sh
+++ b/t/t9903-bash-prompt.sh
@@ -35,6 +35,8 @@ test_expect_success 'setup for prompt tests' '
 	git commit -m "another b2" file &&
 	echo 000 >file &&
 	git commit -m "yet another b2" file &&
+	mkdir ignored_dir &&
+	echo "ignored_dir/" >> .gitignore &&
 	git checkout master
 '
 
@@ -588,4 +590,23 @@ test_expect_success 'prompt - zsh color pc mode' '
 	test_cmp expected "$actual"
 '
 
+test_expect_success 'prompt - prompt omitted in ignored directory' '
+	printf "" >expected &&
+	(
+		cd ignored_dir &&
+		GIT_PS1_OMITIGNORED=y &&
+		__git_ps1 >"$actual"
+	) &&
+	test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - prompt not omitted without GIT_PS1_OMITIGNORED' '
+	printf " (master)" >expected &&
+	(
+		cd ignored_dir &&
+		__git_ps1 >"$actual"
+	) &&
+	test_cmp expected "$actual"
+'
+
 test_done
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH] git-prompt.sh: Omit prompt for ignored directories
  2014-10-08 19:04 [PATCH] git-prompt.sh: Omit prompt for ignored directories Jess Austin
@ 2014-10-08 21:12 ` Richard Hansen
       [not found]   ` <CANp8Xb8ETG-ZFCqrOk=f-RbxtRxehBmAR1O5ozLH80zimWq_Gw@mail.gmail.com>
  0 siblings, 1 reply; 18+ messages in thread
From: Richard Hansen @ 2014-10-08 21:12 UTC (permalink / raw)
  To: Jess Austin, git; +Cc: szeder

On 2014-10-08 15:04, Jess Austin wrote:
> Introduce a new environmental variable, GIT_PS1_OMITIGNORED, which
> tells __git_ps1 to display nothing when the current directory is
> set (e.g. via .gitignore) to be ignored by git. In the absence of
> GIT_PS1_OMITIGNORED this change has no effect.
> 
> Many people manage e.g. dotfiles in their home directory with git.
> This causes the prompt generated by __git_ps1 to refer to that "top
> level" repo while working in any descendant directory. That can be
> distracting, so this patch helps one shut off that noise.

Interesting idea, though I would prefer this to be configurable on a
per-repository basis.  (I wouldn't want to hide the prompt in any
repository besides my home repository.)

I'm not a big fan of the name "OMITIGNORED" (it's not immediately
obvious what this means), but I can't think of anything better off the
top of my head...

-Richard


> 
> Signed-off-by: Jess Austin <jess.austin@gmail.com>
> ---
>  contrib/completion/git-prompt.sh |  9 +++++++++
>  t/t9903-bash-prompt.sh           | 21 +++++++++++++++++++++
>  2 files changed, 30 insertions(+)
> 
> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
> index c5473dc..6a26cb4 100644
> --- a/contrib/completion/git-prompt.sh
> +++ b/contrib/completion/git-prompt.sh
> @@ -84,6 +84,10 @@
>  # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on
>  # the colored output of "git status -sb" and are available only when
>  # using __git_ps1 for PROMPT_COMMAND or precmd.
> +#
> +# If you would like __git_ps1 to do nothing in the case when the current
> +# directory is set up to be ignored by git, then set GIT_PS1_OMITIGNORED
> +# to a nonempty value.
>  
>  # check whether printf supports -v
>  __git_printf_supports_v=
> @@ -501,6 +505,11 @@ __git_ps1 ()
>  	local f="$w$i$s$u"
>  	local gitstring="$c$b${f:+$z$f}$r$p"
>  
> +	if [ -n "$(git check-ignore .)" ] && [ -n "${GIT_PS1_OMITIGNORED}" ]
> +	then
> +		printf_format=""
> +	fi
> +
>  	if [ $pcmode = yes ]; then
>  		if [ "${__git_printf_supports_v-}" != yes ]; then
>  			gitstring=$(printf -- "$printf_format" "$gitstring")
> diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh
> index 9150984..55bcb6b 100755
> --- a/t/t9903-bash-prompt.sh
> +++ b/t/t9903-bash-prompt.sh
> @@ -35,6 +35,8 @@ test_expect_success 'setup for prompt tests' '
>  	git commit -m "another b2" file &&
>  	echo 000 >file &&
>  	git commit -m "yet another b2" file &&
> +	mkdir ignored_dir &&
> +	echo "ignored_dir/" >> .gitignore &&
>  	git checkout master
>  '
>  
> @@ -588,4 +590,23 @@ test_expect_success 'prompt - zsh color pc mode' '
>  	test_cmp expected "$actual"
>  '
>  
> +test_expect_success 'prompt - prompt omitted in ignored directory' '
> +	printf "" >expected &&
> +	(
> +		cd ignored_dir &&
> +		GIT_PS1_OMITIGNORED=y &&
> +		__git_ps1 >"$actual"
> +	) &&
> +	test_cmp expected "$actual"
> +'
> +
> +test_expect_success 'prompt - prompt not omitted without GIT_PS1_OMITIGNORED' '
> +	printf " (master)" >expected &&
> +	(
> +		cd ignored_dir &&
> +		__git_ps1 >"$actual"
> +	) &&
> +	test_cmp expected "$actual"
> +'
> +
>  test_done
> 

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Fwd: [PATCH] git-prompt.sh: Omit prompt for ignored directories
       [not found]   ` <CANp8Xb8ETG-ZFCqrOk=f-RbxtRxehBmAR1O5ozLH80zimWq_Gw@mail.gmail.com>
@ 2014-10-08 21:37     ` Jess Austin
  2014-10-09  5:37       ` Richard Hansen
  0 siblings, 1 reply; 18+ messages in thread
From: Jess Austin @ 2014-10-08 21:37 UTC (permalink / raw)
  To: Richard Hansen; +Cc: git, szeder

On Wed, Oct 8, 2014 at 4:12 PM, Richard Hansen <rhansen@bbn.com> wrote:
>
> On 2014-10-08 15:04, Jess Austin wrote:
> > Introduce a new environmental variable, GIT_PS1_OMITIGNORED, which
> > tells __git_ps1 to display nothing when the current directory is
> > set (e.g. via .gitignore) to be ignored by git. In the absence of
> > GIT_PS1_OMITIGNORED this change has no effect.
> >
> > Many people manage e.g. dotfiles in their home directory with git.
> > This causes the prompt generated by __git_ps1 to refer to that "top
> > level" repo while working in any descendant directory. That can be
> > distracting, so this patch helps one shut off that noise.
>
> Interesting idea, though I would prefer this to be configurable on a
> per-repository basis.  (I wouldn't want to hide the prompt in any
> repository besides my home repository.)

Sorry my description was unclear. Let's say you have a repo in "~",
and another in "~/projects/foo". Also, the file "~/.gitignore" has the line
"projects/" in it. In this case, you'd see repo info in your prompt while
in "~" or in "~/projects/foo", but not if you were in "~/projects". In that
sense, the prompt is not distracting you with the status of the top-level
repo when you're not looking at anything in that repo.

>
> I'm not a big fan of the name "OMITIGNORED" (it's not immediately
> obvious what this means), but I can't think of anything better off the
> top of my head...

I'm definitely open to suggestions.

cheers,
Jess

ps. sorry for the html before

> > Signed-off-by: Jess Austin <jess.austin@gmail.com>
> > ---
> >  contrib/completion/git-prompt.sh |  9 +++++++++
> >  t/t9903-bash-prompt.sh           | 21 +++++++++++++++++++++
> >  2 files changed, 30 insertions(+)
> >
> > diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
> > index c5473dc..6a26cb4 100644
> > --- a/contrib/completion/git-prompt.sh
> > +++ b/contrib/completion/git-prompt.sh
> > @@ -84,6 +84,10 @@
> >  # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on
> >  # the colored output of "git status -sb" and are available only when
> >  # using __git_ps1 for PROMPT_COMMAND or precmd.
> > +#
> > +# If you would like __git_ps1 to do nothing in the case when the current
> > +# directory is set up to be ignored by git, then set GIT_PS1_OMITIGNORED
> > +# to a nonempty value.
> >
> >  # check whether printf supports -v
> >  __git_printf_supports_v=
> > @@ -501,6 +505,11 @@ __git_ps1 ()
> >       local f="$w$i$s$u"
> >       local gitstring="$c$b${f:+$z$f}$r$p"
> >
> > +     if [ -n "$(git check-ignore .)" ] && [ -n "${GIT_PS1_OMITIGNORED}" ]
> > +     then
> > +             printf_format=""
> > +     fi
> > +
> >       if [ $pcmode = yes ]; then
> >               if [ "${__git_printf_supports_v-}" != yes ]; then
> >                       gitstring=$(printf -- "$printf_format" "$gitstring")
> > diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh
> > index 9150984..55bcb6b 100755
> > --- a/t/t9903-bash-prompt.sh
> > +++ b/t/t9903-bash-prompt.sh
> > @@ -35,6 +35,8 @@ test_expect_success 'setup for prompt tests' '
> >       git commit -m "another b2" file &&
> >       echo 000 >file &&
> >       git commit -m "yet another b2" file &&
> > +     mkdir ignored_dir &&
> > +     echo "ignored_dir/" >> .gitignore &&
> >       git checkout master
> >  '
> >
> > @@ -588,4 +590,23 @@ test_expect_success 'prompt - zsh color pc mode' '
> >       test_cmp expected "$actual"
> >  '
> >
> > +test_expect_success 'prompt - prompt omitted in ignored directory' '
> > +     printf "" >expected &&
> > +     (
> > +             cd ignored_dir &&
> > +             GIT_PS1_OMITIGNORED=y &&
> > +             __git_ps1 >"$actual"
> > +     ) &&
> > +     test_cmp expected "$actual"
> > +'
> > +
> > +test_expect_success 'prompt - prompt not omitted without GIT_PS1_OMITIGNORED' '
> > +     printf " (master)" >expected &&
> > +     (
> > +             cd ignored_dir &&
> > +             __git_ps1 >"$actual"
> > +     ) &&
> > +     test_cmp expected "$actual"
> > +'
> > +
> >  test_done
> >
>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] git-prompt.sh: Omit prompt for ignored directories
  2014-10-08 21:37     ` Fwd: " Jess Austin
@ 2014-10-09  5:37       ` Richard Hansen
  2014-10-09 10:27         ` Jess Austin
  0 siblings, 1 reply; 18+ messages in thread
From: Richard Hansen @ 2014-10-09  5:37 UTC (permalink / raw)
  To: Jess Austin; +Cc: git, szeder

On 2014-10-08 17:37, Jess Austin wrote:
> On Wed, Oct 8, 2014 at 4:12 PM, Richard Hansen <rhansen@bbn.com> wrote:
>> On 2014-10-08 15:04, Jess Austin wrote:
>>> Introduce a new environmental variable, GIT_PS1_OMITIGNORED, which
>>> tells __git_ps1 to display nothing when the current directory is
>>> set (e.g. via .gitignore) to be ignored by git. In the absence of
>>> GIT_PS1_OMITIGNORED this change has no effect.
>>>
>>> Many people manage e.g. dotfiles in their home directory with git.
>>> This causes the prompt generated by __git_ps1 to refer to that "top
>>> level" repo while working in any descendant directory. That can be
>>> distracting, so this patch helps one shut off that noise.
>>
>> Interesting idea, though I would prefer this to be configurable on a
>> per-repository basis.  (I wouldn't want to hide the prompt in any
>> repository besides my home repository.)
> 
> Sorry my description was unclear. Let's say you have a repo in "~",
> and another in "~/projects/foo". Also, the file "~/.gitignore" has the line
> "projects/" in it. In this case, you'd see repo info in your prompt while
> in "~" or in "~/projects/foo", but not if you were in "~/projects". In that
> sense, the prompt is not distracting you with the status of the top-level
> repo when you're not looking at anything in that repo.

I understand; I was concerned about this case:

$ PS1='\n\w$(__git_ps1 " (%s)")\n\$ '

/home/rhansen/projects (dotfiles)
$ GIT_PS1_OMITIGNORED=y

/home/rhansen/projects              <-- Git prompt goes away as desired
$ cd foo

/home/rhansen/projects/foo (master) <-- Git prompt back as expected
$ echo ignored/ >>.gitignore && mkdir -p ignored && cd ignored

/home/rhansen/projects/foo/ignored  <-- I want the Git prompt here
$

In other words:  If I were to use this feature, I'd want to be able to
hide the prompt when I'm in an ignored directory in my dotfiles work
tree, but show the prompt when I'm in an ignored directory in any other
work tree.

-Richard

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] git-prompt.sh: Omit prompt for ignored directories
  2014-10-09  5:37       ` Richard Hansen
@ 2014-10-09 10:27         ` Jess Austin
  2014-10-09 22:09           ` Richard Hansen
  0 siblings, 1 reply; 18+ messages in thread
From: Jess Austin @ 2014-10-09 10:27 UTC (permalink / raw)
  To: Richard Hansen; +Cc: git, szeder

On Thu, Oct 9, 2014 at 12:37 AM, Richard Hansen <rhansen@bbn.com> wrote:
> On 2014-10-08 17:37, Jess Austin wrote:
>> On Wed, Oct 8, 2014 at 4:12 PM, Richard Hansen <rhansen@bbn.com> wrote:
>>> On 2014-10-08 15:04, Jess Austin wrote:
>>>> Introduce a new environmental variable, GIT_PS1_OMITIGNORED, which
>>>> tells __git_ps1 to display nothing when the current directory is
>>>> set (e.g. via .gitignore) to be ignored by git. In the absence of
>>>> GIT_PS1_OMITIGNORED this change has no effect.
>>>>
>>>> Many people manage e.g. dotfiles in their home directory with git.
>>>> This causes the prompt generated by __git_ps1 to refer to that "top
>>>> level" repo while working in any descendant directory. That can be
>>>> distracting, so this patch helps one shut off that noise.
>>>
>>> Interesting idea, though I would prefer this to be configurable on a
>>> per-repository basis.  (I wouldn't want to hide the prompt in any
>>> repository besides my home repository.)
>>
>> Sorry my description was unclear. Let's say you have a repo in "~",
>> and another in "~/projects/foo". Also, the file "~/.gitignore" has the line
>> "projects/" in it. In this case, you'd see repo info in your prompt while
>> in "~" or in "~/projects/foo", but not if you were in "~/projects". In that
>> sense, the prompt is not distracting you with the status of the top-level
>> repo when you're not looking at anything in that repo.
>
> I understand; I was concerned about this case:
>
> $ PS1='\n\w$(__git_ps1 " (%s)")\n\$ '
>
> /home/rhansen/projects (dotfiles)
> $ GIT_PS1_OMITIGNORED=y
>
> /home/rhansen/projects              <-- Git prompt goes away as desired
> $ cd foo
>
> /home/rhansen/projects/foo (master) <-- Git prompt back as expected
> $ echo ignored/ >>.gitignore && mkdir -p ignored && cd ignored
>
> /home/rhansen/projects/foo/ignored  <-- I want the Git prompt here
> $
>
> In other words:  If I were to use this feature, I'd want to be able to
> hide the prompt when I'm in an ignored directory in my dotfiles work
> tree, but show the prompt when I'm in an ignored directory in any other
> work tree.

Would you want this configured in each repo (i.e. via a line in ".git/config"),
or would you prefer something global so that it only need be set in one
place? I'm not sure how the latter technique would work, so if that seems
better please advise on how to go about that.

cheers,
Jess

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] git-prompt.sh: Omit prompt for ignored directories
  2014-10-09 10:27         ` Jess Austin
@ 2014-10-09 22:09           ` Richard Hansen
  2014-10-14  2:32             ` [PATCH] git-prompt.sh: Hide prompt for ignored pwd Jess Austin
  0 siblings, 1 reply; 18+ messages in thread
From: Richard Hansen @ 2014-10-09 22:09 UTC (permalink / raw)
  To: Jess Austin; +Cc: git, szeder

On 2014-10-09 06:27, Jess Austin wrote:
> On Thu, Oct 9, 2014 at 12:37 AM, Richard Hansen <rhansen@bbn.com> wrote:
>> On 2014-10-08 17:37, Jess Austin wrote:
>>> On Wed, Oct 8, 2014 at 4:12 PM, Richard Hansen <rhansen@bbn.com> wrote:
>>>> On 2014-10-08 15:04, Jess Austin wrote:
>>>>> Introduce a new environmental variable, GIT_PS1_OMITIGNORED, which
>>>>> tells __git_ps1 to display nothing when the current directory is
>>>>> set (e.g. via .gitignore) to be ignored by git. In the absence of
>>>>> GIT_PS1_OMITIGNORED this change has no effect.
>>>>>
>>>>> Many people manage e.g. dotfiles in their home directory with git.
>>>>> This causes the prompt generated by __git_ps1 to refer to that "top
>>>>> level" repo while working in any descendant directory. That can be
>>>>> distracting, so this patch helps one shut off that noise.
...
>>
>> $ PS1='\n\w$(__git_ps1 " (%s)")\n\$ '
>>
>> /home/rhansen/projects (dotfiles)
>> $ GIT_PS1_OMITIGNORED=y
>>
>> /home/rhansen/projects              <-- Git prompt goes away as desired
>> $ cd foo
>>
>> /home/rhansen/projects/foo (master) <-- Git prompt back as expected
>> $ echo ignored/ >>.gitignore && mkdir -p ignored && cd ignored
>>
>> /home/rhansen/projects/foo/ignored  <-- I want the Git prompt here
>> $
>>
>> In other words:  If I were to use this feature, I'd want to be able to
>> hide the prompt when I'm in an ignored directory in my dotfiles work
>> tree, but show the prompt when I'm in an ignored directory in any other
>> work tree.
> 
> Would you want this configured in each repo (i.e. via a line in ".git/config"),
> or would you prefer something global so that it only need be set in one
> place? I'm not sure how the latter technique would work, so if that seems
> better please advise on how to go about that.

A 'git config' variable is fine.  The bash.showDirtyState,
bash.showUntrackedFiles, and bash.showUpstream config variables seem
like good examples to follow.

-Richard

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH] git-prompt.sh: Hide prompt for ignored pwd
  2014-10-09 22:09           ` Richard Hansen
@ 2014-10-14  2:32             ` Jess Austin
  2014-10-14 18:47               ` Johannes Sixt
  2014-10-14 19:21               ` [PATCH] git-prompt.sh: Hide " Richard Hansen
  0 siblings, 2 replies; 18+ messages in thread
From: Jess Austin @ 2014-10-14  2:32 UTC (permalink / raw)
  To: Richard Hansen; +Cc: Jess Austin, git

Set __git_ps1 to display nothing when present working directory is
ignored, triggered by either the new environmental variable
GIT_PS1_HIDE_ON_IGNORED_PWD or the new repository configuration
variable bash.hideOnIgnoredPwd (or both). In the absence of these
settings this change has no effect.

Many people manage e.g. dotfiles in their home directory with git.
This causes the prompt generated by __git_ps1 to refer to that "top
level" repo while working in any descendant directory. That can be
distracting, so this patch helps one shut off that noise.

Signed-off-by: Jess Austin <jess.austin@gmail.com>
---
On Thu, Oct 9, 2014 at 5:09 PM, Richard Hansen <rhansen@bbn.com> wrote:
> On 2014-10-09 06:27, Jess Austin wrote:
>> Would you want this configured in each repo (i.e. via a line in ".git/config"),
>> or would you prefer something global so that it only need be set in one
>> place? I'm not sure how the latter technique would work, so if that seems
>> better please advise on how to go about that.
>
> A 'git config' variable is fine.  The bash.showDirtyState,
> bash.showUntrackedFiles, and bash.showUpstream config variables seem
> like good examples to follow.

I think this is what you meant. I changed the name of the envvar. Now the
variables are GIT_PS1_HIDE_ON_IGNORED_PWD and bash.hideOnIgnoredPwd. I
admit these are still kind of unwieldy, but maybe now they're more descriptive?

Please advise!

cheers,
Jess

 contrib/completion/git-prompt.sh | 12 ++++++++++++
 t/t9903-bash-prompt.sh           | 42 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+)

diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index c5473dc..d7559ff 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -84,6 +84,11 @@
 # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on
 # the colored output of "git status -sb" and are available only when
 # using __git_ps1 for PROMPT_COMMAND or precmd.
+#
+# If you would like __git_ps1 to do nothing in the case when the current
+# directory is set up to be ignored by git, then set
+# GIT_PS1_HIDE_ON_IGNORED_PWD to a nonempty value, or set
+# bash.hideOnIgnoredPwd to true in the repository configuration.
 
 # check whether printf supports -v
 __git_printf_supports_v=
@@ -501,6 +506,13 @@ __git_ps1 ()
 	local f="$w$i$s$u"
 	local gitstring="$c$b${f:+$z$f}$r$p"
 
+	if [ -n "$(git check-ignore .)" ] &&
+	   ( [ -n "${GIT_PS1_HIDE_ON_IGNORED_PWD}" ] ||
+	     [ "$(git config --bool bash.hideOnIgnoredPwd)" = "true" ] )
+	then
+		printf_format=""
+	fi
+
 	if [ $pcmode = yes ]; then
 		if [ "${__git_printf_supports_v-}" != yes ]; then
 			gitstring=$(printf -- "$printf_format" "$gitstring")
diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh
index 9150984..a8ef8a3 100755
--- a/t/t9903-bash-prompt.sh
+++ b/t/t9903-bash-prompt.sh
@@ -35,6 +35,8 @@ test_expect_success 'setup for prompt tests' '
 	git commit -m "another b2" file &&
 	echo 000 >file &&
 	git commit -m "yet another b2" file &&
+	mkdir ignored_dir &&
+	echo "ignored_dir/" >> .gitignore &&
 	git checkout master
 '
 
@@ -588,4 +590,44 @@ test_expect_success 'prompt - zsh color pc mode' '
 	test_cmp expected "$actual"
 '
 
+test_expect_success 'prompt - hide on ignored pwd - shell variable unset with config disabled' '
+	printf " (master)" >expected &&
+	(
+		cd ignored_dir &&
+		__git_ps1 >"$actual"
+	) &&
+	test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - hide on ignored pwd - shell variable unset with config enabled' '
+	printf "" >expected &&
+	test_config bash.hideOnIgnoredPwd true &&
+	(
+		cd ignored_dir &&
+		__git_ps1 >"$actual"
+	) &&
+	test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - hide on ignored pwd - shell variable set with config disabled' '
+	printf "" >expected &&
+	(
+		cd ignored_dir &&
+		GIT_PS1_HIDE_ON_IGNORED_PWD=y &&
+		__git_ps1 >"$actual"
+	) &&
+	test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - hide on ignored pwd - shell variable set with config enabled' '
+	printf "" >expected &&
+	test_config bash.hideOnIgnoredPwd true &&
+	(
+		cd ignored_dir &&
+		GIT_PS1_HIDE_ON_IGNORED_PWD=y &&
+		__git_ps1 >"$actual"
+	) &&
+	test_cmp expected "$actual"
+'
+
 test_done
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH] git-prompt.sh: Hide prompt for ignored pwd
  2014-10-14  2:32             ` [PATCH] git-prompt.sh: Hide prompt for ignored pwd Jess Austin
@ 2014-10-14 18:47               ` Johannes Sixt
  2014-10-14 19:08                 ` Richard Hansen
  2014-10-15  4:06                 ` [PATCH] git-prompt.sh: Option to hide " Jess Austin
  2014-10-14 19:21               ` [PATCH] git-prompt.sh: Hide " Richard Hansen
  1 sibling, 2 replies; 18+ messages in thread
From: Johannes Sixt @ 2014-10-14 18:47 UTC (permalink / raw)
  To: Jess Austin; +Cc: Richard Hansen, git

Am 14.10.2014 um 04:32 schrieb Jess Austin:
> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
> index c5473dc..d7559ff 100644
> --- a/contrib/completion/git-prompt.sh
> +++ b/contrib/completion/git-prompt.sh
> @@ -84,6 +84,11 @@
>  # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on
>  # the colored output of "git status -sb" and are available only when
>  # using __git_ps1 for PROMPT_COMMAND or precmd.
> +#
> +# If you would like __git_ps1 to do nothing in the case when the current
> +# directory is set up to be ignored by git, then set
> +# GIT_PS1_HIDE_ON_IGNORED_PWD to a nonempty value, or set
> +# bash.hideOnIgnoredPwd to true in the repository configuration.
>  
>  # check whether printf supports -v
>  __git_printf_supports_v=
> @@ -501,6 +506,13 @@ __git_ps1 ()
>  	local f="$w$i$s$u"
>  	local gitstring="$c$b${f:+$z$f}$r$p"
>  
> +	if [ -n "$(git check-ignore .)" ] &&
> +	   ( [ -n "${GIT_PS1_HIDE_ON_IGNORED_PWD}" ] ||
> +	     [ "$(git config --bool bash.hideOnIgnoredPwd)" = "true" ] )

Ahem, no. Please do not punish users who are not interested in the new
feature with two new processes every time __git_ps() is run. Think of
Windows where fork() is really, *really* expensive.

BTW, you can write '{ foo || bar; }' to bracket a || chain without a
sub-process.

> +	then
> +		printf_format=""
> +	fi
> +
>  	if [ $pcmode = yes ]; then
>  		if [ "${__git_printf_supports_v-}" != yes ]; then
>  			gitstring=$(printf -- "$printf_format" "$gitstring")

-- Hannes

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] git-prompt.sh: Hide prompt for ignored pwd
  2014-10-14 18:47               ` Johannes Sixt
@ 2014-10-14 19:08                 ` Richard Hansen
  2014-10-15  4:06                 ` [PATCH] git-prompt.sh: Option to hide " Jess Austin
  1 sibling, 0 replies; 18+ messages in thread
From: Richard Hansen @ 2014-10-14 19:08 UTC (permalink / raw)
  To: Johannes Sixt, Jess Austin; +Cc: git

On 2014-10-14 14:47, Johannes Sixt wrote:
> Am 14.10.2014 um 04:32 schrieb Jess Austin:
>> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
>> index c5473dc..d7559ff 100644
>> --- a/contrib/completion/git-prompt.sh
>> +++ b/contrib/completion/git-prompt.sh
>> @@ -84,6 +84,11 @@
>>  # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on
>>  # the colored output of "git status -sb" and are available only when
>>  # using __git_ps1 for PROMPT_COMMAND or precmd.
>> +#
>> +# If you would like __git_ps1 to do nothing in the case when the current
>> +# directory is set up to be ignored by git, then set
>> +# GIT_PS1_HIDE_ON_IGNORED_PWD to a nonempty value, or set
>> +# bash.hideOnIgnoredPwd to true in the repository configuration.
>>  
>>  # check whether printf supports -v
>>  __git_printf_supports_v=
>> @@ -501,6 +506,13 @@ __git_ps1 ()
>>  	local f="$w$i$s$u"
>>  	local gitstring="$c$b${f:+$z$f}$r$p"
>>  
>> +	if [ -n "$(git check-ignore .)" ] &&
>> +	   ( [ -n "${GIT_PS1_HIDE_ON_IGNORED_PWD}" ] ||
>> +	     [ "$(git config --bool bash.hideOnIgnoredPwd)" = "true" ] )
> 
> Ahem, no. Please do not punish users who are not interested in the new
> feature with two new processes every time __git_ps() is run. Think of
> Windows where fork() is really, *really* expensive.

Is this why bash.showDirtyState and friends aren't checked unless the
corresponding environment variable is set to a non-empty value?

Regardless, it would be nice if the behavior matched the other bash.*
variables (only check the bash.* variable if the corresponding
environment variable is set, and default to true).  The following should
fix it:

    if [ -n "${GIT_PS1_HIDE_ON_IGNORED_PWD}" ] &&
       [ "$(git config --bool bash.hideOnIgnoredPwd)" != "false" ] &&
       [ "$(git check-ignore .)" ]
    then
            ...

-Richard

> 
> BTW, you can write '{ foo || bar; }' to bracket a || chain without a
> sub-process.
> 
>> +	then
>> +		printf_format=""
>> +	fi
>> +
>>  	if [ $pcmode = yes ]; then
>>  		if [ "${__git_printf_supports_v-}" != yes ]; then
>>  			gitstring=$(printf -- "$printf_format" "$gitstring")
> 
> -- Hannes
> 

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] git-prompt.sh: Hide prompt for ignored pwd
  2014-10-14  2:32             ` [PATCH] git-prompt.sh: Hide prompt for ignored pwd Jess Austin
  2014-10-14 18:47               ` Johannes Sixt
@ 2014-10-14 19:21               ` Richard Hansen
  1 sibling, 0 replies; 18+ messages in thread
From: Richard Hansen @ 2014-10-14 19:21 UTC (permalink / raw)
  To: Jess Austin; +Cc: git

On 2014-10-13 22:32, Jess Austin wrote:
> Set __git_ps1 to display nothing when present working directory is
> ignored, triggered by either the new environmental variable
> GIT_PS1_HIDE_ON_IGNORED_PWD or the new repository configuration
> variable bash.hideOnIgnoredPwd (or both). In the absence of these
> settings this change has no effect.
> 
> Many people manage e.g. dotfiles in their home directory with git.
> This causes the prompt generated by __git_ps1 to refer to that "top
> level" repo while working in any descendant directory. That can be
> distracting, so this patch helps one shut off that noise.
> 
> Signed-off-by: Jess Austin <jess.austin@gmail.com>
> ---
> On Thu, Oct 9, 2014 at 5:09 PM, Richard Hansen <rhansen@bbn.com> wrote:
>> On 2014-10-09 06:27, Jess Austin wrote:
>>> Would you want this configured in each repo (i.e. via a line in ".git/config"),
>>> or would you prefer something global so that it only need be set in one
>>> place? I'm not sure how the latter technique would work, so if that seems
>>> better please advise on how to go about that.
>>
>> A 'git config' variable is fine.  The bash.showDirtyState,
>> bash.showUntrackedFiles, and bash.showUpstream config variables seem
>> like good examples to follow.
> 
> I think this is what you meant. I changed the name of the envvar. Now the
> variables are GIT_PS1_HIDE_ON_IGNORED_PWD and bash.hideOnIgnoredPwd. I
> admit these are still kind of unwieldy, but maybe now they're more descriptive?

I do prefer the new names.  They are long, but how often will someone
have to type it?  In this case it's better to be descriptive than to be
short.  (I wonder if adding two letters would improve readability
further:  GIT_PS1_HIDE_WHEN_PWD_IGNORED and bash.hideWhenPwdIgnored.)

To avoid scaring people who might not want this feature enabled, I
recommend changing the subject line to something like this:

    git-prompt.sh: Option to hide prompt for ignored pwd

> 
> Please advise!
> 
> cheers,
> Jess
> 
>  contrib/completion/git-prompt.sh | 12 ++++++++++++
>  t/t9903-bash-prompt.sh           | 42 ++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 54 insertions(+)
> 
> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
> index c5473dc..d7559ff 100644
> --- a/contrib/completion/git-prompt.sh
> +++ b/contrib/completion/git-prompt.sh
> @@ -84,6 +84,11 @@
>  # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on
>  # the colored output of "git status -sb" and are available only when
>  # using __git_ps1 for PROMPT_COMMAND or precmd.
> +#
> +# If you would like __git_ps1 to do nothing in the case when the current
> +# directory is set up to be ignored by git, then set
> +# GIT_PS1_HIDE_ON_IGNORED_PWD to a nonempty value, or set
> +# bash.hideOnIgnoredPwd to true in the repository configuration.

As mentioned in my previous email, I would prefer the code to follow the
behavior of the other config variables (the environment variable has to
be set *and* the config variable has to be non-false).

>  
>  # check whether printf supports -v
>  __git_printf_supports_v=
> @@ -501,6 +506,13 @@ __git_ps1 ()
>  	local f="$w$i$s$u"
>  	local gitstring="$c$b${f:+$z$f}$r$p"
>  
> +	if [ -n "$(git check-ignore .)" ] &&

Rather than:

    [ -n "$(git check-ignore .)" ]

I would prefer:

    git check-ignore -q .

For example:

    if [ -n "${GIT_PS1_HIDE_ON_IGNORED_PWD}" ] &&
       [ "$(git config --bool bash.hideOnIgnoredPwd)" != "false" ] &&
       git check-ignore -q .
    then
            ...

-Richard


> +	   ( [ -n "${GIT_PS1_HIDE_ON_IGNORED_PWD}" ] ||
> +	     [ "$(git config --bool bash.hideOnIgnoredPwd)" = "true" ] )
> +	then
> +		printf_format=""
> +	fi
> +
>  	if [ $pcmode = yes ]; then
>  		if [ "${__git_printf_supports_v-}" != yes ]; then
>  			gitstring=$(printf -- "$printf_format" "$gitstring")
> diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh
> index 9150984..a8ef8a3 100755
> --- a/t/t9903-bash-prompt.sh
> +++ b/t/t9903-bash-prompt.sh
> @@ -35,6 +35,8 @@ test_expect_success 'setup for prompt tests' '
>  	git commit -m "another b2" file &&
>  	echo 000 >file &&
>  	git commit -m "yet another b2" file &&
> +	mkdir ignored_dir &&
> +	echo "ignored_dir/" >> .gitignore &&
>  	git checkout master
>  '
>  
> @@ -588,4 +590,44 @@ test_expect_success 'prompt - zsh color pc mode' '
>  	test_cmp expected "$actual"
>  '
>  
> +test_expect_success 'prompt - hide on ignored pwd - shell variable unset with config disabled' '
> +	printf " (master)" >expected &&
> +	(
> +		cd ignored_dir &&
> +		__git_ps1 >"$actual"
> +	) &&
> +	test_cmp expected "$actual"
> +'
> +
> +test_expect_success 'prompt - hide on ignored pwd - shell variable unset with config enabled' '
> +	printf "" >expected &&
> +	test_config bash.hideOnIgnoredPwd true &&
> +	(
> +		cd ignored_dir &&
> +		__git_ps1 >"$actual"
> +	) &&
> +	test_cmp expected "$actual"
> +'
> +
> +test_expect_success 'prompt - hide on ignored pwd - shell variable set with config disabled' '
> +	printf "" >expected &&
> +	(
> +		cd ignored_dir &&
> +		GIT_PS1_HIDE_ON_IGNORED_PWD=y &&
> +		__git_ps1 >"$actual"
> +	) &&
> +	test_cmp expected "$actual"
> +'
> +
> +test_expect_success 'prompt - hide on ignored pwd - shell variable set with config enabled' '
> +	printf "" >expected &&
> +	test_config bash.hideOnIgnoredPwd true &&
> +	(
> +		cd ignored_dir &&
> +		GIT_PS1_HIDE_ON_IGNORED_PWD=y &&
> +		__git_ps1 >"$actual"
> +	) &&
> +	test_cmp expected "$actual"
> +'
> +
>  test_done
> 

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH] git-prompt.sh: Option to hide prompt for ignored pwd
  2014-10-14 18:47               ` Johannes Sixt
  2014-10-14 19:08                 ` Richard Hansen
@ 2014-10-15  4:06                 ` Jess Austin
  2014-10-15 20:28                   ` Richard Hansen
  1 sibling, 1 reply; 18+ messages in thread
From: Jess Austin @ 2014-10-15  4:06 UTC (permalink / raw)
  To: Richard Hansen; +Cc: Jess Austin, Johannes Sixt, git

Optionally set __git_ps1 to display nothing when present working
directory is ignored, triggered by the new environmental variable
GIT_PS1_HIDE_IF_PWD_IGNORED. This environmental variable may be
overridden on any repository by setting bash.hideIfPwdIgnored to
"false". In the absence of GIT_PS1_HIDE_IF_PWD_IGNORED this change
has no effect.

Many people manage e.g. dotfiles in their home directory with git.
This causes the prompt generated by __git_ps1 to refer to that "top
level" repo while working in any descendant directory. That can be
distracting, so this patch helps one shut off that noise.

Signed-off-by: Jess Austin <jess.austin@gmail.com>
---
On Tue, Oct 14, 2014 at 2:08 PM, Richard Hansen <rhansen@bbn.com> wrote:
> On 2014-10-14 14:47, Johannes Sixt wrote:
>> Ahem, no. Please do not punish users who are not interested in the new
>> feature with two new processes every time __git_ps() is run. Think of
>> Windows where fork() is really, *really* expensive.
> Regardless, it would be nice if the behavior matched the other bash.*
> variables (only check the bash.* variable if the corresponding
> environment variable is set, and default to true).  The following should
> fix it:
>
>     if [ -n "${GIT_PS1_HIDE_ON_IGNORED_PWD}" ] &&
>        [ "$(git config --bool bash.hideOnIgnoredPwd)" != "false" ] &&
>        [ "$(git check-ignore .)" ]
>     then
Thanks for helping me understand this! I think I have it correct now.


On Tue, Oct 14, 2014 at 2:21 PM, Richard Hansen <rhansen@bbn.com> wrote:
> I do prefer the new names.  They are long, but how often will someone
> have to type it?  In this case it's better to be descriptive than to be
> short.  (I wonder if adding two letters would improve readability
> further:  GIT_PS1_HIDE_WHEN_PWD_IGNORED and bash.hideWhenPwdIgnored.)

We got those two letters back with GIT_PS1_HIDE_IF_PWD_IGNORED and
bash.hideIfPwdIgnored.

> To avoid scaring people who might not want this feature enabled, I
> recommend changing the subject line to something like this:
>
>     git-prompt.sh: Option to hide prompt for ignored pwd

Good idea!


 contrib/completion/git-prompt.sh | 12 ++++++++++++
 t/t9903-bash-prompt.sh           | 42 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+)

diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index c5473dc..151218b 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -84,6 +84,11 @@
 # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on
 # the colored output of "git status -sb" and are available only when
 # using __git_ps1 for PROMPT_COMMAND or precmd.
+#
+# If you would like __git_ps1 to do nothing in the case when the current
+# directory is set up to be ignored by git, then set
+# GIT_PS1_HIDE_IF_PWD_IGNORED to a nonempty value. Override this on the
+# repository level by setting bash.hideIfPwdIgnored to "false".
 
 # check whether printf supports -v
 __git_printf_supports_v=
@@ -501,6 +506,13 @@ __git_ps1 ()
 	local f="$w$i$s$u"
 	local gitstring="$c$b${f:+$z$f}$r$p"
 
+	if [ -n "${GIT_PS1_HIDE_IF_PWD_IGNORED}" ] &&
+	   [ "$(git config --bool bash.hideIfPwdIgnored)" != "false" ] &&
+	   git check-ignore -q .
+	then
+		printf_format=""
+	fi
+
 	if [ $pcmode = yes ]; then
 		if [ "${__git_printf_supports_v-}" != yes ]; then
 			gitstring=$(printf -- "$printf_format" "$gitstring")
diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh
index 9150984..88a75cf 100755
--- a/t/t9903-bash-prompt.sh
+++ b/t/t9903-bash-prompt.sh
@@ -35,6 +35,8 @@ test_expect_success 'setup for prompt tests' '
 	git commit -m "another b2" file &&
 	echo 000 >file &&
 	git commit -m "yet another b2" file &&
+	mkdir ignored_dir &&
+	echo "ignored_dir/" >> .gitignore &&
 	git checkout master
 '
 
@@ -588,4 +590,44 @@ test_expect_success 'prompt - zsh color pc mode' '
 	test_cmp expected "$actual"
 '
 
+test_expect_success 'prompt - hide if pwd ignored - shell variable unset with config disabled' '
+	printf " (master)" >expected &&
+	test_config bash.hideIfPwdIgnored false &&
+	(
+		cd ignored_dir &&
+		__git_ps1 >"$actual"
+	) &&
+	test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - hide if pwd ignored - shell variable unset with config unset' '
+	printf " (master)" >expected &&
+	(
+		cd ignored_dir &&
+		__git_ps1 >"$actual"
+	) &&
+	test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - hide if pwd ignored - shell variable set with config disabled' '
+	printf " (master)" >expected &&
+	test_config bash.hideIfPwdIgnored false &&
+	(
+		cd ignored_dir &&
+		GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
+		__git_ps1 >"$actual"
+	) &&
+	test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - hide if pwd ignored - shell variable set with config unset' '
+	printf "" >expected &&
+	(
+		cd ignored_dir &&
+		GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
+		__git_ps1 >"$actual"
+	) &&
+	test_cmp expected "$actual"
+'
+
 test_done
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH] git-prompt.sh: Option to hide prompt for ignored pwd
  2014-10-15  4:06                 ` [PATCH] git-prompt.sh: Option to hide " Jess Austin
@ 2014-10-15 20:28                   ` Richard Hansen
  2015-01-05  7:03                     ` [PATCH v4] " Richard Hansen
  0 siblings, 1 reply; 18+ messages in thread
From: Richard Hansen @ 2014-10-15 20:28 UTC (permalink / raw)
  To: Jess Austin; +Cc: Johannes Sixt, git

On 2014-10-15 00:06, Jess Austin wrote:
> @@ -501,6 +506,13 @@ __git_ps1 ()
>  	local f="$w$i$s$u"
>  	local gitstring="$c$b${f:+$z$f}$r$p"
>  
> +	if [ -n "${GIT_PS1_HIDE_IF_PWD_IGNORED}" ] &&
> +	   [ "$(git config --bool bash.hideIfPwdIgnored)" != "false" ] &&
> +	   git check-ignore -q .
> +	then
> +		printf_format=""
> +	fi
> +
>  	if [ $pcmode = yes ]; then
>  		if [ "${__git_printf_supports_v-}" != yes ]; then
>  			gitstring=$(printf -- "$printf_format" "$gitstring")

This is broken in pcmode due to a Bash bug.  The command:
    printf -v foo "" asdf
is a no-op in Bash.  The variable foo is never changed in any way --
it is neither unset nor set to the empty string.

Also, I noticed that I get an error message if I cd into .git:
    fatal: This operation must be run in a work tree

I think the following change will fix the above issues, and it has the
advantage of avoiding unnecessary work if the directory is ignored:

diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 6a4ce53..68ac82a 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -374,6 +374,17 @@ __git_ps1 ()
 	local inside_gitdir="${repo_info##*$'\n'}"
 	local g="${repo_info%$'\n'*}"
 
+	if [ "true" = "$inside_worktree" ] &&
+	   [ -n "${GIT_PS1_HIDE_IF_PWD_IGNORED}" ] &&
+	   [ "$(git config --bool bash.hideIfPwdIgnored)" != "false" ] &&
+	   git check-ignore -q .
+	then
+		if [ $pcmode = yes ]; then
+			PS1="$ps1pc_start$ps1pc_end"
+		fi
+		return
+	fi
+
 	local r=""
 	local b=""
 	local step=""
@@ -506,13 +517,6 @@ __git_ps1 ()
 	local f="$w$i$s$u"
 	local gitstring="$c$b${f:+$z$f}$r$p"
 
-	if [ -n "${GIT_PS1_HIDE_IF_PWD_IGNORED}" ] &&
-	   [ "$(git config --bool bash.hideIfPwdIgnored)" != "false" ] &&
-	   git check-ignore -q .
-	then
-		printf_format=""
-	fi
-
 	if [ $pcmode = yes ]; then
 		if [ "${__git_printf_supports_v-}" != yes ]; then
 			gitstring=$(printf -- "$printf_format" "$gitstring")

It would be good to add additional test cases for pcmode (two or three
arguments to __git_ps1) and 'cd .git' so that the above issues don't
reappear.

Thanks,
Richard

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v4] git-prompt.sh: Option to hide prompt for ignored pwd
  2014-10-15 20:28                   ` Richard Hansen
@ 2015-01-05  7:03                     ` Richard Hansen
  2015-01-06 23:31                       ` Junio C Hamano
  0 siblings, 1 reply; 18+ messages in thread
From: Richard Hansen @ 2015-01-05  7:03 UTC (permalink / raw)
  To: git; +Cc: j6t, jess.austin

From: Jess Austin <jess.austin@gmail.com>

Optionally set __git_ps1 to display nothing when present working
directory is ignored, triggered by the new environmental variable
GIT_PS1_HIDE_IF_PWD_IGNORED. This environmental variable may be
overridden on any repository by setting bash.hideIfPwdIgnored to
"false". In the absence of GIT_PS1_HIDE_IF_PWD_IGNORED this change
has no effect.

Many people manage e.g. dotfiles in their home directory with git.
This causes the prompt generated by __git_ps1 to refer to that "top
level" repo while working in any descendant directory. That can be
distracting, so this patch helps one shut off that noise.

Signed-off-by: Jess Austin <jess.austin@gmail.com>
Signed-off-by: Richard Hansen <rhansen@bbn.com>
Reviewed-by: Richard Hansen <rhansen@bbn.com>
---
This is the patch from:

  http://article.gmane.org/gmane.comp.version-control.git/258313

modified to include the changes I suggested in:

  http://article.gmane.org/gmane.comp.version-control.git/258355

I never heard back regarding my suggested changes.  The feature was so
close to ready and I thought it would be a shame for the feature to
silently die, so I'm submitting a re-roll with my suggested changes on
behalf of the original author.

-Richard


 contrib/completion/git-prompt.sh |  16 ++++++
 t/t9903-bash-prompt.sh           | 106 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 122 insertions(+)

diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 729f769..cb78c79 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -84,6 +84,11 @@
 # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on
 # the colored output of "git status -sb" and are available only when
 # using __git_ps1 for PROMPT_COMMAND or precmd.
+#
+# If you would like __git_ps1 to do nothing in the case when the current
+# directory is set up to be ignored by git, then set
+# GIT_PS1_HIDE_IF_PWD_IGNORED to a nonempty value. Override this on the
+# repository level by setting bash.hideIfPwdIgnored to "false".
 
 # check whether printf supports -v
 __git_printf_supports_v=
@@ -369,6 +374,17 @@ __git_ps1 ()
 	local inside_gitdir="${repo_info##*$'\n'}"
 	local g="${repo_info%$'\n'*}"
 
+	if [ "true" = "$inside_worktree" ] &&
+	   [ -n "${GIT_PS1_HIDE_IF_PWD_IGNORED}" ] &&
+	   [ "$(git config --bool bash.hideIfPwdIgnored)" != "false" ] &&
+	   git check-ignore -q .
+	then
+		if [ $pcmode = yes ]; then
+			PS1="$ps1pc_start$ps1pc_end"
+		fi
+		return
+	fi
+
 	local r=""
 	local b=""
 	local step=""
diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh
index 9150984..37953c8 100755
--- a/t/t9903-bash-prompt.sh
+++ b/t/t9903-bash-prompt.sh
@@ -35,6 +35,8 @@ test_expect_success 'setup for prompt tests' '
 	git commit -m "another b2" file &&
 	echo 000 >file &&
 	git commit -m "yet another b2" file &&
+	mkdir ignored_dir &&
+	echo "ignored_dir/" >> .gitignore &&
 	git checkout master
 '
 
@@ -588,4 +590,108 @@ test_expect_success 'prompt - zsh color pc mode' '
 	test_cmp expected "$actual"
 '
 
+test_expect_success 'prompt - hide if pwd ignored - env var unset, config disabled' '
+	printf " (master)" >expected &&
+	test_config bash.hideIfPwdIgnored false &&
+	(
+		cd ignored_dir &&
+		__git_ps1 >"$actual"
+	) &&
+	test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - hide if pwd ignored - env var unset, config disabled, pc mode' '
+	printf "BEFORE: (\${__git_ps1_branch_name}):AFTER" >expected &&
+	test_config bash.hideIfPwdIgnored false &&
+	(
+		cd ignored_dir &&
+		__git_ps1 "BEFORE:" ":AFTER" &&
+		printf "%s" "$PS1" >"$actual"
+	) &&
+	test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - hide if pwd ignored - env var unset, config unset' '
+	printf " (master)" >expected &&
+	(
+		cd ignored_dir &&
+		__git_ps1 >"$actual"
+	) &&
+	test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - hide if pwd ignored - env var unset, config unset, pc mode' '
+	printf "BEFORE: (\${__git_ps1_branch_name}):AFTER" >expected &&
+	(
+		cd ignored_dir &&
+		__git_ps1 "BEFORE:" ":AFTER" &&
+		printf "%s" "$PS1" >"$actual"
+	) &&
+	test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - hide if pwd ignored - env var set, config disabled' '
+	printf " (master)" >expected &&
+	test_config bash.hideIfPwdIgnored false &&
+	(
+		cd ignored_dir &&
+		GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
+		__git_ps1 >"$actual"
+	) &&
+	test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - hide if pwd ignored - env var set, config disabled, pc mode' '
+	printf "BEFORE: (\${__git_ps1_branch_name}):AFTER" >expected &&
+	test_config bash.hideIfPwdIgnored false &&
+	(
+		cd ignored_dir &&
+		GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
+		__git_ps1 "BEFORE:" ":AFTER" &&
+		printf "%s" "$PS1" >"$actual"
+	) &&
+	test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - hide if pwd ignored - env var set, config unset' '
+	printf "" >expected &&
+	(
+		cd ignored_dir &&
+		GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
+		__git_ps1 >"$actual"
+	) &&
+	test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - hide if pwd ignored - env var set, config unset, pc mode' '
+	printf "BEFORE::AFTER" >expected &&
+	(
+		cd ignored_dir &&
+		GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
+		__git_ps1 "BEFORE:" ":AFTER" &&
+		printf "%s" "$PS1" >"$actual"
+	) &&
+	test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - hide if pwd ignored - inside gitdir (stdout)' '
+	printf " (GIT_DIR!)" >expected &&
+	(
+		GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
+		cd .git &&
+		__git_ps1 >"$actual" 2>/dev/null
+	) &&
+	test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - hide if pwd ignored - inside gitdir (stderr)' '
+	printf "" >expected &&
+	(
+		GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
+		cd .git &&
+		__git_ps1 >/dev/null 2>"$actual"
+	) &&
+	test_cmp expected "$actual"
+'
+
 test_done
-- 
2.2.1

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH v4] git-prompt.sh: Option to hide prompt for ignored pwd
  2015-01-05  7:03                     ` [PATCH v4] " Richard Hansen
@ 2015-01-06 23:31                       ` Junio C Hamano
  2015-01-07  1:22                         ` [PATCH v5 0/2] " Richard Hansen
  0 siblings, 1 reply; 18+ messages in thread
From: Junio C Hamano @ 2015-01-06 23:31 UTC (permalink / raw)
  To: Richard Hansen; +Cc: git, j6t, jess.austin

Richard Hansen <rhansen@bbn.com> writes:

> This is the patch from:
>
>   http://article.gmane.org/gmane.comp.version-control.git/258313
>
> modified to include the changes I suggested in:
>
>   http://article.gmane.org/gmane.comp.version-control.git/258355
>
> I never heard back regarding my suggested changes.  The feature was so
> close to ready and I thought it would be a shame for the feature to
> silently die, so I'm submitting a re-roll with my suggested changes on
> behalf of the original author.

> +# If you would like __git_ps1 to do nothing in the case when the current
> +# directory is set up to be ignored by git, then set
> +# GIT_PS1_HIDE_IF_PWD_IGNORED to a nonempty value. Override this on the
> +# repository level by setting bash.hideIfPwdIgnored to "false".

Perhaps nobody had much interest in the original or the update.
Occassionally resending with improvements like this is a good way to
show it to more people who may have missed it the last time to
solicit comments and supports.

I am personally not very interested, as you and the original made it
sound as if this is primarily for those who keep track of $HOME/.dot
files in $HOME/.git, which is one of the ways I would never use Git.

But I do not have to be the target of each and every new feature ;-).

>  # check whether printf supports -v
>  __git_printf_supports_v=
> @@ -369,6 +374,17 @@ __git_ps1 ()
>  	local inside_gitdir="${repo_info##*$'\n'}"
>  	local g="${repo_info%$'\n'*}"
>  
> +	if [ "true" = "$inside_worktree" ] &&
> +	   [ -n "${GIT_PS1_HIDE_IF_PWD_IGNORED}" ] &&

Many existing checks on variables are written this way with the
"subsitutute with default value" syntax

        if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ] &&

to make sure that people with non-standard settings to report
references to unset variables as errors will not have to suffer.
Don't you need to do something similar here?

> +	   [ "$(git config --bool bash.hideIfPwdIgnored)" != "false" ] &&
> +	   git check-ignore -q .
> +	then
> +		if [ $pcmode = yes ]; then
> +			PS1="$ps1pc_start$ps1pc_end"
> +		fi
> +		return

There are already two places where "under pcmode, we need to set PS1
to this empty thing" is known, and this patch adds yet another.
Would it be sensible to refactor that into a helper function, or
open coding them this way is necessary for performance or some other
reasons?

> +	fi
> +
>  	local r=""
>  	local b=""
>  	local step=""
> diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh
> index 9150984..37953c8 100755
> --- a/t/t9903-bash-prompt.sh
> +++ b/t/t9903-bash-prompt.sh
> @@ -35,6 +35,8 @@ test_expect_success 'setup for prompt tests' '
>  	git commit -m "another b2" file &&
>  	echo 000 >file &&
>  	git commit -m "yet another b2" file &&
> +	mkdir ignored_dir &&
> +	echo "ignored_dir/" >> .gitignore &&

Drop the SP after (but not before) redirection operator >>.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v5 0/2] git-prompt.sh: Option to hide prompt for ignored pwd
  2015-01-06 23:31                       ` Junio C Hamano
@ 2015-01-07  1:22                         ` Richard Hansen
  2015-01-07  1:22                           ` [PATCH v5 1/2] git-prompt.sh: if pc mode, immediately set PS1 to a plain prompt Richard Hansen
  2015-01-07  1:22                           ` [PATCH v5 2/2] git-prompt.sh: Option to hide prompt for ignored pwd Richard Hansen
  0 siblings, 2 replies; 18+ messages in thread
From: Richard Hansen @ 2015-01-07  1:22 UTC (permalink / raw)
  To: gitster; +Cc: j6t, jess.austin, git

On 2015-01-06T15:31-08:00, Junio C Hamano wrote:
>> This is the patch from:
>>
>>   http://article.gmane.org/gmane.comp.version-control.git/258313
>>
>> modified to include the changes I suggested in:
>>
>>   http://article.gmane.org/gmane.comp.version-control.git/258355
>>
>> I never heard back regarding my suggested changes.  The feature was so
>> close to ready and I thought it would be a shame for the feature to
>> silently die, so I'm submitting a re-roll with my suggested changes on
>> behalf of the original author.
> 
>> +# If you would like __git_ps1 to do nothing in the case when the current
>> +# directory is set up to be ignored by git, then set
>> +# GIT_PS1_HIDE_IF_PWD_IGNORED to a nonempty value. Override this on the
>> +# repository level by setting bash.hideIfPwdIgnored to "false".
> 
> Perhaps nobody had much interest in the original or the update.
> Occassionally resending with improvements like this is a good way to
> show it to more people who may have missed it the last time to
> solicit comments and supports.
> 
> I am personally not very interested, as you and the original made it
> sound as if this is primarily for those who keep track of $HOME/.dot
> files in $HOME/.git, which is one of the ways I would never use Git.

I do keep my dotfiles in a Git repository (~/.git exists), yet I
wouldn't use this feature either.  (I just use refs/heads/dotfiles as
HEAD so that my prompt is unique when I'm not in some project working
directory.)

However, it doesn't seem like a very invasive change to me, and at
least one person wants this feature (evidenced by Jess Austin going to
the trouble of submitting a patch), so I thought I'd help it along.

If someone has a reasonable objection to this feature, or even if
there's not enough positive interest, I wouldn't be too sad to see it
not get adopted.

>> +	   [ -n "${GIT_PS1_HIDE_IF_PWD_IGNORED}" ] &&
> 
> Many existing checks on variables are written this way with the
> "subsitutute with default value" syntax
> 
>         if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ] &&
> 
> to make sure that people with non-standard settings to report
> references to unset variables as errors will not have to suffer.
> Don't you need to do something similar here?

Yes; fixed.

>> +	   [ "$(git config --bool bash.hideIfPwdIgnored)" != "false" ] &&
>> +	   git check-ignore -q .
>> +	then
>> +		if [ $pcmode = yes ]; then
>> +			PS1="$ps1pc_start$ps1pc_end"
>> +		fi
>> +		return
> 
> There are already two places where "under pcmode, we need to set PS1
> to this empty thing" is known, and this patch adds yet another.
> Would it be sensible to refactor that into a helper function, or
> open coding them this way is necessary for performance or some other
> reasons?

I thought about factoring it out, but didn't because defining a
function with just three lines seemed awkward.  But I thought of a
better way to eliminate the duplicate code without defining a helper
function; see the new prequel patch.

>> +	echo "ignored_dir/" >> .gitignore &&
> 
> Drop the SP after (but not before) redirection operator >>.

Done.

Thanks for the review,
Richard


Jess Austin (1):
  git-prompt.sh: Option to hide prompt for ignored pwd

Richard Hansen (1):
  git-prompt.sh: if pc mode, immediately set PS1 to a plain prompt

 contrib/completion/git-prompt.sh |  24 ++++++---
 t/t9903-bash-prompt.sh           | 106 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 123 insertions(+), 7 deletions(-)

-- 
2.2.1

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v5 1/2] git-prompt.sh: if pc mode, immediately set PS1 to a plain prompt
  2015-01-07  1:22                         ` [PATCH v5 0/2] " Richard Hansen
@ 2015-01-07  1:22                           ` Richard Hansen
  2015-01-14 11:45                             ` [PATCH v5 1/2] git-prompt.sh: if pc mode, immediately set PS1 SZEDER Gábor
  2015-01-07  1:22                           ` [PATCH v5 2/2] git-prompt.sh: Option to hide prompt for ignored pwd Richard Hansen
  1 sibling, 1 reply; 18+ messages in thread
From: Richard Hansen @ 2015-01-07  1:22 UTC (permalink / raw)
  To: gitster; +Cc: j6t, jess.austin, git

At the beginning of __git_ps1, right after determining that the
function is running in pc mode, set PS1 to a plain (undecorated)
prompt.  This makes it possible to simply return early without having
to set PS1 if the prompt should not be decorated.

Signed-off-by: Richard Hansen <rhansen@bbn.com>
---
 contrib/completion/git-prompt.sh | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 729f769..b0de082 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -299,6 +299,10 @@ __git_ps1 ()
 			ps1pc_start="$1"
 			ps1pc_end="$2"
 			printf_format="${3:-$printf_format}"
+			# set PS1 to a plain prompt so that we can
+			# simply return early if the prompt should not
+			# be decorated
+			PS1="$ps1pc_start$ps1pc_end"
 		;;
 		0|1)	printf_format="${1:-$printf_format}"
 		;;
@@ -350,10 +354,6 @@ __git_ps1 ()
 	rev_parse_exit_code="$?"
 
 	if [ -z "$repo_info" ]; then
-		if [ $pcmode = yes ]; then
-			#In PC mode PS1 always needs to be set
-			PS1="$ps1pc_start$ps1pc_end"
-		fi
 		return
 	fi
 
@@ -412,9 +412,6 @@ __git_ps1 ()
 		else
 			local head=""
 			if ! __git_eread "$g/HEAD" head; then
-				if [ $pcmode = yes ]; then
-					PS1="$ps1pc_start$ps1pc_end"
-				fi
 				return
 			fi
 			# is it a symbolic ref?
-- 
2.2.1

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v5 2/2] git-prompt.sh: Option to hide prompt for ignored pwd
  2015-01-07  1:22                         ` [PATCH v5 0/2] " Richard Hansen
  2015-01-07  1:22                           ` [PATCH v5 1/2] git-prompt.sh: if pc mode, immediately set PS1 to a plain prompt Richard Hansen
@ 2015-01-07  1:22                           ` Richard Hansen
  1 sibling, 0 replies; 18+ messages in thread
From: Richard Hansen @ 2015-01-07  1:22 UTC (permalink / raw)
  To: gitster; +Cc: j6t, jess.austin, git

From: Jess Austin <jess.austin@gmail.com>

Optionally set __git_ps1 to display nothing when present working
directory is ignored, triggered by the new environmental variable
GIT_PS1_HIDE_IF_PWD_IGNORED. This environmental variable may be
overridden on any repository by setting bash.hideIfPwdIgnored to
"false". In the absence of GIT_PS1_HIDE_IF_PWD_IGNORED this change
has no effect.

Many people manage e.g. dotfiles in their home directory with git.
This causes the prompt generated by __git_ps1 to refer to that "top
level" repo while working in any descendant directory. That can be
distracting, so this patch helps one shut off that noise.

Signed-off-by: Jess Austin <jess.austin@gmail.com>
Signed-off-by: Richard Hansen <rhansen@bbn.com>
Reviewed-by: Richard Hansen <rhansen@bbn.com>
---
 contrib/completion/git-prompt.sh |  13 +++++
 t/t9903-bash-prompt.sh           | 106 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 119 insertions(+)

diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index b0de082..75c3f0f 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -84,6 +84,11 @@
 # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on
 # the colored output of "git status -sb" and are available only when
 # using __git_ps1 for PROMPT_COMMAND or precmd.
+#
+# If you would like __git_ps1 to do nothing in the case when the current
+# directory is set up to be ignored by git, then set
+# GIT_PS1_HIDE_IF_PWD_IGNORED to a nonempty value. Override this on the
+# repository level by setting bash.hideIfPwdIgnored to "false".
 
 # check whether printf supports -v
 __git_printf_supports_v=
@@ -369,6 +374,14 @@ __git_ps1 ()
 	local inside_gitdir="${repo_info##*$'\n'}"
 	local g="${repo_info%$'\n'*}"
 
+	if [ "true" = "$inside_worktree" ] &&
+	   [ -n "${GIT_PS1_HIDE_IF_PWD_IGNORED-}" ] &&
+	   [ "$(git config --bool bash.hideIfPwdIgnored)" != "false" ] &&
+	   git check-ignore -q .
+	then
+		return
+	fi
+
 	local r=""
 	local b=""
 	local step=""
diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh
index 9150984..51ecd3e 100755
--- a/t/t9903-bash-prompt.sh
+++ b/t/t9903-bash-prompt.sh
@@ -35,6 +35,8 @@ test_expect_success 'setup for prompt tests' '
 	git commit -m "another b2" file &&
 	echo 000 >file &&
 	git commit -m "yet another b2" file &&
+	mkdir ignored_dir &&
+	echo "ignored_dir/" >>.gitignore &&
 	git checkout master
 '
 
@@ -588,4 +590,108 @@ test_expect_success 'prompt - zsh color pc mode' '
 	test_cmp expected "$actual"
 '
 
+test_expect_success 'prompt - hide if pwd ignored - env var unset, config disabled' '
+	printf " (master)" >expected &&
+	test_config bash.hideIfPwdIgnored false &&
+	(
+		cd ignored_dir &&
+		__git_ps1 >"$actual"
+	) &&
+	test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - hide if pwd ignored - env var unset, config disabled, pc mode' '
+	printf "BEFORE: (\${__git_ps1_branch_name}):AFTER" >expected &&
+	test_config bash.hideIfPwdIgnored false &&
+	(
+		cd ignored_dir &&
+		__git_ps1 "BEFORE:" ":AFTER" &&
+		printf "%s" "$PS1" >"$actual"
+	) &&
+	test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - hide if pwd ignored - env var unset, config unset' '
+	printf " (master)" >expected &&
+	(
+		cd ignored_dir &&
+		__git_ps1 >"$actual"
+	) &&
+	test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - hide if pwd ignored - env var unset, config unset, pc mode' '
+	printf "BEFORE: (\${__git_ps1_branch_name}):AFTER" >expected &&
+	(
+		cd ignored_dir &&
+		__git_ps1 "BEFORE:" ":AFTER" &&
+		printf "%s" "$PS1" >"$actual"
+	) &&
+	test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - hide if pwd ignored - env var set, config disabled' '
+	printf " (master)" >expected &&
+	test_config bash.hideIfPwdIgnored false &&
+	(
+		cd ignored_dir &&
+		GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
+		__git_ps1 >"$actual"
+	) &&
+	test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - hide if pwd ignored - env var set, config disabled, pc mode' '
+	printf "BEFORE: (\${__git_ps1_branch_name}):AFTER" >expected &&
+	test_config bash.hideIfPwdIgnored false &&
+	(
+		cd ignored_dir &&
+		GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
+		__git_ps1 "BEFORE:" ":AFTER" &&
+		printf "%s" "$PS1" >"$actual"
+	) &&
+	test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - hide if pwd ignored - env var set, config unset' '
+	printf "" >expected &&
+	(
+		cd ignored_dir &&
+		GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
+		__git_ps1 >"$actual"
+	) &&
+	test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - hide if pwd ignored - env var set, config unset, pc mode' '
+	printf "BEFORE::AFTER" >expected &&
+	(
+		cd ignored_dir &&
+		GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
+		__git_ps1 "BEFORE:" ":AFTER" &&
+		printf "%s" "$PS1" >"$actual"
+	) &&
+	test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - hide if pwd ignored - inside gitdir (stdout)' '
+	printf " (GIT_DIR!)" >expected &&
+	(
+		GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
+		cd .git &&
+		__git_ps1 >"$actual" 2>/dev/null
+	) &&
+	test_cmp expected "$actual"
+'
+
+test_expect_success 'prompt - hide if pwd ignored - inside gitdir (stderr)' '
+	printf "" >expected &&
+	(
+		GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
+		cd .git &&
+		__git_ps1 >/dev/null 2>"$actual"
+	) &&
+	test_cmp expected "$actual"
+'
+
 test_done
-- 
2.2.1

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH v5 1/2] git-prompt.sh: if pc mode, immediately set PS1
  2015-01-07  1:22                           ` [PATCH v5 1/2] git-prompt.sh: if pc mode, immediately set PS1 to a plain prompt Richard Hansen
@ 2015-01-14 11:45                             ` SZEDER Gábor
  0 siblings, 0 replies; 18+ messages in thread
From: SZEDER Gábor @ 2015-01-14 11:45 UTC (permalink / raw)
  To: Richard Hansen; +Cc: gitster, j6t, jess.austin, git

Hi,


Quoting Richard Hansen <rhansen@bbn.com>:
> At the beginning of __git_ps1, right after determining that the
> function is running in pc mode, set PS1 to a plain (undecorated)
> prompt.  This makes it possible to simply return early without having
> to set PS1 if the prompt should not be decorated.
>
> Signed-off-by: Richard Hansen <rhansen@bbn.com>
> ---
>   contrib/completion/git-prompt.sh | 11 ++++-------
>   1 file changed, 4 insertions(+), 7 deletions(-)
>
> diff --git a/contrib/completion/git-prompt.sh
> b/contrib/completion/git-prompt.sh
> index 729f769..b0de082 100644
> --- a/contrib/completion/git-prompt.sh
> +++ b/contrib/completion/git-prompt.sh
> @@ -299,6 +299,10 @@ __git_ps1 ()
>   			ps1pc_start="$1"
>   			ps1pc_end="$2"
>   			printf_format="${3:-$printf_format}"
> +			# set PS1 to a plain prompt so that we can
> +			# simply return early if the prompt should not
> +			# be decorated
> +			PS1="$ps1pc_start$ps1pc_end"
>   		;;
>   		0|1)	printf_format="${1:-$printf_format}"
>   		;;
> @@ -350,10 +354,6 @@ __git_ps1 ()
>   	rev_parse_exit_code="$?"
>
>   	if [ -z "$repo_info" ]; then
> -		if [ $pcmode = yes ]; then
> -			#In PC mode PS1 always needs to be set
> -			PS1="$ps1pc_start$ps1pc_end"
> -		fi
>   		return
>   	fi
>
> @@ -412,9 +412,6 @@ __git_ps1 ()
>   		else
>   			local head=""
>   			if ! __git_eread "$g/HEAD" head; then
> -				if [ $pcmode = yes ]; then
> -					PS1="$ps1pc_start$ps1pc_end"
> -				fi
>   				return
>   			fi
>   			# is it a symbolic ref?
> --
> 2.2.1

As the one responsible for the last hunk I really like this change.

Thanks,
Gábor

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2015-01-14 11:45 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-08 19:04 [PATCH] git-prompt.sh: Omit prompt for ignored directories Jess Austin
2014-10-08 21:12 ` Richard Hansen
     [not found]   ` <CANp8Xb8ETG-ZFCqrOk=f-RbxtRxehBmAR1O5ozLH80zimWq_Gw@mail.gmail.com>
2014-10-08 21:37     ` Fwd: " Jess Austin
2014-10-09  5:37       ` Richard Hansen
2014-10-09 10:27         ` Jess Austin
2014-10-09 22:09           ` Richard Hansen
2014-10-14  2:32             ` [PATCH] git-prompt.sh: Hide prompt for ignored pwd Jess Austin
2014-10-14 18:47               ` Johannes Sixt
2014-10-14 19:08                 ` Richard Hansen
2014-10-15  4:06                 ` [PATCH] git-prompt.sh: Option to hide " Jess Austin
2014-10-15 20:28                   ` Richard Hansen
2015-01-05  7:03                     ` [PATCH v4] " Richard Hansen
2015-01-06 23:31                       ` Junio C Hamano
2015-01-07  1:22                         ` [PATCH v5 0/2] " Richard Hansen
2015-01-07  1:22                           ` [PATCH v5 1/2] git-prompt.sh: if pc mode, immediately set PS1 to a plain prompt Richard Hansen
2015-01-14 11:45                             ` [PATCH v5 1/2] git-prompt.sh: if pc mode, immediately set PS1 SZEDER Gábor
2015-01-07  1:22                           ` [PATCH v5 2/2] git-prompt.sh: Option to hide prompt for ignored pwd Richard Hansen
2014-10-14 19:21               ` [PATCH] git-prompt.sh: Hide " Richard Hansen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.