{"thread":{"id":"28900","subject":"Bash tab completion for _git_fetch alias is broken on Git 1.7.7.1","startedAt":"2011-11-10T02:46:06Z","lastAt":"2011-11-12T17:53:32Z","messageCount":9,"participants":["Nathan Broadbent","Junio C Hamano","Johannes Sixt","SZEDER Gábor","Scott Bronson"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"179233","messageId":"CAPXHQbND61TyU21ckHwRyMYH=P=H7+GZR5KNY8m+qaMEEhEZKQ@mail.gmail.com","threadId":"28900","inReplyTo":"CAPXHQbPgepSFHX63F+Nt8TJ+znAaVqzzmSZmJqxj2mekhStO-g@mail.gmail.com","subject":"Bash tab completion for _git_fetch alias is broken on Git 1.7.7.1","fromName":"Nathan Broadbent","fromEmail":"nathan.f77@gmail.com","sentAt":"2011-11-10T02:46:06Z","receivedAt":"2011-11-10T02:46:06Z","isPatch":false,"sender":{"key":"nathan.f77@gmail.com","avatar":"https://gravatar.com/avatar/04c985b22bf73709b7ef435ab9b5d707646972663afced8d5dad619666ce2409?d=mp&s=160"},"body":"Dear git mailing list,\n\nI'm assigning the `_git_fetch` bash tab completion to the alias `gf`,\nwith the following command:\n\n    complete -o default -o nospace -F _git_fetch gf\n\nThe tab completion then works fine in git 1.7.0.4, but breaks on git\n1.7.7.1, with the following error:\n\n    -bash: [: 2: unary operator expected\n\n\nHere is the related issue on github (the project is a set of git shortcuts):\nhttps://github.com/ndbroadbent/scm_breeze/issues/11\n\n\nThanks for your time, I'd really appreciate some help!\n\n\nRegards,\nNathan B\n"},{"id":"179234","messageId":"7vehxgu0fy.fsf@alter.siamese.dyndns.org","threadId":"28900","inReplyTo":"CAPXHQbND61TyU21ckHwRyMYH=P=H7+GZR5KNY8m+qaMEEhEZKQ@mail.gmail.com","subject":"Re: Bash tab completion for _git_fetch alias is broken on Git 1.7.7.1","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-11-10T03:21:37Z","receivedAt":"2011-11-10T03:21:37Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nathan Broadbent <nathan.f77@gmail.com> writes:\n\n> Dear git mailing list,\n>\n> I'm assigning the `_git_fetch` bash tab completion to the alias `gf`,\n> with the following command:\n>\n>     complete -o default -o nospace -F _git_fetch gf\n>\n> The tab completion then works fine in git 1.7.0.4, but breaks on git\n> 1.7.7.1, with the following error:\n\nWe have been cooking for 1.7.8 and have the first release candidate\n1.7.8-rc1; could you try it and report what you find out?\n"},{"id":"179237","messageId":"4EBB78C7.101@viscovery.net","threadId":"28900","inReplyTo":"7vehxgu0fy.fsf@alter.siamese.dyndns.org","subject":"Re: Bash tab completion for _git_fetch alias is broken on Git 1.7.7.1","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2011-11-10T07:09:59Z","receivedAt":"2011-11-10T07:09:59Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 11/10/2011 4:21, schrieb Junio C Hamano:\n> Nathan Broadbent <nathan.f77@gmail.com> writes:\n> \n>> Dear git mailing list,\n>>\n>> I'm assigning the `_git_fetch` bash tab completion to the alias `gf`,\n>> with the following command:\n>>\n>>     complete -o default -o nospace -F _git_fetch gf\n>>\n>> The tab completion then works fine in git 1.7.0.4, but breaks on git\n>> 1.7.7.1, with the following error:\n> \n> We have been cooking for 1.7.8 and have the first release candidate\n> 1.7.8-rc1; could you try it and report what you find out?\n\nIt looks like _git_fetch is not meant to be called directly. All git\ncompletions must go through _git.\n\nSee also this post:\n\nhttp://thread.gmane.org/gmane.comp.version-control.msysgit/13310/focus=13335\n\n-- Hannes\n"},{"id":"179270","messageId":"CAPXHQbP4yCzZ96WEKuHsV_8Pny0MRzcLOY7qi5W3_L_5CnY0vA@mail.gmail.com","threadId":"28900","inReplyTo":"4EBB78C7.101@viscovery.net","subject":"Re: Bash tab completion for _git_fetch alias is broken on Git 1.7.7.1","fromName":"Nathan Broadbent","fromEmail":"nathan.f77@gmail.com","sentAt":"2011-11-10T08:52:33Z","receivedAt":"2011-11-10T08:52:33Z","isPatch":false,"sender":{"key":"nathan.f77@gmail.com","avatar":"https://gravatar.com/avatar/04c985b22bf73709b7ef435ab9b5d707646972663afced8d5dad619666ce2409?d=mp&s=160"},"body":"So, this is a feature, not a bug... Tab completion for aliases is\nreally useful. It's important enough to me that I won't stop until\nI've found a solution.\nI can appreciate that _git_fetch is not currently meant to be called\ndirectly, but we found a way to utilize it when it previously worked.\nPerhaps the scope of these completion functions could be expanded to\nallow for aliases? I'll attempt to submit a patch if someone can give\nme approval.\n\n\nThanks,\nNathan\n\n\nOn Thu, Nov 10, 2011 at 3:09 PM, Johannes Sixt <j.sixt@viscovery.net> wrote:\n>\n> Am 11/10/2011 4:21, schrieb Junio C Hamano:\n> > Nathan Broadbent <nathan.f77@gmail.com> writes:\n> >\n> >> Dear git mailing list,\n> >>\n> >> I'm assigning the `_git_fetch` bash tab completion to the alias `gf`,\n> >> with the following command:\n> >>\n> >>     complete -o default -o nospace -F _git_fetch gf\n> >>\n> >> The tab completion then works fine in git 1.7.0.4, but breaks on git\n> >> 1.7.7.1, with the following error:\n> >\n> > We have been cooking for 1.7.8 and have the first release candidate\n> > 1.7.8-rc1; could you try it and report what you find out?\n>\n> It looks like _git_fetch is not meant to be called directly. All git\n> completions must go through _git.\n>\n> See also this post:\n>\n> http://thread.gmane.org/gmane.comp.version-control.msysgit/13310/focus=13335\n>\n> -- Hannes\n"},{"id":"179279","messageId":"CAPXHQbMXYkCGDvDPigQqEgfmP0qZhW1JVRNaEan1ByTzdTZczg@mail.gmail.com","threadId":"28900","inReplyTo":"CAPXHQbP2O2C6sDVYLB=eMu0UpdMm79t3fqopqBvNpmdpKPRsXQ@mail.gmail.com","subject":"Re: Bash tab completion for _git_fetch alias is broken on Git 1.7.7.1","fromName":"Nathan Broadbent","fromEmail":"nathan.f77@gmail.com","sentAt":"2011-11-10T14:28:56Z","receivedAt":"2011-11-10T14:28:56Z","isPatch":false,"sender":{"key":"nathan.f77@gmail.com","avatar":"https://gravatar.com/avatar/04c985b22bf73709b7ef435ab9b5d707646972663afced8d5dad619666ce2409?d=mp&s=160"},"body":"> No change with 1.7.8-rc1, tab completion still fails\n"},{"id":"179280","messageId":"20111110151412.GA11479@goldbirke","threadId":"28900","inReplyTo":"CAPXHQbP4yCzZ96WEKuHsV_8Pny0MRzcLOY7qi5W3_L_5CnY0vA@mail.gmail.com","subject":"Re: Bash tab completion for _git_fetch alias is broken on Git 1.7.7.1","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2011-11-10T15:14:12Z","receivedAt":"2011-11-10T15:14:12Z","isPatch":false,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Hi,\n\n \n[Please don't top-post.]\n\n> On Thu, Nov 10, 2011 at 3:09 PM, Johannes Sixt <j.sixt@viscovery.net> wrote:\n> >\n> > Am 11/10/2011 4:21, schrieb Junio C Hamano:\n> > > Nathan Broadbent <nathan.f77@gmail.com> writes:\n> > >\n> > >> Dear git mailing list,\n> > >>\n> > >> I'm assigning the `_git_fetch` bash tab completion to the alias `gf`,\n> > >> with the following command:\n> > >>\n> > >>     complete -o default -o nospace -F _git_fetch gf\n\nI assume you have an\n\n  alias gf=\"git fetch\"\n\nsomewhere, right?\n\n> > >> The tab completion then works fine in git 1.7.0.4, but breaks on git\n> > >> 1.7.7.1, with the following error:\n\nI didn't actually tried, but I guess this is a side-effect of da4902a7\n(completion: remove unnecessary _get_comp_words_by_ref() invocations,\n2011-04-28), which was in v1.7.6.  Since the clean-up in that commit\nwe only call _get_comp_words_by_ref() in the top-level completion\nfunctions _git() and _gitk() to populate completion-related variables\n($cur, $prev, $words, $cword), so invoking any _git_<cmd>() completion\nfunction directly causes an error or wrong behavior, because all those\nvariables are empty.\n\nCalling a completion function directly was not an issue earlier,\nbecause every _git_<cmd>() completion function invoked\n_get_comp_words_by_ref() to populate those variables, or in the\npre-_get_comp_words_by_ref() times they just accessed the\ncompletion-related bash variables $COMP_WORDS and $COMP_CWORD\ndirectly.\n\n\nOn Thu, Nov 10, 2011 at 04:52:33PM +0800, Nathan Broadbent wrote:\n> So, this is a feature, not a bug... Tab completion for aliases is\n> really useful. It's important enough to me that I won't stop until\n> I've found a solution.\n> I can appreciate that _git_fetch is not currently meant to be called\n> directly, but we found a way to utilize it when it previously worked.\n> Perhaps the scope of these completion functions could be expanded to\n> allow for aliases? I'll attempt to submit a patch if someone can give\n> me approval.\n\nThe quickest way would be to just revert da4902a7, but it would be the\ndirtiest, too: it would bring back a lot of redundant calls to\n_get_comp_words_by_ref() and it might have side-effects under zsh (but\nI didn't think this through).\n\nIt would be a bit more clever to revert only parts of da4902a7, i.e.\nto bring back _get_comp_words_by_ref() calls in _git_<cmd> completion\nfunctions but not in __git_<whatever>() helper functions.  This way\n_git_<cmd>() functions would have their completion-related variables\ninitialized even when called directly instead through _git(), and\n_get_comp_words_by_ref() would be called \"only\" twice during a single\ncompletion.  But that's still one too many, and again: there can be\nissues with zsh.\n\nAlternatively, you could easily create your own wrapper function\naround _git_fetch(), like this:\n\n_gf () {\n\tlocal cur prev words cword\n\t_get_comp_words_by_ref -n =: cur prev words cword\n\t_git_fetch\n}\n\n\nHowever.\n\nHaving said all that, I'd like to point out that even if _git_fetch()\ndidn't error out when called for the 'gf' alias, it still wouldn't\nwork properly.  After 'gf origin <TAB>' it offers the list of remotes\nagain and it never offers refspecs, because it calls\n__git_complete_remote_or_refspec(), which\n\n - depends on the fact that there must be at least two words ('git'\n   and 'fetch') on the command line before the remote, and\n\n - needs to know the git command (i.e. fetch, pull, or push) to offer\n   the proper refspecs, but it can't find that out from your alias.\n\n\nBest,\nGábor\n"},{"id":"179348","messageId":"CAKmUPx6TpbLL2GZq6G1nWPPBe=_SsqJmqXs1o9x5BxqR8y9h2Q@mail.gmail.com","threadId":"28900","inReplyTo":"20111110151412.GA11479@goldbirke","subject":"Re: Bash tab completion for _git_fetch alias is broken on Git 1.7.7.1","fromName":"Scott Bronson","fromEmail":"bronson@rinspin.com","sentAt":"2011-11-12T08:08:59Z","receivedAt":"2011-11-12T08:08:59Z","isPatch":false,"sender":{"key":"bronson@rinspin.com","avatar":null},"body":"2011/11/10 SZEDER Gábor <szeder@ira.uka.de>\n> > On Thu, Nov 10, 2011 at 3:09 PM, Johannes Sixt <j.sixt@viscovery.net> wrote:\n> > > Am 11/10/2011 4:21, schrieb Junio C Hamano:\n> > > > Nathan Broadbent <nathan.f77@gmail.com> writes:\n> > > >> Dear git mailing list,\n> > > >> I'm assigning the `_git_fetch` bash tab completion to the alias `gf`,\n> > > >> with the following command:\n> > > >>     complete -o default -o nospace -F _git_fetch gf\n> > > >> The tab completion then works fine in git 1.7.0.4, but breaks on git\n> > > >> 1.7.7.1, with the following error:\n>\n> I didn't actually tried, but I guess this is a side-effect of da4902a7\n> (completion: remove unnecessary _get_comp_words_by_ref() invocations,\n\nI looked into it and this is exactly right.\n\n\n> Alternatively, you could easily create your own wrapper function\n> around _git_fetch(), like this:\n>\n> _gf () {\n>        local cur prev words cword\n>        _get_comp_words_by_ref -n =: cur prev words cword\n>        _git_fetch\n> }\n>\n>\n> However.\n>\n> Having said all that, I'd like to point out that even if _git_fetch()\n> didn't error out when called for the 'gf' alias, it still wouldn't\n> work properly.  After 'gf origin <TAB>' it offers the list of remotes\n> again and it never offers refspecs, because it calls\n> __git_complete_remote_or_refspec(), which\n>\n>  - depends on the fact that there must be at least two words ('git'\n>   and 'fetch') on the command line before the remote, and\n>\n>  - needs to know the git command (i.e. fetch, pull, or push) to offer\n>   the proper refspecs, but it can't find that out from your alias.\n\nVery true.  But if you tweak the completion variables, you can fool\n_git_fetch into working perfectly:\n\n  _gf () {\n      COMP_LINE=\"git fetch${COMP_LINE#gf}\"\n      let COMP_POINT+=7  # strlen('git fetch') - strlen('gf')\n      COMP_WORDS=(git fetch \"${COMP_WORDS[@]:1}\")\n      let COMP_CWORD+=1\n\n      local cur words cword prev\n      _get_comp_words_by_ref -n =: cur words cword prev\n      _git_fetch\n  }\n\nCan anyone find a place where this would fail?\n\nIt would be pretty easy to write similar wrappers for _git_add,\n_git_branch, and all the rest. [*]\n\nIs there any possibility for a full set of wrappers (with better\nnames) to be merged into the git completions?  A number of\npeopl are disappointed that abbreviation completion doesn't\nwork anymore, myself included:\n  https://github.com/bobthecow/git-flow-completion/issues/2\n  https://github.com/ndbroadbent/scm_breeze/issues/11\n\nI'm happy to write them if there's a chance they'd be merged.\nThank you for all the work you've done on the completions Gábor!\n\n    - Scott\n\n\n* If I had more time, I'd be tempted to write a function that\nwould define all the wrapper functions.\n\n    define_wrapper add, ga\n    define_wrapper branch, gb\n    define_wrapper fetch, gf\n    ...\n\nNothing a little eval metaprogramming can't solve.  :)\n"},{"id":"179354","messageId":"CAKmUPx67GMmF=dbFvYGq4x3NdfhWDE++dSSzbCqL9LYAF+j9ww@mail.gmail.com","threadId":"28900","inReplyTo":"CAKmUPx6TpbLL2GZq6G1nWPPBe=_SsqJmqXs1o9x5BxqR8y9h2Q@mail.gmail.com","subject":"Re: Bash tab completion for _git_fetch alias is broken on Git 1.7.7.1","fromName":"Scott Bronson","fromEmail":"bronson@rinspin.com","sentAt":"2011-11-12T17:50:08Z","receivedAt":"2011-11-12T17:50:08Z","isPatch":false,"sender":{"key":"bronson@rinspin.com","avatar":null},"body":"2011/11/12 Scott Bronson <bronson@rinspin.com>:\n> 2011/11/10 SZEDER Gábor <szeder@ira.uka.de>\n>> > On Thu, Nov 10, 2011 at 3:09 PM, Johannes Sixt <j.sixt@viscovery.net> wrote:\n>> > > Am 11/10/2011 4:21, schrieb Junio C Hamano:\n>> > > > Nathan Broadbent <nathan.f77@gmail.com> writes:\n>> > > >> Dear git mailing list,\n>> > > >> I'm assigning the `_git_fetch` bash tab completion to the alias `gf`,\n>> > > >> with the following command:\n>> > > >>     complete -o default -o nospace -F _git_fetch gf\n>> > > >> The tab completion then works fine in git 1.7.0.4, but breaks on git\n>> > > >> 1.7.7.1, with the following error:\n>> I didn't actually tried, but I guess this is a side-effect of da4902a7\n>> (completion: remove unnecessary _get_comp_words_by_ref() invocations,\n>> ...\n>> Alternatively, you could easily create your own wrapper function\n>> around _git_fetch(), like this:\n> Very true.  But if you tweak the completion variables, you can fool\n> _git_fetch into working perfectly:\n> * If I had more time, I'd be tempted to write a function that\n> would define all the wrapper functions.\n\nI couldn't stop thinking about it last night, I had to try it.  Here's the\nresult, seems to work great:\n\n\n    __define_git_completion () {\n    eval \"\n        _git_$2_shortcut () {\n            COMP_LINE=\\\"git $2\\${COMP_LINE#$1}\\\"\n            let COMP_POINT+=$((4+${#2}-${#1}))\n            COMP_WORDS=(git $2 \\\"\\${COMP_WORDS[@]:1}\\\")\n            let COMP_CWORD+=1\n\n            local cur words cword prev\n            _get_comp_words_by_ref -n =: cur words cword prev\n            _git_$2\n        }\n    \"\n    }\n\n    __git_shortcut () {\n        type _git_$2_shortcut &>/dev/null || __define_git_completion $1 $2\n        alias $1=\"git $2 $3\"\n        complete -o default -o nospace -F _git_$2_shortcut $1\n    }\n\n    __git_shortcut  ga    add\n    __git_shortcut  gb    branch\n    __git_shortcut  gba   branch -a\n    __git_shortcut  gco   checkout\n    __git_shortcut  gci   commit -v\n    __git_shortcut  gcia  commit '-a -v'\n    __git_shortcut  gd    diff\n    __git_shortcut  gdc   diff --cached\n    __git_shortcut  gds   diff --stat\n    __git_shortcut  gf    fetch\n    __git_shortcut  gl    log\n    __git_shortcut  glp   log -p\n    __git_shortcut  gls   log --stat\n\n\nOn Github:\nhttps://github.com/bronson/dotfiles/blob/731bfd951be68f395247982ba1fb745fbed2455c/.bashrc#L81\n\nIt would be nice to see the __define_git_completion function merged\nupstram. Possible?\n\n    - Scott\n"},{"id":"179355","messageId":"CAPXHQbMo0VadLPQNV5=PtFQ8yneDeJ+rB1x+23d0iyALPF=PdA@mail.gmail.com","threadId":"28900","inReplyTo":"CAKmUPx67GMmF=dbFvYGq4x3NdfhWDE++dSSzbCqL9LYAF+j9ww@mail.gmail.com","subject":"Re: Bash tab completion for _git_fetch alias is broken on Git 1.7.7.1","fromName":"Nathan Broadbent","fromEmail":"nathan.f77@gmail.com","sentAt":"2011-11-12T17:53:32Z","receivedAt":"2011-11-12T17:53:32Z","isPatch":false,"sender":{"key":"nathan.f77@gmail.com","avatar":"https://gravatar.com/avatar/04c985b22bf73709b7ef435ab9b5d707646972663afced8d5dad619666ce2409?d=mp&s=160"},"body":"2011/11/13 Scott Bronson <bronson@rinspin.com>\n>\n> 2011/11/12 Scott Bronson <bronson@rinspin.com>:\n> > 2011/11/10 SZEDER Gábor <szeder@ira.uka.de>\n> >> > On Thu, Nov 10, 2011 at 3:09 PM, Johannes Sixt <j.sixt@viscovery.net> wrote:\n> >> > > Am 11/10/2011 4:21, schrieb Junio C Hamano:\n> >> > > > Nathan Broadbent <nathan.f77@gmail.com> writes:\n> >> > > >> Dear git mailing list,\n> >> > > >> I'm assigning the `_git_fetch` bash tab completion to the alias `gf`,\n> >> > > >> with the following command:\n> >> > > >>     complete -o default -o nospace -F _git_fetch gf\n> >> > > >> The tab completion then works fine in git 1.7.0.4, but breaks on git\n> >> > > >> 1.7.7.1, with the following error:\n> >> I didn't actually tried, but I guess this is a side-effect of da4902a7\n> >> (completion: remove unnecessary _get_comp_words_by_ref() invocations,\n> >> ...\n> >> Alternatively, you could easily create your own wrapper function\n> >> around _git_fetch(), like this:\n> > Very true.  But if you tweak the completion variables, you can fool\n> > _git_fetch into working perfectly:\n> > * If I had more time, I'd be tempted to write a function that\n> > would define all the wrapper functions.\n>\n> I couldn't stop thinking about it last night, I had to try it.  Here's the\n> result, seems to work great:\n>\n>\n>    __define_git_completion () {\n>    eval \"\n>        _git_$2_shortcut () {\n>            COMP_LINE=\\\"git $2\\${COMP_LINE#$1}\\\"\n>            let COMP_POINT+=$((4+${#2}-${#1}))\n>            COMP_WORDS=(git $2 \\\"\\${COMP_WORDS[@]:1}\\\")\n>            let COMP_CWORD+=1\n>\n>            local cur words cword prev\n>            _get_comp_words_by_ref -n =: cur words cword prev\n>            _git_$2\n>        }\n>    \"\n>    }\n>\n>    __git_shortcut () {\n>        type _git_$2_shortcut &>/dev/null || __define_git_completion $1 $2\n>        alias $1=\"git $2 $3\"\n>        complete -o default -o nospace -F _git_$2_shortcut $1\n>    }\n>\n>    __git_shortcut  ga    add\n>    __git_shortcut  gb    branch\n>    __git_shortcut  gba   branch -a\n>    __git_shortcut  gco   checkout\n>    __git_shortcut  gci   commit -v\n>    __git_shortcut  gcia  commit '-a -v'\n>    __git_shortcut  gd    diff\n>    __git_shortcut  gdc   diff --cached\n>    __git_shortcut  gds   diff --stat\n>    __git_shortcut  gf    fetch\n>    __git_shortcut  gl    log\n>    __git_shortcut  glp   log -p\n>    __git_shortcut  gls   log --stat\n>\n>\n> On Github:\n> https://github.com/bronson/dotfiles/blob/731bfd951be68f395247982ba1fb745fbed2455c/.bashrc#L81\n>\n> It would be nice to see the __define_git_completion function merged\n> upstram. Possible?\n>\n>    - Scott\n\n\nYou are amazing!!! Thanks so much for this!\n\n\nNathan\n"}]}