{"thread":{"id":"38816","subject":"[PATCH/RFC] completion: filter sources of git scripts from available commands","startedAt":"2015-03-15T20:45:48Z","lastAt":"2015-03-19T17:51:28Z","messageCount":2,"participants":["SZEDER Gábor","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"257747","messageId":"1426452348-6304-1-git-send-email-szeder@ira.uka.de","threadId":"38816","inReplyTo":null,"subject":"[PATCH/RFC] completion: filter sources of git scripts from available commands","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2015-03-15T20:45:48Z","receivedAt":"2015-03-15T20:45:48Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"A bit of background first:\n\n- The completion script gets the lists of available and porcelain git\n  commands from the output of 'git help -a', which, besides the\n  \"official\" git commands from $GIT_EXEC_PATH, includes all executables\n  from $PATH whose name begins with 'git-'.  Great, this way the\n  completion script can include the user's custom git commands that he\n  dropped somewhere in his $PATH.\n\n- The lists of available and porcelain git commands are not initialized\n  when the completion script is sourced, but it's done lazily when the\n  first git completion is performed.  Great, this way interactive shells\n  start faster, see eaa4e6ee2a (Speed up bash completion loading,\n  2009-11-17).\n\n- MSysGit's /etc/profile by default includes the current working\n  directory in $PATH.  Great, this way MSysGit Bash \"mimics the Win32\n  method of finding executables\" (quoted from /etc/profile).\n\nWhile all three things above are great by themselves, their combination,\nhowever, has unwanted side-effects: it makes the list of git commands\nnon-deterministic on MSysGit, as it will depend on the current working\ndirectory where the first git completion is performed.  Perhaps it's\nworst when it is performed at the top of a git.git clone because the\nsource files of all git scripts are included in the lists of available\nand porcelain commands, about twenty, some of them not even sources of\nporcelains.\n\nPossible solutions to avoid this issue are:\n\n- Strip the current working directory from $PATH temporarily while we run\n  'git help -a' to get all the available commands.  Care must be taken,\n  because '.' can appear at the very beginning, end, or in the middle of\n  $PATH, not to mention that on unixes it's unlikely but possible to have\n  a directory containing e.g. ':.:' in the $PATH.\n\n- Filter out scripts from the output of 'git help -a'.  This can be done\n  by either\n  * listing all possible script extensions, but this list will most likely\n    never be complete, or\n  * filtering out all commands containing a filename extension, i.e.\n    anything with a '.' in it.\n  This will bite users whose custom git commands have filename extensions,\n  i.e. who put 'git-mycmd.sh' in '~/bin'.\n\nSince this is an RFC, it goes with the last option, because that's the\nshortest and simplest.\n\nSigned-off-by: SZEDER Gábor <szeder@ira.uka.de>\n---\n contrib/completion/git-completion.bash | 1 +\n 1 file changed, 1 insertion(+)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex c21190d..9173c41 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -637,6 +637,7 @@ __git_list_all_commands ()\n \tdo\n \t\tcase $i in\n \t\t*--*)             : helper pattern;;\n+\t\t*.*)              : script sources;;\n \t\t*) echo $i;;\n \t\tesac\n \tdone\n-- \n1.9.5.msysgit.0\n"},{"id":"258036","messageId":"xmqqbnjokh9b.fsf@gitster.dls.corp.google.com","threadId":"38816","inReplyTo":"1426452348-6304-1-git-send-email-szeder@ira.uka.de","subject":"Re: [PATCH/RFC] completion: filter sources of git scripts from available commands","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-03-19T17:51:28Z","receivedAt":"2015-03-19T17:51:28Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"SZEDER Gábor <szeder@ira.uka.de> writes:\n\n> Possible solutions to avoid this issue are:\n>\n> - Strip the current working directory from $PATH temporarily while we run\n>   'git help -a' to get all the available commands.  Care must be taken,\n>   because '.' can appear at the very beginning, end, or in the middle of\n>   $PATH, not to mention that on unixes it's unlikely but possible to have\n>   a directory containing e.g. ':.:' in the $PATH.\n>\n> - Filter out scripts from the output of 'git help -a'.  This can be done\n>   by either\n>   * listing all possible script extensions, but this list will most likely\n>     never be complete, or\n>   * filtering out all commands containing a filename extension, i.e.\n>     anything with a '.' in it.\n>   This will bite users whose custom git commands have filename extensions,\n>   i.e. who put 'git-mycmd.sh' in '~/bin'.\n>\n> Since this is an RFC, it goes with the last option, because that's the\n> shortest and simplest.\n\nWould it be another option to re-evaluate the list upon chdir (we\ncan trap an attempt to \"cd\", can't we?) _and_ if $PATH might contain\n\".\".  It is OK if the latter criterion is not precise as long as it\ndoes not say \"$PATH does not have '.' in it\" when it does.\n\n>\n> Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>\n> ---\n>  contrib/completion/git-completion.bash | 1 +\n>  1 file changed, 1 insertion(+)\n>\n> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n> index c21190d..9173c41 100644\n> --- a/contrib/completion/git-completion.bash\n> +++ b/contrib/completion/git-completion.bash\n> @@ -637,6 +637,7 @@ __git_list_all_commands ()\n>  \tdo\n>  \t\tcase $i in\n>  \t\t*--*)             : helper pattern;;\n> +\t\t*.*)              : script sources;;\n>  \t\t*) echo $i;;\n>  \t\tesac\n>  \tdone\n"}]}