Re: Bash tab completion for _git_fetch alias is broken on Git 1.7.7.1
Hi,
[Please don't top-post.]
Show 11 quoted lines
> On Thu, Nov 10, 2011 at 3:09 PM, Johannes Sixt <j.sixt@viscovery.net> wrote:
> >
> > Am 11/10/2011 4:21, schrieb Junio C Hamano:
> > > Nathan Broadbent <nathan.f77@gmail.com> writes:
> > >
> > >> Dear git mailing list,
> > >>
> > >> I'm assigning the `_git_fetch` bash tab completion to the alias `gf`,
> > >> with the following command:
> > >>
> > >> complete -o default -o nospace -F _git_fetch gf
I assume you have an
alias gf="git fetch"
somewhere, right?
> > >> The tab completion then works fine in git 1.7.0.4, but breaks on git
> > >> 1.7.7.1, with the following error:
I didn't actually tried, but I guess this is a side-effect of da4902a7 (completion: remove unnecessary _get_comp_words_by_ref() invocations, 2011-04-28), which was in v1.7.6. Since the clean-up in that commit we only call _get_comp_words_by_ref() in the top-level completion functions _git() and _gitk() to populate completion-related variables ($cur, $prev, $words, $cword), so invoking any _git_<cmd>() completion function directly causes an error or wrong behavior, because all those variables are empty.
Calling a completion function directly was not an issue earlier, because every _git_<cmd>() completion function invoked _get_comp_words_by_ref() to populate those variables, or in the pre-_get_comp_words_by_ref() times they just accessed the completion-related bash variables $COMP_WORDS and $COMP_CWORD directly.
On Thu, Nov 10, 2011 at 04:52:33PM +0800, Nathan Broadbent wrote:
Show 8 quoted lines
> So, this is a feature, not a bug... Tab completion for aliases is
> really useful. It's important enough to me that I won't stop until
> I've found a solution.
> I can appreciate that _git_fetch is not currently meant to be called
> directly, but we found a way to utilize it when it previously worked.
> Perhaps the scope of these completion functions could be expanded to
> allow for aliases? I'll attempt to submit a patch if someone can give
> me approval.
The quickest way would be to just revert da4902a7, but it would be the dirtiest, too: it would bring back a lot of redundant calls to _get_comp_words_by_ref() and it might have side-effects under zsh (but I didn't think this through).
It would be a bit more clever to revert only parts of da4902a7, i.e. to bring back _get_comp_words_by_ref() calls in _git_<cmd> completion functions but not in __git_<whatever>() helper functions. This way _git_<cmd>() functions would have their completion-related variables initialized even when called directly instead through _git(), and _get_comp_words_by_ref() would be called "only" twice during a single completion. But that's still one too many, and again: there can be issues with zsh.
Alternatively, you could easily create your own wrapper function around _git_fetch(), like this:
_gf () {
local cur prev words cword
_get_comp_words_by_ref -n =: cur prev words cword
_git_fetch
}However.
Having said all that, I'd like to point out that even if _git_fetch() didn't error out when called for the 'gf' alias, it still wouldn't work properly. After 'gf origin <TAB>' it offers the list of remotes again and it never offers refspecs, because it calls __git_complete_remote_or_refspec(), which
- depends on the fact that there must be at least two words ('git'
and 'fetch') on the command line before the remote, and - needs to know the git command (i.e. fetch, pull, or push) to offer
the proper refspecs, but it can't find that out from your alias.
Best, Gábor