From mboxrd@z Thu Jan 1 00:00:00 1970 From: SZEDER =?iso-8859-1?Q?G=E1bor?= Subject: Re: Bash tab completion for _git_fetch alias is broken on Git 1.7.7.1 Date: Thu, 10 Nov 2011 16:14:12 +0100 Message-ID: <20111110151412.GA11479@goldbirke> References: <7vehxgu0fy.fsf@alter.siamese.dyndns.org> <4EBB78C7.101@viscovery.net> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: Johannes Sixt , Junio C Hamano , To: Nathan Broadbent X-From: git-owner@vger.kernel.org Thu Nov 10 16:14:25 2011 Return-path: Envelope-to: gcvg-git-2@lo.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ROWKe-0005wO-Rb for gcvg-git-2@lo.gmane.org; Thu, 10 Nov 2011 16:14:25 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757705Ab1KJPOT convert rfc822-to-quoted-printable (ORCPT ); Thu, 10 Nov 2011 10:14:19 -0500 Received: from ex-e-1.perimeter.fzi.de ([141.21.8.250]:37678 "EHLO EX-E-1.perimeter.fzi.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751308Ab1KJPOT (ORCPT ); Thu, 10 Nov 2011 10:14:19 -0500 Received: from ex-ca-ht-1.fzi.de (141.21.32.98) by EX-E-1.perimeter.fzi.de (141.21.8.250) with Microsoft SMTP Server (TLS) id 14.1.339.1; Thu, 10 Nov 2011 16:20:49 +0100 Received: from localhost6.localdomain6 (141.21.50.31) by ex-ca-ht-1.fzi.de (141.21.32.98) with Microsoft SMTP Server (TLS) id 14.1.339.1; Thu, 10 Nov 2011 16:14:15 +0100 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: Hi, =20 [Please don't top-post.] > On Thu, Nov 10, 2011 at 3:09 PM, Johannes Sixt = wrote: > > > > Am 11/10/2011 4:21, schrieb Junio C Hamano: > > > Nathan Broadbent writes: > > > > > >> Dear git mailing list, > > >> > > >> I'm assigning the `_git_fetch` bash tab completion to the alias = `gf`, > > >> with the following command: > > >> > > >> =A0 =A0 complete -o default -o nospace -F _git_fetch gf I assume you have an alias gf=3D"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_() 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_() 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: > 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_ completion functions but not in __git_() helper functions. This way _git_() 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 =3D: 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 ' 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=E1bor