Re: [RFC PATCH 18/19] bash prompt: avoid command substitution when checking for untracked files

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



SZEDER Gábor <szeder@xxxxxxxxxx> writes:

> When enabled, the bash prompt can indicate the presence of untracked
> files with a '%' sign.  __git_ps1() checks for untracked files by running the
> '$(git ls-files --others --exclude-standard)' command substitution,
> and displays the indicator when there is no output.
>
> Avoid this command substitution by additionally passing
> '--error-unmatch *', and checking the command's return value.

This is too subtle and needs to be explained in a in-code comment.  For
example, it is unclear to me how this '*' pathspec and an untracked file
that does not fnmatch(3) with the pattern (e.g. ".trash").


        $ rm -fr /var/tmp/x && git init /var/tmp/x && cd /var/tmp/x
	$ args='ls-files --others --exclude-standard'

	$ git $args | wc -l
        0
        $ git $args --error-unmatch -- '*' >/dev/null 2>&1 ; echo $?
        1

        $ >a
        $ git $args | wc -l
	1
        $ git $args --error-unmatch -- '*' >/dev/null 2>&1 ; echo $?
	0

	$ mv a .a
        $ git $args | wc -l
	1
        $ git $args --error-unmatch -- '*' >/dev/null 2>&1 ; echo $?
	0

The first two cases seem to be fine, but isn't the last one showing that
your update is incorrect?

>
> Signed-off-by: SZEDER Gábor <szeder@xxxxxxxxxx>
> ---
>
> This seems to do the right thing, but I'm not quite sure, so I would
> appreciate a pair of expert eyeballs on it.
>
>  contrib/completion/git-completion.bash | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index c4feab68..5ea19018 100755
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -348,9 +348,8 @@ __git_ps1 ()
>  			fi
>  
>  			if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
> -				if [ -n "$(git ls-files --others --exclude-standard)" ]; then
> -					u="%"
> -				fi
> +				git ls-files --others --exclude-standard --error-unmatch -- '*' >/dev/null 2>/dev/null &&
> +				u="%"
>  			fi
>  		fi
>  	fi
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]