git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] completion: treat unset GIT_COMPLETION_SHOW_ALL gracefully

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 6, 2021, 22:16 UTC
Message-ID
<xmqqo8er12kq.fsf@gitster.g>
In-Reply-To
<20210406181247.250046-1-ville.skytta@iki.fi>
Ville Skyttä <ville.skytta@iki.fi> writes:
Show 7 quoted lines
> If not set, referencing it in nounset (set -u) mode unguarded produces
> an error.
>
> Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>
> ---
>  contrib/completion/git-completion.bash | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
Thanks.
$ git grep -h -o -e '\$GIT_[A-Z_]*' master -- contrib/completion/git-completion.bash
gives a few other hits.

$GIT_DIR $GIT_COMPLETION_SHOW_ALL $GIT_TESTING_ALL_COMMAND_LIST $GIT_TESTING_ALL_COMMAND_LIST $GIT_TESTING_PORCELAIN_COMMAND_LIST

Have you gone through all of these hits?
I just checked that the reference to $GIT_DIR is safe.
        elif [ -n "${GIT_DIR-}" ]; then
                test -d "${GIT_DIR-}" &&
                __git_repo_path="$GIT_DIR"

In fact, after checking "is this non-empty?", the form used to see "is this a directory" does not even need to be "${VAR-}".

Among the two references to GIT_TESTING_ALL_COMMAND_LIST, the first one does not look safe to me, and that is what made me take a look myself. It probably wants to follow the same pattern as above, doesn't it? Or am I reading the code incorrectly and the use there is safe?

Reference to $GIT_TESTING_PORCELAIN_COMMAND_LIST is safe, as it follows the same "if test -n "${VAR-}"; then use "$VAR"; fi" pattern.

So, this patch definitely looks like an improvement, but if there are so few remaining issues, I'd prefer to see that (1) the proposed log message explain that the patch author audited all usages of variables and updated all "-u"-unsafe ones, and (2) the patch actually does update all remaining problematic ones.

If I am wrong about TESTING_ALL_COMMAND_LIST, then (2) may already be true, but then we want to describe that fact in the log message even more. It would ensure that future developers understand that ${VAR-} constructs are no accident and we are striving to make the script "-u"-safe.

Thanks.
Show 13 quoted lines
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index e1a66954fe..6d77f56f92 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -427,7 +427,7 @@ __gitcomp_builtin ()
>  
>  	if [ -z "$options" ]; then
>  		local completion_helper
> -		if [ "$GIT_COMPLETION_SHOW_ALL" = "1" ]; then
> +		if [ "${GIT_COMPLETION_SHOW_ALL-}" = "1" ]; then
>  			completion_helper="--git-completion-helper-all"
>  		else
>  			completion_helper="--git-completion-helper"
Previous: Ville SkyttäNext: Ville Skyttä
Message 2 of 3 in “completion: treat unset GIT_COMPLETION_SHOW_ALL gracefully”
  1. completion: treat unset GIT_COMPLETION_SHOW_ALL gracefullyVille Skyttä, Apr 6, 2021
  2. Junio C HamanoApr 6, 2021
  3. Ville SkyttäApr 8, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.