{"thread":{"id":"33629","subject":"[PATCH 00/11] completion: general cleanups","startedAt":"2013-04-27T10:19:43Z","lastAt":"2013-04-27T20:13:15Z","messageCount":19,"participants":["Felipe Contreras","Manlio Perillo"],"isPatch":true,"patchVersion":1,"patchTotal":11},"messages":[{"id":"215682","messageId":"1367057994-19887-1-git-send-email-felipe.contreras@gmail.com","threadId":"33629","inReplyTo":null,"subject":"[PATCH 00/11] completion: general cleanups","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-04-27T10:19:43Z","receivedAt":"2013-04-27T10:19:43Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Hi,\n\nBasically while trying to understand the code for path completion, I found that\na lot of code was duplicated, and for not much gain.\n\nI also noticed that doing 'git add file' doesn't add the trailing space as\nbefore. It's not clear if it should be possible to do that with -o filenames,\nbut after all, what do -o filenames gives us? Nothing we can't do ourselves,\napparently.\n\nHowever, in zsh the -f option does give us lots of niceties, so there's a patch\nto allow that in a zsh way.\n\nAlso, add the missing tests.\n\nCheers.\n\nFelipe Contreras (11):\n  completion: add file completion tests\n  completion: document tilde expansion failure in tests\n  completion; remove unuseful comments\n  completion: use __gitcompadd for __gitcomp_file\n  completion: refactor diff_index wrappers\n  completion: refactor __git_complete_index_file()\n  completion: avoid compopt -o filenames\n  completion: get rid of __gitcomp_file()\n  completion: add space after completed filename\n  completion: remove __git_index_file_list_filter()\n  completion: zsh: add proper file support\n\n contrib/completion/git-completion.bash | 168 +++++----------------------------\n contrib/completion/git-completion.zsh  |  41 +++++++-\n t/t9902-completion.sh                  |  77 +++++++++++++++\n 3 files changed, 140 insertions(+), 146 deletions(-)\n\n-- \n1.8.2.1.1031.g2ee5873\n"},{"id":"215683","messageId":"1367057994-19887-2-git-send-email-felipe.contreras@gmail.com","threadId":"33629","inReplyTo":"1367057994-19887-1-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH 01/11] completion: add file completion tests","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-04-27T10:19:44Z","receivedAt":"2013-04-27T10:19:44Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"The commit fea16b4 (git-completion.bash: add support for path\ncompletion) introduced quite a few changes, without the usual tests.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n t/t9902-completion.sh | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 68 insertions(+)\n\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 6d9d141..385e1e4 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -347,4 +347,72 @@ test_expect_success 'send-email' '\n \ttest_completion \"git send-email ma\" \"master \"\n '\n \n+test_expect_success 'complete files' '\n+\tgit init tmp && cd tmp &&\n+\ttest_when_finished \"cd .. && rm -rf tmp\" &&\n+\n+\techo \"expected\" > .gitignore &&\n+\techo \"out\" >> .gitignore &&\n+\n+\tgit add .gitignore &&\n+\ttest_completion \"git commit \" \".gitignore\" &&\n+\n+\tgit commit -m ignore &&\n+\n+\ttouch new &&\n+\ttest_completion \"git add \" \"new\" &&\n+\n+\tgit add new &&\n+\tgit commit -a -m new &&\n+\ttest_completion \"git add \" \"\" &&\n+\n+\tgit mv new modified &&\n+\techo modify > modified &&\n+\ttest_completion \"git add \" \"modified\" &&\n+\n+\ttouch untracked &&\n+\n+\t: TODO .gitignore should not be here &&\n+\ttest_completion \"git rm \" <<-\\EOF &&\n+\t.gitignore\n+\tmodified\n+\tEOF\n+\n+\ttest_completion \"git clean \" \"untracked\" &&\n+\n+\t: TODO .gitignore should not be here &&\n+\ttest_completion \"git mv \" <<-\\EOF &&\n+\t.gitignore\n+\tmodified\n+\tEOF\n+\n+\tmkdir dir &&\n+\ttouch dir/file-in-dir &&\n+\tgit add dir/file-in-dir &&\n+\tgit commit -m dir &&\n+\n+\tmkdir untracked-dir &&\n+\n+\t: TODO .gitignore should not be here &&\n+\ttest_completion \"git mv modified \" <<-\\EOF &&\n+\t.gitignore\n+\tdir\n+\tmodified\n+\tuntracked\n+\tuntracked-dir\n+\tEOF\n+\n+\ttest_completion \"git commit \" \"modified\" &&\n+\n+\t: TODO .gitignore should not be here &&\n+\ttest_completion \"git ls-files \" <<-\\EOF\n+\t.gitignore\n+\tdir\n+\tmodified\n+\tEOF\n+\n+\ttouch momified &&\n+\ttest_completion \"git add mom\" \"momified\"\n+'\n+\n test_done\n-- \n1.8.2.1.1031.g2ee5873\n"},{"id":"215690","messageId":"1367057994-19887-3-git-send-email-felipe.contreras@gmail.com","threadId":"33629","inReplyTo":"1367057994-19887-1-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH 02/11] completion: document tilde expansion failure in tests","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-04-27T10:19:45Z","receivedAt":"2013-04-27T10:19:45Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n t/t9902-completion.sh | 9 +++++++++\n 1 file changed, 9 insertions(+)\n\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 385e1e4..81a1657 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -415,4 +415,13 @@ test_expect_success 'complete files' '\n \ttest_completion \"git add mom\" \"momified\"\n '\n \n+test_expect_failure 'complete with tilde expansion' '\n+\tgit init tmp && cd tmp &&\n+\ttest_when_finished \"cd .. && rm -rf tmp\" &&\n+\n+\ttouch ~/tmp/file &&\n+\n+\ttest_completion \"git add ~/tmp/\" \"~/tmp/file\"\n+'\n+\n test_done\n-- \n1.8.2.1.1031.g2ee5873\n"},{"id":"215686","messageId":"1367057994-19887-4-git-send-email-felipe.contreras@gmail.com","threadId":"33629","inReplyTo":"1367057994-19887-1-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH 03/11] completion; remove unuseful comments","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-04-27T10:19:46Z","receivedAt":"2013-04-27T10:19:46Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"The only caller, __git_complete_index_file() doesn't specify any limits\nto the options for 'git ls-files', neither should this function.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 2 --\n 1 file changed, 2 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex bc3fc9e..f7b0f3c 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -323,8 +323,6 @@ __git_diff_index_helper ()\n \n # __git_index_files accepts 1 or 2 arguments:\n # 1: Options to pass to ls-files (required).\n-#    Supported options are --cached, --modified, --deleted, --others,\n-#    and --directory.\n # 2: A directory path (optional).\n #    If provided, only files within the specified directory are listed.\n #    Sub directories are never recursed.  Path must have a trailing\n-- \n1.8.2.1.1031.g2ee5873\n"},{"id":"215687","messageId":"1367057994-19887-5-git-send-email-felipe.contreras@gmail.com","threadId":"33629","inReplyTo":"1367057994-19887-1-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH 04/11] completion: use __gitcompadd for __gitcomp_file","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-04-27T10:19:47Z","receivedAt":"2013-04-27T10:19:47Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Like the rest of the script does; let's not access COMPREPLY directly.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex f7b0f3c..7f1ebe4 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -252,7 +252,7 @@ __gitcomp_file ()\n \t# since tilde expansion is not applied.\n \t# This means that COMPREPLY will be empty and Bash default\n \t# completion will be used.\n-\tCOMPREPLY=($(compgen -P \"${2-}\" -W \"$1\" -- \"${3-$cur}\"))\n+\t__gitcompadd \"$1\" \"${2-}\" \"${3-$cur}\" \"\"\n \n \t# Tell Bash that compspec generates filenames.\n \tcompopt -o filenames 2>/dev/null\n-- \n1.8.2.1.1031.g2ee5873\n"},{"id":"215691","messageId":"1367057994-19887-6-git-send-email-felipe.contreras@gmail.com","threadId":"33629","inReplyTo":"1367057994-19887-1-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH 05/11] completion: refactor diff_index wrappers","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-04-27T10:19:48Z","receivedAt":"2013-04-27T10:19:48Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"At the end of the day what we really need is to find out the files that\nhave been staged, or modified, because those files are the ones that\nmake sense to pass as arguments to 'git commit'.\n\nWe need diff-index to find those out, since 'git ls-files' doesn't do\nthat.\n\nBut we don't need wrappers and wrappers basically identical to the ones\nused for 'git ls-files', when we can pretend it receives a --committable\noption that would return what we need.\n\nThat way, we can remove a bunch of code without any functional changes.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 71 ++++++++--------------------------\n 1 file changed, 16 insertions(+), 55 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 7f1ebe4..2561265 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -297,30 +297,25 @@ __git_index_file_list_filter ()\n \t__git_index_file_list_filter_bash\n }\n \n-# Execute git ls-files, returning paths relative to the directory\n-# specified in the first argument, and using the options specified in\n-# the second argument.\n+# Execute 'git ls-files', unless the --committable option is specified, in\n+# which case it runs 'git diff-index' to find out the files that can be\n+# committed.  It return paths relative to the directory specified in the first\n+# argument, and using the options specified in the second argument.\n __git_ls_files_helper ()\n {\n \t(\n \t\ttest -n \"${CDPATH+set}\" && unset CDPATH\n-\t\t# NOTE: $2 is not quoted in order to support multiple options\n-\t\tcd \"$1\" && git ls-files --exclude-standard $2\n+\t\tcd \"$1\"\n+\t\tif [ \"$2\" == \"--committable\" ]; then\n+\t\t\tgit diff-index --name-only --relative HEAD\n+\t\telse\n+\t\t\t# NOTE: $2 is not quoted in order to support multiple options\n+\t\t\tgit ls-files --exclude-standard $2\n+\t\tfi\n \t) 2>/dev/null\n }\n \n \n-# Execute git diff-index, returning paths relative to the directory\n-# specified in the first argument, and using the tree object id\n-# specified in the second argument.\n-__git_diff_index_helper ()\n-{\n-\t(\n-\t\ttest -n \"${CDPATH+set}\" && unset CDPATH\n-\t\tcd \"$1\" && git diff-index --name-only --relative \"$2\"\n-\t) 2>/dev/null\n-}\n-\n # __git_index_files accepts 1 or 2 arguments:\n # 1: Options to pass to ls-files (required).\n # 2: A directory path (optional).\n@@ -337,22 +332,6 @@ __git_index_files ()\n \tfi\n }\n \n-# __git_diff_index_files accepts 1 or 2 arguments:\n-# 1) The id of a tree object.\n-# 2) A directory path (optional).\n-#    If provided, only files within the specified directory are listed.\n-#    Sub directories are never recursed.  Path must have a trailing\n-#    slash.\n-__git_diff_index_files ()\n-{\n-\tlocal dir=\"$(__gitdir)\" root=\"${2-.}\"\n-\n-\tif [ -d \"$dir\" ]; then\n-\t\t__git_diff_index_helper \"$root\" \"$1\" | __git_index_file_list_filter |\n-\t\t\tsort | uniq\n-\tfi\n-}\n-\n __git_heads ()\n {\n \tlocal dir=\"$(__gitdir)\"\n@@ -550,8 +529,10 @@ __git_complete_revlist_file ()\n }\n \n \n-# __git_complete_index_file requires 1 argument: the options to pass to\n-# ls-file\n+# __git_complete_index_file requires 1 argument:\n+# 1: the options to pass to ls-file\n+#\n+# The exception is --committable, which finds the files appropriate commit.\n __git_complete_index_file ()\n {\n \tlocal pfx cur_=\"$cur\"\n@@ -570,26 +551,6 @@ __git_complete_index_file ()\n \tesac\n }\n \n-# __git_complete_diff_index_file requires 1 argument: the id of a tree\n-# object\n-__git_complete_diff_index_file ()\n-{\n-\tlocal pfx cur_=\"$cur\"\n-\n-\tcase \"$cur_\" in\n-\t?*/*)\n-\t\tpfx=\"${cur_%/*}\"\n-\t\tcur_=\"${cur_##*/}\"\n-\t\tpfx=\"${pfx}/\"\n-\n-\t\t__gitcomp_file \"$(__git_diff_index_files \"$1\" \"$pfx\")\" \"$pfx\" \"$cur_\"\n-\t\t;;\n-\t*)\n-\t\t__gitcomp_file \"$(__git_diff_index_files \"$1\")\" \"\" \"$cur_\"\n-\t\t;;\n-\tesac\n-}\n-\n __git_complete_file ()\n {\n \t__git_complete_revlist_file\n@@ -1211,7 +1172,7 @@ _git_commit ()\n \tesac\n \n \tif git rev-parse --verify --quiet HEAD >/dev/null; then\n-\t\t__git_complete_diff_index_file \"HEAD\"\n+\t\t__git_complete_index_file \"--committable\"\n \telse\n \t\t# This is the first commit\n \t\t__git_complete_index_file \"--cached\"\n-- \n1.8.2.1.1031.g2ee5873\n"},{"id":"215688","messageId":"1367057994-19887-7-git-send-email-felipe.contreras@gmail.com","threadId":"33629","inReplyTo":"1367057994-19887-1-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH 06/11] completion: refactor __git_complete_index_file()","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-04-27T10:19:49Z","receivedAt":"2013-04-27T10:19:49Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"The calls to __gitcomp_file() are essentially the same, but with\ndifferent prefix.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 9 +++------\n 1 file changed, 3 insertions(+), 6 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 2561265..9cea170 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -535,20 +535,17 @@ __git_complete_revlist_file ()\n # The exception is --committable, which finds the files appropriate commit.\n __git_complete_index_file ()\n {\n-\tlocal pfx cur_=\"$cur\"\n+\tlocal pfx=\"\" cur_=\"$cur\"\n \n \tcase \"$cur_\" in\n \t?*/*)\n \t\tpfx=\"${cur_%/*}\"\n \t\tcur_=\"${cur_##*/}\"\n \t\tpfx=\"${pfx}/\"\n-\n-\t\t__gitcomp_file \"$(__git_index_files \"$1\" \"$pfx\")\" \"$pfx\" \"$cur_\"\n-\t\t;;\n-\t*)\n-\t\t__gitcomp_file \"$(__git_index_files \"$1\")\" \"\" \"$cur_\"\n \t\t;;\n \tesac\n+\n+\t__gitcomp_file \"$(__git_index_files \"$1\" \"$pfx\")\" \"$pfx\" \"$cur_\"\n }\n \n __git_complete_file ()\n-- \n1.8.2.1.1031.g2ee5873\n"},{"id":"215684","messageId":"1367057994-19887-8-git-send-email-felipe.contreras@gmail.com","threadId":"33629","inReplyTo":"1367057994-19887-1-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH 07/11] completion: avoid compopt -o filenames","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-04-27T10:19:50Z","receivedAt":"2013-04-27T10:19:50Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"If this option causes so much trouble, lets just not use it.\n\nThe supposed advantages of specifying the 'filenames' is that 1) a slash\nis added at the end, 2) trailing spaces are removed (which doesn't seem\nto be true), and 3) special characters are quoted. We can do all those\nthings by ourselves.\n\nAlso, this will allow us to add a space after the completion, just like\nit happened before fea16b4 (git-completion.bash: add support for path\ncompletion), and just like the rest of the script does.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 43 ++++------------------------------\n t/t9902-completion.sh                  |  6 ++---\n 2 files changed, 7 insertions(+), 42 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 9cea170..5dd6646 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -253,12 +253,12 @@ __gitcomp_file ()\n \t# This means that COMPREPLY will be empty and Bash default\n \t# completion will be used.\n \t__gitcompadd \"$1\" \"${2-}\" \"${3-$cur}\" \"\"\n-\n-\t# Tell Bash that compspec generates filenames.\n-\tcompopt -o filenames 2>/dev/null\n }\n \n-__git_index_file_list_filter_compat ()\n+# Process path list returned by \"ls-files\" and \"diff-index --name-only\"\n+# commands, in order to list only file names relative to a specified\n+# directory, and append a slash to directory names.\n+__git_index_file_list_filter ()\n {\n \tlocal path\n \n@@ -270,33 +270,6 @@ __git_index_file_list_filter_compat ()\n \tdone\n }\n \n-__git_index_file_list_filter_bash ()\n-{\n-\tlocal path\n-\n-\twhile read -r path; do\n-\t\tcase \"$path\" in\n-\t\t?*/*)\n-\t\t\t# XXX if we append a slash to directory names when using\n-\t\t\t# `compopt -o filenames`, Bash will append another slash.\n-\t\t\t# This is pretty stupid, and this the reason why we have to\n-\t\t\t# define a compatible version for this function.\n-\t\t\techo \"${path%%/*}\" ;;\n-\t\t*)\n-\t\t\techo \"$path\" ;;\n-\t\tesac\n-\tdone\n-}\n-\n-# Process path list returned by \"ls-files\" and \"diff-index --name-only\"\n-# commands, in order to list only file names relative to a specified\n-# directory, and append a slash to directory names.\n-__git_index_file_list_filter ()\n-{\n-\t# Default to Bash >= 4.x\n-\t__git_index_file_list_filter_bash\n-}\n-\n # Execute 'git ls-files', unless the --committable option is specified, in\n # which case it runs 'git diff-index' to find out the files that can be\n # committed.  It return paths relative to the directory specified in the first\n@@ -2651,14 +2624,6 @@ if [[ -n ${ZSH_VERSION-} ]]; then\n \n \tcompdef _git git gitk\n \treturn\n-elif [[ -n ${BASH_VERSION-} ]]; then\n-\tif ((${BASH_VERSINFO[0]} < 4)); then\n-\t\t# compopt is not supported\n-\t\t__git_index_file_list_filter ()\n-\t\t{\n-\t\t\t__git_index_file_list_filter_compat\n-\t\t}\n-\tfi\n fi\n \n __git_func_wrap ()\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 81a1657..e6cdb05 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -396,10 +396,10 @@ test_expect_success 'complete files' '\n \t: TODO .gitignore should not be here &&\n \ttest_completion \"git mv modified \" <<-\\EOF &&\n \t.gitignore\n-\tdir\n+\tdir/\n \tmodified\n \tuntracked\n-\tuntracked-dir\n+\tuntracked-dir/\n \tEOF\n \n \ttest_completion \"git commit \" \"modified\" &&\n@@ -407,7 +407,7 @@ test_expect_success 'complete files' '\n \t: TODO .gitignore should not be here &&\n \ttest_completion \"git ls-files \" <<-\\EOF\n \t.gitignore\n-\tdir\n+\tdir/\n \tmodified\n \tEOF\n \n-- \n1.8.2.1.1031.g2ee5873\n"},{"id":"215689","messageId":"1367057994-19887-9-git-send-email-felipe.contreras@gmail.com","threadId":"33629","inReplyTo":"1367057994-19887-1-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH 08/11] completion: get rid of __gitcomp_file()","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-04-27T10:19:51Z","receivedAt":"2013-04-27T10:19:51Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Now that we don't use -o filenames, it's no different from\n__gitcomp_nl().\n\nThe only reason we might want it is for other shells, like zsh, which\ncan do more useful things if they know it's a file, like colouring the\noutput. But that can be done in the zsh completion.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 29 +----------------------------\n contrib/completion/git-completion.zsh  |  9 ---------\n 2 files changed, 1 insertion(+), 37 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 5dd6646..a9b6a48 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -237,24 +237,6 @@ __gitcomp_nl ()\n \t__gitcompadd \"$1\" \"${2-}\" \"${3-$cur}\" \"${4- }\"\n }\n \n-# Generates completion reply with compgen from newline-separated possible\n-# completion filenames.\n-# It accepts 1 to 3 arguments:\n-# 1: List of possible completion filenames, separated by a single newline.\n-# 2: A directory prefix to be added to each possible completion filename\n-#    (optional).\n-# 3: Generate possible completion matches for this word (optional).\n-__gitcomp_file ()\n-{\n-\tlocal IFS=$'\\n'\n-\n-\t# XXX does not work when the directory prefix contains a tilde,\n-\t# since tilde expansion is not applied.\n-\t# This means that COMPREPLY will be empty and Bash default\n-\t# completion will be used.\n-\t__gitcompadd \"$1\" \"${2-}\" \"${3-$cur}\" \"\"\n-}\n-\n # Process path list returned by \"ls-files\" and \"diff-index --name-only\"\n # commands, in order to list only file names relative to a specified\n # directory, and append a slash to directory names.\n@@ -518,7 +500,7 @@ __git_complete_index_file ()\n \t\t;;\n \tesac\n \n-\t__gitcomp_file \"$(__git_index_files \"$1\" \"$pfx\")\" \"$pfx\" \"$cur_\"\n+\t__gitcomp_nl \"$(__git_index_files \"$1\" \"$pfx\")\" \"$pfx\" \"$cur_\" \"\"\n }\n \n __git_complete_file ()\n@@ -2594,15 +2576,6 @@ if [[ -n ${ZSH_VERSION-} ]]; then\n \t\tcompadd -Q -S \"${4- }\" -p \"${2-}\" -- ${=1} && _ret=0\n \t}\n \n-\t__gitcomp_file ()\n-\t{\n-\t\temulate -L zsh\n-\n-\t\tlocal IFS=$'\\n'\n-\t\tcompset -P '*[=:]'\n-\t\tcompadd -Q -p \"${2-}\" -f -- ${=1} && _ret=0\n-\t}\n-\n \t__git_zsh_helper ()\n \t{\n \t\temulate -L ksh\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex cf8116d..4577502 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -60,15 +60,6 @@ __gitcomp_nl ()\n \tcompadd -Q -S \"${4- }\" -p \"${2-}\" -- ${=1} && _ret=0\n }\n \n-__gitcomp_file ()\n-{\n-\temulate -L zsh\n-\n-\tlocal IFS=$'\\n'\n-\tcompset -P '*[=:]'\n-\tcompadd -Q -p \"${2-}\" -f -- ${=1} && _ret=0\n-}\n-\n _git ()\n {\n \tlocal _ret=1\n-- \n1.8.2.1.1031.g2ee5873\n"},{"id":"215685","messageId":"1367057994-19887-10-git-send-email-felipe.contreras@gmail.com","threadId":"33629","inReplyTo":"1367057994-19887-1-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH 09/11] completion: add space after completed filename","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-04-27T10:19:52Z","receivedAt":"2013-04-27T10:19:52Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Just like before fea16b4 (git-completion.bash: add support for path\ncompletion).\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash |  2 +-\n t/t9902-completion.sh                  | 28 ++++++++++++++--------------\n 2 files changed, 15 insertions(+), 15 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex a9b6a48..60a6a0b 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -247,7 +247,7 @@ __git_index_file_list_filter ()\n \twhile read -r path; do\n \t\tcase \"$path\" in\n \t\t?*/*) echo \"${path%%/*}/\" ;;\n-\t\t*) echo \"$path\" ;;\n+\t\t*) echo \"$path \" ;;\n \t\tesac\n \tdone\n }\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex e6cdb05..8968ef6 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -355,12 +355,12 @@ test_expect_success 'complete files' '\n \techo \"out\" >> .gitignore &&\n \n \tgit add .gitignore &&\n-\ttest_completion \"git commit \" \".gitignore\" &&\n+\ttest_completion \"git commit \" \".gitignore \" &&\n \n \tgit commit -m ignore &&\n \n \ttouch new &&\n-\ttest_completion \"git add \" \"new\" &&\n+\ttest_completion \"git add \" \"new \" &&\n \n \tgit add new &&\n \tgit commit -a -m new &&\n@@ -368,22 +368,22 @@ test_expect_success 'complete files' '\n \n \tgit mv new modified &&\n \techo modify > modified &&\n-\ttest_completion \"git add \" \"modified\" &&\n+\ttest_completion \"git add \" \"modified \" &&\n \n \ttouch untracked &&\n \n \t: TODO .gitignore should not be here &&\n \ttest_completion \"git rm \" <<-\\EOF &&\n-\t.gitignore\n-\tmodified\n+\t.gitignore Z\n+\tmodified Z\n \tEOF\n \n-\ttest_completion \"git clean \" \"untracked\" &&\n+\ttest_completion \"git clean \" \"untracked \" &&\n \n \t: TODO .gitignore should not be here &&\n \ttest_completion \"git mv \" <<-\\EOF &&\n-\t.gitignore\n-\tmodified\n+\t.gitignore Z\n+\tmodified Z\n \tEOF\n \n \tmkdir dir &&\n@@ -395,20 +395,20 @@ test_expect_success 'complete files' '\n \n \t: TODO .gitignore should not be here &&\n \ttest_completion \"git mv modified \" <<-\\EOF &&\n-\t.gitignore\n+\t.gitignore Z\n \tdir/\n-\tmodified\n-\tuntracked\n+\tmodified Z\n+\tuntracked Z\n \tuntracked-dir/\n \tEOF\n \n-\ttest_completion \"git commit \" \"modified\" &&\n+\ttest_completion \"git commit \" \"modified \" &&\n \n \t: TODO .gitignore should not be here &&\n \ttest_completion \"git ls-files \" <<-\\EOF\n-\t.gitignore\n+\t.gitignore Z\n \tdir/\n-\tmodified\n+\tmodified Z\n \tEOF\n \n \ttouch momified &&\n-- \n1.8.2.1.1031.g2ee5873\n"},{"id":"215692","messageId":"1367057994-19887-11-git-send-email-felipe.contreras@gmail.com","threadId":"33629","inReplyTo":"1367057994-19887-1-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH 10/11] completion: remove __git_index_file_list_filter()","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-04-27T10:19:53Z","receivedAt":"2013-04-27T10:19:53Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Refactor the code into the only caller; __git_index_files().\n\nAlso, Somehow messing up with the 'path' variable messes up the 'PATH'\nvariable. So let's not do that.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 26 ++++++++------------------\n 1 file changed, 8 insertions(+), 18 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 60a6a0b..8100085 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -237,21 +237,6 @@ __gitcomp_nl ()\n \t__gitcompadd \"$1\" \"${2-}\" \"${3-$cur}\" \"${4- }\"\n }\n \n-# Process path list returned by \"ls-files\" and \"diff-index --name-only\"\n-# commands, in order to list only file names relative to a specified\n-# directory, and append a slash to directory names.\n-__git_index_file_list_filter ()\n-{\n-\tlocal path\n-\n-\twhile read -r path; do\n-\t\tcase \"$path\" in\n-\t\t?*/*) echo \"${path%%/*}/\" ;;\n-\t\t*) echo \"$path \" ;;\n-\t\tesac\n-\tdone\n-}\n-\n # Execute 'git ls-files', unless the --committable option is specified, in\n # which case it runs 'git diff-index' to find out the files that can be\n # committed.  It return paths relative to the directory specified in the first\n@@ -279,11 +264,16 @@ __git_ls_files_helper ()\n #    slash.\n __git_index_files ()\n {\n-\tlocal dir=\"$(__gitdir)\" root=\"${2-.}\"\n+\tlocal dir=\"$(__gitdir)\" root=\"${2-.}\" file\n \n \tif [ -d \"$dir\" ]; then\n-\t\t__git_ls_files_helper \"$root\" \"$1\" | __git_index_file_list_filter |\n-\t\t\tsort | uniq\n+\t\t__git_ls_files_helper \"$root\" \"$1\" |\n+\t\twhile read -r file; do\n+\t\t\tcase \"$file\" in\n+\t\t\t?*/*) echo \"${file%%/*}/\" ;;\n+\t\t\t*) echo \"$file \" ;;\n+\t\t\tesac\n+\t\tdone | sort | uniq\n \tfi\n }\n \n-- \n1.8.2.1.1031.g2ee5873\n"},{"id":"215693","messageId":"1367057994-19887-12-git-send-email-felipe.contreras@gmail.com","threadId":"33629","inReplyTo":"1367057994-19887-1-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH 11/11] completion: zsh: add proper file support","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-04-27T10:19:54Z","receivedAt":"2013-04-27T10:19:54Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"So the files are completed and coloured nicely.\n\nThe code would be only a couple of lines if only _multi_parts or\n_path_files worked correctly, but alas, they don't.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.zsh | 42 +++++++++++++++++++++++++++++++++++\n 1 file changed, 42 insertions(+)\n\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex 4577502..8c6916a 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -60,6 +60,48 @@ __gitcomp_nl ()\n \tcompadd -Q -S \"${4- }\" -p \"${2-}\" -- ${=1} && _ret=0\n }\n \n+#\n+# We need to remove the extra slash for directories, and we need to remove the\n+# spaces for files, otherwise zsh can't stat them and threat them as proper files.\n+#\n+__git_index_files ()\n+{\n+\tlocal dir=\"$(__gitdir)\" root=\"${2-.}\" file\n+\n+\tif [ -d \"$dir\" ]; then\n+\t\tlocal -a files\n+\t\temulate ksh -c '__git_ls_files_helper \"$root\" \"$1\"' |\n+\t\twhile read -r file; do\n+\t\t\tcase \"$file\" in\n+\t\t\t?*/*)\n+\t\t\t\tfiles+=\"${file%%/*}\"\n+\t\t\t\t;;\n+\t\t\t*)\n+\t\t\t\tfiles+=\"$file\"\n+\t\t\t\t;;\n+\t\t\tesac\n+\t\tdone\n+\t\tcompadd -Q -p \"${2-}\" -f -a files && _ret=0\n+\tfi\n+}\n+\n+__git_complete_index_file ()\n+{\n+\temulate -L zsh\n+\n+\tlocal pfx=\"\" cur_=\"$cur\"\n+\n+\tcase \"$cur_\" in\n+\t?*/*)\n+\t\tpfx=\"${cur_%/*}\"\n+\t\tcur_=\"${cur_##*/}\"\n+\t\tpfx=\"${pfx}/\"\n+\t\t;;\n+\tesac\n+\n+\t__git_index_files \"$1\" \"$pfx\"\n+}\n+\n _git ()\n {\n \tlocal _ret=1\n-- \n1.8.2.1.1031.g2ee5873\n"},{"id":"215695","messageId":"517BB798.4070703@gmail.com","threadId":"33629","inReplyTo":"1367057994-19887-1-git-send-email-felipe.contreras@gmail.com","subject":"Re: [PATCH 00/11] completion: general cleanups","fromName":"Manlio Perillo","fromEmail":"manlio.perillo@gmail.com","sentAt":"2013-04-27T11:33:44Z","receivedAt":"2013-04-27T11:33:44Z","isPatch":true,"sender":{"key":"manlio.perillo@gmail.com","avatar":"https://avatars.githubusercontent.com/u/6217088?v=4"},"body":"-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA1\n\nIl 27/04/2013 12:19, Felipe Contreras ha scritto:\n> Hi,\n> \n> Basically while trying to understand the code for path completion, I found that\n> a lot of code was duplicated, and for not much gain.\n> \n> I also noticed that doing 'git add file' doesn't add the trailing space as\n> before. It's not clear if it should be possible to do that with -o filenames,\n> but after all, what do -o filenames gives us? Nothing we can't do ourselves,\n> apparently.\n> \n\nNo, you can not do it yourself, as far as I know.\n\nI added the `compopt -o filenames` on Junio request for something like\n\"It  would be nice if completion for real files would behave like\nbuiltin bash completion\", if I remember correctly.\n\nTry `git rm contrib/completion/<TAB>`, in the git reporitory.\n\nUsing the new feature, bash will suggest:\n\"git-completion.bash  git-completion.tcsh  git-completion.zsh\ngit-prompt.sh\"\n\nOld behaviour, instead, was to suggest:\n\"contrib/completion/git-completion.bash\ncontrib/completion/git-completion.zsh\ncontrib/completion/git-completion.tcsh  contrib/completion/git-prompt.sh\"\n\nI tried several things, but I was unable to emulate Bash builtin file\ncompletion, whithout having to use `compopt -o filenames`.\n\n\n\nAs far as the \"double slash\" problem with the\n__git_index_file_list_filter_bash function, please try\n`git rm contrib<TAB>`.\n\nWith current code, Bash will suggest:\n\"blameview/ diffall/ git-shell-commands/\"\n\nIf you remove the __git_index_file_list_filter_bash function and use\n__git_index_file_list_filter_compat instead, Bash will suggest:\n\n\"blameview// diffall// git-shell-commands//\"\n\nI can confirm this on my system, and it was confirmed by another user.\nIt only happens when you use `compopt -o filenames`. I don't know if\nthis is a bug or a feature, but I can try to ask to Bash mailing list,\nso that we can update the comment to make more clear why a separate\nfunction was needed.\n\n\n> [...]\n\n\nRegards  Manlio\n-----BEGIN PGP SIGNATURE-----\nVersion: GnuPG v1.4.10 (GNU/Linux)\nComment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/\n\niEYEARECAAYFAlF7t5gACgkQscQJ24LbaUSO5QCffllxM8RbGUP47kb7uL5J3drF\nhkUAn26ezKptTAC412EJZnxjh7RVcdAO\n=Piyz\n-----END PGP SIGNATURE-----\n"},{"id":"215697","messageId":"CAMP44s1od7W0OufMhn2TCZTAo0aK9D+7VLzwVy7BSGNxAMuk6w@mail.gmail.com","threadId":"33629","inReplyTo":"517BB798.4070703@gmail.com","subject":"Re: [PATCH 00/11] completion: general cleanups","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-04-27T12:36:35Z","receivedAt":"2013-04-27T12:36:35Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Sat, Apr 27, 2013 at 6:33 AM, Manlio Perillo\n<manlio.perillo@gmail.com> wrote:\n> -----BEGIN PGP SIGNED MESSAGE-----\n> Hash: SHA1\n>\n> Il 27/04/2013 12:19, Felipe Contreras ha scritto:\n>> Hi,\n>>\n>> Basically while trying to understand the code for path completion, I found that\n>> a lot of code was duplicated, and for not much gain.\n>>\n>> I also noticed that doing 'git add file' doesn't add the trailing space as\n>> before. It's not clear if it should be possible to do that with -o filenames,\n>> but after all, what do -o filenames gives us? Nothing we can't do ourselves,\n>> apparently.\n>>\n>\n> No, you can not do it yourself, as far as I know.\n>\n> I added the `compopt -o filenames` on Junio request for something like\n> \"It  would be nice if completion for real files would behave like\n> builtin bash completion\", if I remember correctly.\n>\n> Try `git rm contrib/completion/<TAB>`, in the git reporitory.\n>\n> Using the new feature, bash will suggest:\n> \"git-completion.bash  git-completion.tcsh  git-completion.zsh\n> git-prompt.sh\"\n>\n> Old behaviour, instead, was to suggest:\n> \"contrib/completion/git-completion.bash\n> contrib/completion/git-completion.zsh\n> contrib/completion/git-completion.tcsh  contrib/completion/git-prompt.sh\"\n>\n> I tried several things, but I was unable to emulate Bash builtin file\n> completion, whithout having to use `compopt -o filenames`.\n\nI see. I'm not convinced it's such a great feature, but it would be\nnice to have.\n\nAnyway, 'compopt -o filenames +o nospace' should restore the old\nbehavior to add a space after the completion.\n\n> As far as the \"double slash\" problem with the\n> __git_index_file_list_filter_bash function, please try\n> `git rm contrib<TAB>`.\n>\n> With current code, Bash will suggest:\n> \"blameview/ diffall/ git-shell-commands/\"\n>\n> If you remove the __git_index_file_list_filter_bash function and use\n> __git_index_file_list_filter_compat instead, Bash will suggest:\n>\n> \"blameview// diffall// git-shell-commands//\"\n>\n> I can confirm this on my system, and it was confirmed by another user.\n> It only happens when you use `compopt -o filenames`. I don't know if\n> this is a bug or a feature, but I can try to ask to Bash mailing list,\n> so that we can update the comment to make more clear why a separate\n> function was needed.\n\nI've managed to reproduce the issue. The slash doesn't appear in the\ncompletion, it appears on the list of completions.\n\nI'll see what I can think to fix the issues while still keep the code simple.\n\nCheers.\n\n-- \nFelipe Contreras\n"},{"id":"215700","messageId":"CAMP44s3h43S=A7+QEWuv0iefxbXyKZsiJ2QMdc-XiouoO3yYng@mail.gmail.com","threadId":"33629","inReplyTo":"CAMP44s1od7W0OufMhn2TCZTAo0aK9D+7VLzwVy7BSGNxAMuk6w@mail.gmail.com","subject":"Re: [PATCH 00/11] completion: general cleanups","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-04-27T13:07:58Z","receivedAt":"2013-04-27T13:07:58Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Sat, Apr 27, 2013 at 7:36 AM, Felipe Contreras\n<felipe.contreras@gmail.com> wrote:\n> On Sat, Apr 27, 2013 at 6:33 AM, Manlio Perillo\n> <manlio.perillo@gmail.com> wrote:\n>> -----BEGIN PGP SIGNED MESSAGE-----\n>> Hash: SHA1\n>>\n>> Il 27/04/2013 12:19, Felipe Contreras ha scritto:\n>>> Hi,\n>>>\n>>> Basically while trying to understand the code for path completion, I found that\n>>> a lot of code was duplicated, and for not much gain.\n>>>\n>>> I also noticed that doing 'git add file' doesn't add the trailing space as\n>>> before. It's not clear if it should be possible to do that with -o filenames,\n>>> but after all, what do -o filenames gives us? Nothing we can't do ourselves,\n>>> apparently.\n>>>\n>>\n>> No, you can not do it yourself, as far as I know.\n>>\n>> I added the `compopt -o filenames` on Junio request for something like\n>> \"It  would be nice if completion for real files would behave like\n>> builtin bash completion\", if I remember correctly.\n>>\n>> Try `git rm contrib/completion/<TAB>`, in the git reporitory.\n>>\n>> Using the new feature, bash will suggest:\n>> \"git-completion.bash  git-completion.tcsh  git-completion.zsh\n>> git-prompt.sh\"\n>>\n>> Old behaviour, instead, was to suggest:\n>> \"contrib/completion/git-completion.bash\n>> contrib/completion/git-completion.zsh\n>> contrib/completion/git-completion.tcsh  contrib/completion/git-prompt.sh\"\n>>\n>> I tried several things, but I was unable to emulate Bash builtin file\n>> completion, whithout having to use `compopt -o filenames`.\n>\n> I see. I'm not convinced it's such a great feature, but it would be\n> nice to have.\n>\n> Anyway, 'compopt -o filenames +o nospace' should restore the old\n> behavior to add a space after the completion.\n>\n>> As far as the \"double slash\" problem with the\n>> __git_index_file_list_filter_bash function, please try\n>> `git rm contrib<TAB>`.\n>>\n>> With current code, Bash will suggest:\n>> \"blameview/ diffall/ git-shell-commands/\"\n>>\n>> If you remove the __git_index_file_list_filter_bash function and use\n>> __git_index_file_list_filter_compat instead, Bash will suggest:\n>>\n>> \"blameview// diffall// git-shell-commands//\"\n>>\n>> I can confirm this on my system, and it was confirmed by another user.\n>> It only happens when you use `compopt -o filenames`. I don't know if\n>> this is a bug or a feature, but I can try to ask to Bash mailing list,\n>> so that we can update the comment to make more clear why a separate\n>> function was needed.\n>\n> I've managed to reproduce the issue. The slash doesn't appear in the\n> completion, it appears on the list of completions.\n>\n> I'll see what I can think to fix the issues while still keep the code simple.\n\nThis should do the trick. No?\n\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -262,16 +262,17 @@ __git_ls_files_helper ()\n #    If provided, only files within the specified directory are listed.\n #    Sub directories are never recursed.  Path must have a trailing\n #    slash.\n+# 3. Compat mode; set to enable.\n __git_index_files ()\n {\n-       local dir=\"$(__gitdir)\" root=\"${2-.}\" file\n+       local dir=\"$(__gitdir)\" root=\"${2-.}\" file old=\"${3-}\"\n\n        if [ -d \"$dir\" ]; then\n                __git_ls_files_helper \"$root\" \"$1\" |\n                while read -r file; do\n                        case \"$file\" in\n-                       ?*/*) echo \"${file%%/*}/\" ;;\n-                       *) echo \"$file \" ;;\n+                       ?*/*) echo \"${file%%/*}${old:+/}\" ;;\n+                       *) echo \"${file}${old:+ }\" ;;\n                        esac\n                done | sort | uniq\n        fi\n@@ -480,7 +481,7 @@ __git_complete_revlist_file ()\n # The exception is --committable, which finds the files appropriate commit.\n __git_complete_index_file ()\n {\n-       local pfx=\"\" cur_=\"$cur\"\n+       local pfx=\"\" cur_=\"$cur\" old\n\n        case \"$cur_\" in\n        ?*/*)\n@@ -490,7 +491,8 @@ __git_complete_index_file ()\n                ;;\n        esac\n\n-       __gitcomp_nl \"$(__git_index_files \"$1\" \"$pfx\")\" \"$pfx\" \"$cur_\" \"\"\n+       compopt -o filenames +o nospace 2> /dev/null || old=1\n+       __gitcomp_nl \"$(__git_index_files \"$1\" \"$pfx\" \"$old\")\" \"$pfx\" \"$cur_\" \"\"\n }\n\n __git_complete_file ()\n\n-- \nFelipe Contreras\n"},{"id":"215714","messageId":"517BF167.7090300@gmail.com","threadId":"33629","inReplyTo":"CAMP44s3h43S=A7+QEWuv0iefxbXyKZsiJ2QMdc-XiouoO3yYng@mail.gmail.com","subject":"Re: [PATCH 00/11] completion: general cleanups","fromName":"Manlio Perillo","fromEmail":"manlio.perillo@gmail.com","sentAt":"2013-04-27T15:40:23Z","receivedAt":"2013-04-27T15:40:23Z","isPatch":true,"sender":{"key":"manlio.perillo@gmail.com","avatar":"https://avatars.githubusercontent.com/u/6217088?v=4"},"body":"-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA1\n\nIl 27/04/2013 15:07, Felipe Contreras ha scritto:\n> [...]\n> This should do the trick. No?\n> \n> --- a/contrib/completion/git-completion.bash\n> +++ b/contrib/completion/git-completion.bash\n> @@ -262,16 +262,17 @@ __git_ls_files_helper ()\n>  #    If provided, only files within the specified directory are listed.\n>  #    Sub directories are never recursed.  Path must have a trailing\n>  #    slash.\n> +# 3. Compat mode; set to enable.\n>  __git_index_files ()\n>  {\n> -       local dir=\"$(__gitdir)\" root=\"${2-.}\" file\n> +       local dir=\"$(__gitdir)\" root=\"${2-.}\" file old=\"${3-}\"\n> \n>         if [ -d \"$dir\" ]; then\n>                 __git_ls_files_helper \"$root\" \"$1\" |\n>                 while read -r file; do\n>                         case \"$file\" in\n> -                       ?*/*) echo \"${file%%/*}/\" ;;\n> -                       *) echo \"$file \" ;;\n> +                       ?*/*) echo \"${file%%/*}${old:+/}\" ;;\n> +                       *) echo \"${file}${old:+ }\" ;;\n>                         esac\n>                 done | sort | uniq\n>         fi\n> @@ -480,7 +481,7 @@ __git_complete_revlist_file ()\n>  # The exception is --committable, which finds the files appropriate commit.\n>  __git_complete_index_file ()\n>  {\n> -       local pfx=\"\" cur_=\"$cur\"\n> +       local pfx=\"\" cur_=\"$cur\" old\n> \n>         case \"$cur_\" in\n>         ?*/*)\n> @@ -490,7 +491,8 @@ __git_complete_index_file ()\n>                 ;;\n>         esac\n> \n> -       __gitcomp_nl \"$(__git_index_files \"$1\" \"$pfx\")\" \"$pfx\" \"$cur_\" \"\"\n> +       compopt -o filenames +o nospace 2> /dev/null || old=1\n> +       __gitcomp_nl \"$(__git_index_files \"$1\" \"$pfx\" \"$old\")\" \"$pfx\" \"$cur_\" \"\"\n>  }\n> \n>  __git_complete_file ()\n> \n\nI like the idea (but I have not tested it), however compopt is called\ntwo times, for each completion.\n\nMaybe we can test for `-o filenames` support when script is loaded,\nwhere currently there is a Bash version check, and set a global variable?\n\n\n\nRegards   Manlio\n-----BEGIN PGP SIGNATURE-----\nVersion: GnuPG v1.4.10 (GNU/Linux)\nComment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/\n\niEYEARECAAYFAlF78WcACgkQscQJ24LbaUSjzgCfWq26RMqFLgGU9B8C0mb+Wogu\nA5IAnjKpupGbdOZAKtYZkglYKSmbqtqK\n=iTzW\n-----END PGP SIGNATURE-----\n"},{"id":"215718","messageId":"CAMP44s32WrnFr9Lp03Wu8gC6=FaACBtDbi1rnu=bo94Aa73TBA@mail.gmail.com","threadId":"33629","inReplyTo":"517BF167.7090300@gmail.com","subject":"Re: [PATCH 00/11] completion: general cleanups","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-04-27T19:15:43Z","receivedAt":"2013-04-27T19:15:43Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Sat, Apr 27, 2013 at 10:40 AM, Manlio Perillo\n<manlio.perillo@gmail.com> wrote:\n> -----BEGIN PGP SIGNED MESSAGE-----\n> Hash: SHA1\n>\n> Il 27/04/2013 15:07, Felipe Contreras ha scritto:\n>> [...]\n>> This should do the trick. No?\n>>\n>> --- a/contrib/completion/git-completion.bash\n>> +++ b/contrib/completion/git-completion.bash\n>> @@ -262,16 +262,17 @@ __git_ls_files_helper ()\n>>  #    If provided, only files within the specified directory are listed.\n>>  #    Sub directories are never recursed.  Path must have a trailing\n>>  #    slash.\n>> +# 3. Compat mode; set to enable.\n>>  __git_index_files ()\n>>  {\n>> -       local dir=\"$(__gitdir)\" root=\"${2-.}\" file\n>> +       local dir=\"$(__gitdir)\" root=\"${2-.}\" file old=\"${3-}\"\n>>\n>>         if [ -d \"$dir\" ]; then\n>>                 __git_ls_files_helper \"$root\" \"$1\" |\n>>                 while read -r file; do\n>>                         case \"$file\" in\n>> -                       ?*/*) echo \"${file%%/*}/\" ;;\n>> -                       *) echo \"$file \" ;;\n>> +                       ?*/*) echo \"${file%%/*}${old:+/}\" ;;\n>> +                       *) echo \"${file}${old:+ }\" ;;\n>>                         esac\n>>                 done | sort | uniq\n>>         fi\n>> @@ -480,7 +481,7 @@ __git_complete_revlist_file ()\n>>  # The exception is --committable, which finds the files appropriate commit.\n>>  __git_complete_index_file ()\n>>  {\n>> -       local pfx=\"\" cur_=\"$cur\"\n>> +       local pfx=\"\" cur_=\"$cur\" old\n>>\n>>         case \"$cur_\" in\n>>         ?*/*)\n>> @@ -490,7 +491,8 @@ __git_complete_index_file ()\n>>                 ;;\n>>         esac\n>>\n>> -       __gitcomp_nl \"$(__git_index_files \"$1\" \"$pfx\")\" \"$pfx\" \"$cur_\" \"\"\n>> +       compopt -o filenames +o nospace 2> /dev/null || old=1\n>> +       __gitcomp_nl \"$(__git_index_files \"$1\" \"$pfx\" \"$old\")\" \"$pfx\" \"$cur_\" \"\"\n>>  }\n>>\n>>  __git_complete_file ()\n>>\n>\n> I like the idea (but I have not tested it), however compopt is called\n> two times, for each completion.\n\nWhy two times?\n\n> Maybe we can test for `-o filenames` support when script is loaded,\n> where currently there is a Bash version check, and set a global variable?\n\nYeah, that's the way bash-completion used to do it. But I wonder if we\nshould be worrying about this at this point, even bash-completion\ndropped support for bash < 4 more than two years ago, and even debian\nstable is at 4.1.\n\nhttp://anonscm.debian.org/gitweb/?p=bash-completion/bash-completion.git;a=commitdiff;h=f1b3be235722d1ea51160acf50120eb88995a5b7\n\nCheers.\n\n-- \nFelipe Contreras\n"},{"id":"215719","messageId":"CAMP44s10Uv-n2rBLPS-uYpZBoyZDCjQ_hRA2q=zf1WC4S=ac6g@mail.gmail.com","threadId":"33629","inReplyTo":"CAMP44s32WrnFr9Lp03Wu8gC6=FaACBtDbi1rnu=bo94Aa73TBA@mail.gmail.com","subject":"Re: [PATCH 00/11] completion: general cleanups","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-04-27T19:43:30Z","receivedAt":"2013-04-27T19:43:30Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Sat, Apr 27, 2013 at 2:15 PM, Felipe Contreras\n<felipe.contreras@gmail.com> wrote:\n> On Sat, Apr 27, 2013 at 10:40 AM, Manlio Perillo\n> <manlio.perillo@gmail.com> wrote:\n>> -----BEGIN PGP SIGNED MESSAGE-----\n>> Hash: SHA1\n>>\n>> Il 27/04/2013 15:07, Felipe Contreras ha scritto:\n>>> [...]\n>>> This should do the trick. No?\n>>>\n>>> --- a/contrib/completion/git-completion.bash\n>>> +++ b/contrib/completion/git-completion.bash\n>>> @@ -262,16 +262,17 @@ __git_ls_files_helper ()\n>>>  #    If provided, only files within the specified directory are listed.\n>>>  #    Sub directories are never recursed.  Path must have a trailing\n>>>  #    slash.\n>>> +# 3. Compat mode; set to enable.\n>>>  __git_index_files ()\n>>>  {\n>>> -       local dir=\"$(__gitdir)\" root=\"${2-.}\" file\n>>> +       local dir=\"$(__gitdir)\" root=\"${2-.}\" file old=\"${3-}\"\n>>>\n>>>         if [ -d \"$dir\" ]; then\n>>>                 __git_ls_files_helper \"$root\" \"$1\" |\n>>>                 while read -r file; do\n>>>                         case \"$file\" in\n>>> -                       ?*/*) echo \"${file%%/*}/\" ;;\n>>> -                       *) echo \"$file \" ;;\n>>> +                       ?*/*) echo \"${file%%/*}${old:+/}\" ;;\n>>> +                       *) echo \"${file}${old:+ }\" ;;\n>>>                         esac\n>>>                 done | sort | uniq\n>>>         fi\n>>> @@ -480,7 +481,7 @@ __git_complete_revlist_file ()\n>>>  # The exception is --committable, which finds the files appropriate commit.\n>>>  __git_complete_index_file ()\n>>>  {\n>>> -       local pfx=\"\" cur_=\"$cur\"\n>>> +       local pfx=\"\" cur_=\"$cur\" old\n>>>\n>>>         case \"$cur_\" in\n>>>         ?*/*)\n>>> @@ -490,7 +491,8 @@ __git_complete_index_file ()\n>>>                 ;;\n>>>         esac\n>>>\n>>> -       __gitcomp_nl \"$(__git_index_files \"$1\" \"$pfx\")\" \"$pfx\" \"$cur_\" \"\"\n>>> +       compopt -o filenames +o nospace 2> /dev/null || old=1\n>>> +       __gitcomp_nl \"$(__git_index_files \"$1\" \"$pfx\" \"$old\")\" \"$pfx\" \"$cur_\" \"\"\n>>>  }\n>>>\n>>>  __git_complete_file ()\n>>>\n>>\n>> I like the idea (but I have not tested it), however compopt is called\n>> two times, for each completion.\n>\n> Why two times?\n>\n>> Maybe we can test for `-o filenames` support when script is loaded,\n>> where currently there is a Bash version check, and set a global variable?\n>\n> Yeah, that's the way bash-completion used to do it. But I wonder if we\n> should be worrying about this at this point, even bash-completion\n> dropped support for bash < 4 more than two years ago, and even debian\n> stable is at 4.1.\n>\n> http://anonscm.debian.org/gitweb/?p=bash-completion/bash-completion.git;a=commitdiff;h=f1b3be235722d1ea51160acf50120eb88995a5b7\n\nActually, there's a way to trigger this in bash < 4, I've tested it\nand it works:\n\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -270,8 +270,8 @@ __git_index_files ()\n                __git_ls_files_helper \"$root\" \"$1\" |\n                while read -r file; do\n                        case \"$file\" in\n-                       ?*/*) echo \"${file%%/*}/\" ;;\n-                       *) echo \"$file \" ;;\n+                       ?*/*) echo \"${file%%/*}\" ;;\n+                       *) echo \"${file}\" ;;\n                        esac\n                done | sort | uniq\n        fi\n@@ -490,6 +490,10 @@ __git_complete_index_file ()\n                ;;\n        esac\n\n+       # use a hack to enable file mode in bash < 4\n+       compopt -o filenames +o nospace 2> /dev/null ||\n+       compgen -f /non-existing-dir/ > /dev/null\n+\n        __gitcomp_nl \"$(__git_index_files \"$1\" \"$pfx\")\" \"$pfx\" \"$cur_\" \"\"\n }\n\n\n-- \nFelipe Contreras\n"},{"id":"215749","messageId":"517C315B.2080106@gmail.com","threadId":"33629","inReplyTo":"CAMP44s32WrnFr9Lp03Wu8gC6=FaACBtDbi1rnu=bo94Aa73TBA@mail.gmail.com","subject":"Re: [PATCH 00/11] completion: general cleanups","fromName":"Manlio Perillo","fromEmail":"manlio.perillo@gmail.com","sentAt":"2013-04-27T20:13:15Z","receivedAt":"2013-04-27T20:13:15Z","isPatch":true,"sender":{"key":"manlio.perillo@gmail.com","avatar":"https://avatars.githubusercontent.com/u/6217088?v=4"},"body":"-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA1\n\nIl 27/04/2013 21:15, Felipe Contreras ha scritto:\n> [...]\n>>> @@ -480,7 +481,7 @@ __git_complete_revlist_file ()\n>>>  # The exception is --committable, which finds the files appropriate commit.\n>>>  __git_complete_index_file ()\n>>>  {\n>>> -       local pfx=\"\" cur_=\"$cur\"\n>>> +       local pfx=\"\" cur_=\"$cur\" old\n>>>\n>>>         case \"$cur_\" in\n>>>         ?*/*)\n>>> @@ -490,7 +491,8 @@ __git_complete_index_file ()\n>>>                 ;;\n>>>         esac\n>>>\n>>> -       __gitcomp_nl \"$(__git_index_files \"$1\" \"$pfx\")\" \"$pfx\" \"$cur_\" \"\"\n>>> +       compopt -o filenames +o nospace 2> /dev/null || old=1\n>>> +       __gitcomp_nl \"$(__git_index_files \"$1\" \"$pfx\" \"$old\")\" \"$pfx\" \"$cur_\" \"\"\n>>>  }\n>>>\n>>>  __git_complete_file ()\n>>>\n>>\n>> I like the idea (but I have not tested it), however compopt is called\n>> two times, for each completion.\n> \n> Why two times?\n\nAh, right; sorry.\nI missed the fact that you are using __gitcomp_nl instead of my\n__gitcomp_file.\n\n> \n>> Maybe we can test for `-o filenames` support when script is loaded,\n>> where currently there is a Bash version check, and set a global variable?\n> \n> Yeah, that's the way bash-completion used to do it. But I wonder if we\n> should be worrying about this at this point, even bash-completion\n> dropped support for bash < 4 more than two years ago, and even debian\n> stable is at 4.1.\n> \n\nI'm +0.\n\n> [...]\n\n\nRegards  Manlio\n-----BEGIN PGP SIGNATURE-----\nVersion: GnuPG v1.4.10 (GNU/Linux)\nComment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/\n\niEYEARECAAYFAlF8MVsACgkQscQJ24LbaUSY/wCgkq8CQeVGNpZFtchiLAKXYpxS\nwsAAnR0abrQzA1jW+Do7CSuJOZVMRuJu\n=zPgk\n-----END PGP SIGNATURE-----\n"}]}