Re: [RFC PATCH 18/19] bash prompt: avoid command substitution when checking for untracked files
- From
Junio C Hamano <gitster@pobox.com>
- Date
- May 9, 2012, 20:32 UTC
- Message-ID
- <7vr4utqemg.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <1336524290-30023-19-git-send-email-szeder@ira.uka.de>
SZEDER Gábor <szeder@ira.uka.de> writes:
Show 7 quoted lines
> 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 $?
0The first two cases seem to be fine, but isn't the last one showing that your update is incorrect?
Show 26 quoted lines
>
> Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
> ---
>
> 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