{"thread":{"id":"55945","subject":"Error in bash completion","startedAt":"2021-06-16T15:49:23Z","lastAt":"2021-06-17T02:15:40Z","messageCount":6,"participants":["Harrison McCullough","Denton Liu","Felipe Contreras"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"427619","messageId":"CAHLeu+y3DxLv7M4SM2f5yVxtKXbpAWD7Ad2m+rVKpKfKiA6PVw@mail.gmail.com","threadId":"55945","inReplyTo":null,"subject":"Error in bash completion","fromName":"Harrison McCullough","fromEmail":"mccullough.harrison@gmail.com","sentAt":"2021-06-16T15:44:38Z","receivedAt":"2021-06-16T15:49:23Z","isPatch":false,"sender":{"key":"mccullough.harrison@gmail.com","avatar":null},"body":"What did you do before the bug happened? (Steps to reproduce your issue)\n\n1. Create a Bash function, e.g. `ga() { git add \"${@:-.}\"; }`\n2. Use the `__git_complete` function to add Bash tab completion for your custom\n   Bash function, e.g. `__git_complete ga git_add`\n3. Attempt to tab complete a file path, e.g. `ga my-incomplete-file-path<TAB>`\n\n\nWhat did you expect to happen? (Expected behavior)\n\nBash tab-completes the file path.\n\n\nWhat happened instead? (Actual behavior)\n\nBash tab-completes the file path but also displays an error:\n\n$ ga fi-bash: [: -lt: unary operator expected\nle3.txt\n\n(This is when I was using tab completion to add a file called `file3.txt`).\n\n\nWhat's different between what you expected and what actually happened?\n\nI do not expect using tab completion to display an error.\n\n\nAnything else you want to add:\n\nI have tested this with a minial setup with Bash version 5.1.8(1)-release with\nno other files sourced at startup except\n/usr/local/Cellar/git/2.32.0/etc/bash_completion.d/git-completion.bash\n\n[System Info]\ngit version:\ngit version 2.32.0\ncpu: x86_64\nno commit associated with this build\nsizeof-long: 8\nsizeof-size_t: 8\nshell-path: /bin/sh\nuname: Darwin 20.5.0 Darwin Kernel Version 20.5.0: Sat May  8 05:10:33\nPDT 2021; root:xnu-7195.121.3~9/RELEASE_X86_64 x86_64\ncompiler info: clang: 12.0.5 (clang-1205.0.22.9)\nlibc info: no libc information available\n$SHELL (typically, interactive shell): /usr/local/bin/bash\n\n\n[Enabled Hooks]\n\n-Harrison McCullough\n"},{"id":"427624","messageId":"YMo3j6mqiKBTTEbS@generichostname","threadId":"55945","inReplyTo":"CAHLeu+y3DxLv7M4SM2f5yVxtKXbpAWD7Ad2m+rVKpKfKiA6PVw@mail.gmail.com","subject":"Re: Error in bash completion","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2021-06-16T17:40:31Z","receivedAt":"2021-06-16T17:40:39Z","isPatch":false,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"Hi Harrison,\n\nOn Wed, Jun 16, 2021 at 09:44:38AM -0600, Harrison McCullough wrote:\n> What did you do before the bug happened? (Steps to reproduce your issue)\n> \n> 1. Create a Bash function, e.g. `ga() { git add \"${@:-.}\"; }`\n> 2. Use the `__git_complete` function to add Bash tab completion for your custom\n>    Bash function, e.g. `__git_complete ga git_add`\n> 3. Attempt to tab complete a file path, e.g. `ga my-incomplete-file-path<TAB>`\n> \n> \n> What did you expect to happen? (Expected behavior)\n> \n> Bash tab-completes the file path.\n> \n> \n> What happened instead? (Actual behavior)\n> \n> Bash tab-completes the file path but also displays an error:\n> \n> $ ga fi-bash: [: -lt: unary operator expected\n> le3.txt\n\nThis happened as a result of my changes at e94fb44042\n(git-completion.bash: pass $__git_subcommand_idx from __git_main(),\n2021-03-24) and 87e629756f (git-completion.bash: rename to\n$__git_cmd_idx, 2021-04-22).\n\nThe tl;dr is that $__git_cmd_idx must be set to the index of the\ngit command you're executing (e.g. for `git add`, the index of `add`).\nAs a workaround for you, try setting __git_cmd_idx=0 where you define\nga().\n\nNow, a question to the wider list: does git-completion.bash have a\npublic interface? I've been working off the assumption that any time a\nuser uses the internals, it's at their own risk. Is this a valid\nassumption to make?\n\n-Denton\n"},{"id":"427627","messageId":"CAHLeu+xC+ecEidoofXsOqSdT4fmf=5A1PAnHzbFPqCiPr5D+BA@mail.gmail.com","threadId":"55945","inReplyTo":"YMo3j6mqiKBTTEbS@generichostname","subject":"Re: Error in bash completion","fromName":"Harrison McCullough","fromEmail":"mccullough.harrison@gmail.com","sentAt":"2021-06-16T18:05:30Z","receivedAt":"2021-06-16T18:05:47Z","isPatch":false,"sender":{"key":"mccullough.harrison@gmail.com","avatar":null},"body":"I don't have any knowledge of the expectations regarding Git internals, but I\nthink it would be good to note that lines 32-33 of `git-completion.bash` say\nthis:\n\n    If you have a command that is not part of git, but you would still\n    like completion, you can use __git_complete:\n\nFor me that would imply that the `__git_complete` function is intended to be a\n\"public interface\", but maybe I'm reading it wrong.\n\n-Harrison McCullough\n\nOn Wed, Jun 16, 2021 at 11:40 AM Denton Liu <liu.denton@gmail.com> wrote:\n>\n> Hi Harrison,\n>\n> On Wed, Jun 16, 2021 at 09:44:38AM -0600, Harrison McCullough wrote:\n> > What did you do before the bug happened? (Steps to reproduce your issue)\n> >\n> > 1. Create a Bash function, e.g. `ga() { git add \"${@:-.}\"; }`\n> > 2. Use the `__git_complete` function to add Bash tab completion for your custom\n> >    Bash function, e.g. `__git_complete ga git_add`\n> > 3. Attempt to tab complete a file path, e.g. `ga my-incomplete-file-path<TAB>`\n> >\n> >\n> > What did you expect to happen? (Expected behavior)\n> >\n> > Bash tab-completes the file path.\n> >\n> >\n> > What happened instead? (Actual behavior)\n> >\n> > Bash tab-completes the file path but also displays an error:\n> >\n> > $ ga fi-bash: [: -lt: unary operator expected\n> > le3.txt\n>\n> This happened as a result of my changes at e94fb44042\n> (git-completion.bash: pass $__git_subcommand_idx from __git_main(),\n> 2021-03-24) and 87e629756f (git-completion.bash: rename to\n> $__git_cmd_idx, 2021-04-22).\n>\n> The tl;dr is that $__git_cmd_idx must be set to the index of the\n> git command you're executing (e.g. for `git add`, the index of `add`).\n> As a workaround for you, try setting __git_cmd_idx=0 where you define\n> ga().\n>\n> Now, a question to the wider list: does git-completion.bash have a\n> public interface? I've been working off the assumption that any time a\n> user uses the internals, it's at their own risk. Is this a valid\n> assumption to make?\n>\n> -Denton\n"},{"id":"427629","messageId":"60ca4ec28b0f9_56f520855@natae.notmuch","threadId":"55945","inReplyTo":"YMo3j6mqiKBTTEbS@generichostname","subject":"Re: Error in bash completion","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-06-16T19:19:30Z","receivedAt":"2021-06-16T19:19:36Z","isPatch":false,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Denton Liu wrote:\n> Hi Harrison,\n> \n> On Wed, Jun 16, 2021 at 09:44:38AM -0600, Harrison McCullough wrote:\n> > What did you do before the bug happened? (Steps to reproduce your issue)\n> > \n> > 1. Create a Bash function, e.g. `ga() { git add \"${@:-.}\"; }`\n> > 2. Use the `__git_complete` function to add Bash tab completion for your custom\n> >    Bash function, e.g. `__git_complete ga git_add`\n> > 3. Attempt to tab complete a file path, e.g. `ga my-incomplete-file-path<TAB>`\n> > \n> > \n> > What did you expect to happen? (Expected behavior)\n> > \n> > Bash tab-completes the file path.\n> > \n> > \n> > What happened instead? (Actual behavior)\n> > \n> > Bash tab-completes the file path but also displays an error:\n> > \n> > $ ga fi-bash: [: -lt: unary operator expected\n> > le3.txt\n> \n> This happened as a result of my changes at e94fb44042\n> (git-completion.bash: pass $__git_subcommand_idx from __git_main(),\n> 2021-03-24) and 87e629756f (git-completion.bash: rename to\n> $__git_cmd_idx, 2021-04-22).\n> \n> The tl;dr is that $__git_cmd_idx must be set to the index of the\n> git command you're executing (e.g. for `git add`, the index of `add`).\n> As a workaround for you, try setting __git_cmd_idx=0 where you define\n> ga().\n> \n> Now, a question to the wider list: does git-completion.bash have a\n> public interface? I've been working off the assumption that any time a\n> user uses the internals, it's at their own risk. Is this a valid\n> assumption to make?\n\nTraditionally that was a valid assumption, although in reality people\nhave been using __git_complete for many years.\n\nSince 5a067ba9d0 (completion: add proper public __git_complete,\n2020-12-30) __git_complete became officially public, and the internal\none is ___git_complete.\n\nPerhaps we could set __git_cmd_idx in __git_complete, but we would also\nneed to consider the zsh equivalent of __git_complete, which is compdef.\n\n-- \nFelipe Contreras\n"},{"id":"427650","messageId":"60caae2f893ec_894e2085d@natae.notmuch","threadId":"55945","inReplyTo":"CAHLeu+y3DxLv7M4SM2f5yVxtKXbpAWD7Ad2m+rVKpKfKiA6PVw@mail.gmail.com","subject":"RE: Error in bash completion","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-06-17T02:06:39Z","receivedAt":"2021-06-17T02:06:53Z","isPatch":false,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Harrison McCullough wrote:\n> What did you do before the bug happened? (Steps to reproduce your issue)\n> \n> 1. Create a Bash function, e.g. `ga() { git add \"${@:-.}\"; }`\n> 2. Use the `__git_complete` function to add Bash tab completion for your custom\n>    Bash function, e.g. `__git_complete ga git_add`\n> 3. Attempt to tab complete a file path, e.g. `ga my-incomplete-file-path<TAB>`\n\nI can reproduce this issue; it's caused by 59d85a2a05\n(git-completion.bash: use $__git_cmd_idx in more places, 2021-04-22)\nwhich is present in v2.32.\n\nThe problem is that __git_find_on_cmdline now relies on __git_cmd_idx,\nwhich is not defined when you do __git_complete.\n\nThe solution is to add __git_cmd_idx=1 to __git_func_wrap.\n\nzsh is also broken by the same change, and the fix is to do the same in\nthe _git service.\n\nI've fixed this in git-completion's master branch [1].\n\nYou are welcome to trying the fix.\n\nCheers.\n\n[1] https://github.com/felipec/git-completion/commit/95b3b49\n[2] https://github.com/git/git/commit/59d85a2a05\n\n-- \nFelipe Contreras\n"},{"id":"427651","messageId":"CAHLeu+zcgrhvdqMWG1GegSP-y6CmJsJranxX-2MEGkhTaWWHMw@mail.gmail.com","threadId":"55945","inReplyTo":"60caae2f893ec_894e2085d@natae.notmuch","subject":"Re: Error in bash completion","fromName":"Harrison McCullough","fromEmail":"mccullough.harrison@gmail.com","sentAt":"2021-06-17T02:15:23Z","receivedAt":"2021-06-17T02:15:40Z","isPatch":false,"sender":{"key":"mccullough.harrison@gmail.com","avatar":null},"body":"I can verify that this fix works. Thank you for the quick response!\n\n-Harrison McCullough\n\nOn Wed, Jun 16, 2021 at 8:06 PM Felipe Contreras\n<felipe.contreras@gmail.com> wrote:\n>\n> Harrison McCullough wrote:\n> > What did you do before the bug happened? (Steps to reproduce your issue)\n> >\n> > 1. Create a Bash function, e.g. `ga() { git add \"${@:-.}\"; }`\n> > 2. Use the `__git_complete` function to add Bash tab completion for your custom\n> >    Bash function, e.g. `__git_complete ga git_add`\n> > 3. Attempt to tab complete a file path, e.g. `ga my-incomplete-file-path<TAB>`\n>\n> I can reproduce this issue; it's caused by 59d85a2a05\n> (git-completion.bash: use $__git_cmd_idx in more places, 2021-04-22)\n> which is present in v2.32.\n>\n> The problem is that __git_find_on_cmdline now relies on __git_cmd_idx,\n> which is not defined when you do __git_complete.\n>\n> The solution is to add __git_cmd_idx=1 to __git_func_wrap.\n>\n> zsh is also broken by the same change, and the fix is to do the same in\n> the _git service.\n>\n> I've fixed this in git-completion's master branch [1].\n>\n> You are welcome to trying the fix.\n>\n> Cheers.\n>\n> [1] https://github.com/felipec/git-completion/commit/95b3b49\n> [2] https://github.com/git/git/commit/59d85a2a05\n>\n> --\n> Felipe Contreras\n"}]}