Re: [PATCH 1/2] completion: add a helper function to get config variables
- From
SZEDER Gábor <szeder@ira.uka.de>
- Date
- May 10, 2015, 13:16 UTC
- Message-ID
- <20150510151652.Horde.FOfYcnwZZkdBJUYkl0pDQg1@webmail.informatik.kit.edu>
- In-Reply-To
- <1431262218-7304-1-git-send-email-szeder@ira.uka.de>
Quoting SZEDER Gábor <szeder@ira.uka.de>:
Show 31 quoted lines
> Currently there are a few completion functions that perform similar 'git
> config' queries and filtering to get config variable names: the completion
> of pretty aliases, aliases, and remote groups for 'git remote update'.
>
> Unify those 'git config' queries in a helper function to eliminate code
> duplication.
>
> Though the helper functions to get pretty aliases and alieses are reduced
> to mere one-liner wrappers around the newly added function, keep these
> helpers still, because users' completion functions out there might depend
> on them. And they keep their callers a tad easier to read, too.
>
> Add tests for the pretty alias and alias helper to show that they work
> as before; not for the remote groups query, though, because that's not
> extracted into a helper function and it's not worth the effort to do so
> for a sole callsite.
>
> Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
> ---
> @@ -2260,12 +2259,7 @@ _git_remote ()
> __git_complete_remote_or_refspec
> ;;
> update)
> - local i c='' IFS=$'\n'
> - for i in $(git --git-dir="$(__gitdir)" config --get-regexp
> "remotes\..*" 2>/dev/null); do
> - i="${i#remotes.}"
> - c="$c ${i/ */}"
> - done
> - __gitcomp "$c"
> + __gitcomp "$(__git_get_config_variables "remotes")"I just noticed that this query for remote groups does lack that filtering case statement eliminated in the next patch and the regex is not limited to the beginning of the config variable name. So, let's suppose we have a branch named 'remotes', for which we add a branch description (and no remote groups, for symplicity's sake):
$ git config branch.remotes.description uh-oh $ git remote update <TAB>
This will complete to:
$ git remote update branch.remotes.description
and that's obviously bad.
This series fixes this.
Best, Gábor