public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Richard Hansen <rhansen@bbn•com>
To: Jess Austin <jess.austin@gmail•com>
Cc: Johannes Sixt <j6t@kdbg•org>, git@vger•kernel.org
Subject: Re: [PATCH] git-prompt.sh: Option to hide prompt for ignored pwd
Date: Wed, 15 Oct 2014 16:28:54 -0400	[thread overview]
Message-ID: <543ED906.403@bbn.com> (raw)
In-Reply-To: <1413345993-14393-1-git-send-email-jess.austin@gmail.com>

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

  reply	other threads:[~2014-10-15 20:29 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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-14 19:21               ` Richard Hansen
2014-10-15  4:06                 ` [PATCH] git-prompt.sh: Option to hide " Jess Austin
2014-10-15 20:28                   ` Richard Hansen [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=543ED906.403@bbn.com \
    --to=rhansen@bbn$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=j6t@kdbg$(echo .)org \
    --cc=jess.austin@gmail$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox