{"thread":{"id":"32432","subject":"[PATCH v4] git-completion.bash: add support for path completion","startedAt":"2012-12-21T16:54:32Z","lastAt":"2013-01-08T18:28:40Z","messageCount":15,"participants":["Manlio Perillo","Junio C Hamano","Marc Khouzam","John Keeping"],"isPatch":true,"patchVersion":4,"patchTotal":null},"messages":[{"id":"205344","messageId":"1356108872-5881-1-git-send-email-manlio.perillo@gmail.com","threadId":"32432","inReplyTo":null,"subject":"[PATCH v4] git-completion.bash: add support for path completion","fromName":"Manlio Perillo","fromEmail":"manlio.perillo@gmail.com","sentAt":"2012-12-21T16:54:32Z","receivedAt":"2012-12-21T16:54:32Z","isPatch":true,"sender":{"key":"manlio.perillo@gmail.com","avatar":"https://avatars.githubusercontent.com/u/6217088?v=4"},"body":"The git-completion.bash script did not implemented full, git aware,\nsupport to complete paths, for git commands that operate on files within\nthe current working directory or the index.\n\nAs an example:\n\n\tgit add <TAB>\n\nwill suggest all files in the current working directory, including\nignored files and files that have not been modified.\n\nSupport path completion, for git commands where the non-option arguments\nalways refer to paths within the current working directory or the index,\nas the follow:\n\n* the path completion for the \"git rm\" and \"git ls-files\"\n  commands will suggest all cached files.\n\n* the path completion for the \"git add\" command will suggest all\n  untracked and modified files.  Ignored files are excluded.\n\n* the path completion for the \"git clean\" command will suggest all\n  untracked files.  Ignored files are excluded.\n\n* the path completion for the \"git mv\" command will suggest all cached\n  files when expanding the first argument, and all untracked and cached\n  files for subsequent arguments.  In the latter case, empty directories\n  are included and ignored files are excluded.\n\n* the path completion for the \"git commit\" command will suggest all\n  files that have been modified from the HEAD, if HEAD exists, otherwise\n  it will suggest all cached files.\n\nFor all affected commands, completion will always stop at directory\nboundary.  Only standard ignored files are excluded, using the\n--exclude-standard option of the ls-files command.\n\nSigned-off-by: Manlio Perillo <manlio.perillo@gmail.com>\n---\n\nChanges from version 3:\n\n\t* Fixed quoting issues\n\t* Fixed default parameters handling\n\t* Fixed a typo in the commit message: the affected command was ls-files,\n\t  not ls-tree.\n\t* Fixed incorrect behavior when expanding a path in \"git commit\"\n\t  command, for a newly created repository (when HEAD does not\n\t  exists).\n\t* Make sure to always execute git commands with stderr redirected to\n\t  /dev/null.\n\t* Improved path completion for the git mv command.\n\t  This required a small refactorization of the __git_index_files\n\t  function, in order to support multiple options for ls-files.\n\n contrib/completion/git-completion.bash | 140 +++++++++++++++++++++++++++++----\n 1 file changed, 124 insertions(+), 16 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 0b77eb1..c8c6464 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -13,6 +13,7 @@\n #    *) .git/remotes file names\n #    *) git 'subcommands'\n #    *) tree paths within 'ref:path/to/file' expressions\n+#    *) file paths within current working directory and index\n #    *) common --long-options\n #\n # To use these routines:\n@@ -233,6 +234,62 @@ __gitcomp_nl ()\n \tCOMPREPLY=($(compgen -P \"${2-}\" -S \"${4- }\" -W \"$1\" -- \"${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+# It accepts 1 optional argument: a directory path.  The path must have\n+# a trailing slash.\n+__git_index_file_list_filter ()\n+{\n+\tlocal pfx=\"${1-}\" offset=${#pfx} path\n+\n+\twhile read -r path; do\n+\t\tpath=\"${path:$offset}\"\n+\n+\t\tcase \"$path\" in\n+\t\t?*/*) echo \"${path%%/*}/\" ;;\n+\t\t*) echo $path ;;\n+\t\tesac\n+\tdone\n+}\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+#    slash.\n+__git_index_files ()\n+{\n+\tlocal dir=\"$(__gitdir)\"\n+\n+\tif [ -d \"$dir\" ]; then\n+\t\t# NOTE: $1 is not quoted in order to support multiple options\n+\t\tgit --git-dir=\"$dir\" ls-files --exclude-standard $1 ${2+\"$2\"} 2>/dev/null |\n+\t\t\t__git_index_file_list_filter ${2+\"$2\"} |\n+\t\t\tuniq\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)\"\n+\n+\tif [ -d \"$dir\" ]; then\n+\t\tgit --git-dir=\"$dir\" diff-index --name-only \"$1\" 2>/dev/null |\n+\t\t\t__git_index_file_list_filter ${2+\"$2\"} |\n+\t\t\tuniq\n+\tfi\n+}\n+\n __git_heads ()\n {\n \tlocal dir=\"$(__gitdir)\"\n@@ -430,6 +487,46 @@ __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 ()\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_nl \"$(__git_index_files \"$1\" \"$pfx\")\" \"$pfx\" \"$cur_\" \"\"\n+\t\t;;\n+\t*)\n+\t\t__gitcomp_nl \"$(__git_index_files \"$1\")\" \"\" \"$cur_\" \"\"\n+\t\t;;\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_nl \"$(__git_diff_index_files \"$1\" \"$pfx\")\" \"$pfx\" \"$cur_\" \"\"\n+\t\t;;\n+\t*)\n+\t\t__gitcomp_nl \"$(__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@@ -770,8 +867,6 @@ _git_apply ()\n \n _git_add ()\n {\n-\t__git_has_doubledash && return\n-\n \tcase \"$cur\" in\n \t--*)\n \t\t__gitcomp \"\n@@ -780,7 +875,9 @@ _git_add ()\n \t\t\t\"\n \t\treturn\n \tesac\n-\tCOMPREPLY=()\n+\n+\t# XXX should we check for --update and --all options ?\n+\t__git_complete_index_file \"--others --modified\"\n }\n \n _git_archive ()\n@@ -930,15 +1027,15 @@ _git_cherry_pick ()\n \n _git_clean ()\n {\n-\t__git_has_doubledash && return\n-\n \tcase \"$cur\" in\n \t--*)\n \t\t__gitcomp \"--dry-run --quiet\"\n \t\treturn\n \t\t;;\n \tesac\n-\tCOMPREPLY=()\n+\n+\t# XXX should we check for -x option ?\n+\t__git_complete_index_file \"--others\"\n }\n \n _git_clone ()\n@@ -969,8 +1066,6 @@ _git_clone ()\n \n _git_commit ()\n {\n-\t__git_has_doubledash && return\n-\n \tcase \"$cur\" in\n \t--cleanup=*)\n \t\t__gitcomp \"default strip verbatim whitespace\n@@ -998,7 +1093,13 @@ _git_commit ()\n \t\t\t\"\n \t\treturn\n \tesac\n-\tCOMPREPLY=()\n+\n+\tif git rev-parse --verify --quiet HEAD 1>/dev/null; then\n+\t\t__git_complete_diff_index_file \"HEAD\"\n+\telse\n+\t\t# This is the first commit\n+\t\t__git_complete_index_file \"--cached\"\n+\tfi\n }\n \n _git_describe ()\n@@ -1216,8 +1317,6 @@ _git_init ()\n \n _git_ls_files ()\n {\n-\t__git_has_doubledash && return\n-\n \tcase \"$cur\" in\n \t--*)\n \t\t__gitcomp \"--cached --deleted --modified --others --ignored\n@@ -1230,7 +1329,10 @@ _git_ls_files ()\n \t\treturn\n \t\t;;\n \tesac\n-\tCOMPREPLY=()\n+\n+\t# XXX ignore options like --modified and always suggest all cached\n+\t# files.\n+\t__git_complete_index_file \"--cached\"\n }\n \n _git_ls_remote ()\n@@ -1362,7 +1464,14 @@ _git_mv ()\n \t\treturn\n \t\t;;\n \tesac\n-\tCOMPREPLY=()\n+\n+\tif [ $cword -gt 2 ]; then\n+\t\t# We need to show both cached and untracked files (including\n+\t\t# empty directories) since this may not be the last argument.\n+\t\t__git_complete_index_file \"--cached --others --directory\"\n+\telse\n+\t\t__git_complete_index_file \"--cached\"\n+\tfi\n }\n \n _git_name_rev ()\n@@ -2068,15 +2177,14 @@ _git_revert ()\n \n _git_rm ()\n {\n-\t__git_has_doubledash && return\n-\n \tcase \"$cur\" in\n \t--*)\n \t\t__gitcomp \"--cached --dry-run --ignore-unmatch --quiet\"\n \t\treturn\n \t\t;;\n \tesac\n-\tCOMPREPLY=()\n+\n+\t__git_complete_index_file \"--cached\"\n }\n \n _git_shortlog ()\n-- \n1.8.1.rc1.18.g9db0d25\n"},{"id":"205354","messageId":"7vmwx71e2y.fsf@alter.siamese.dyndns.org","threadId":"32432","inReplyTo":"1356108872-5881-1-git-send-email-manlio.perillo@gmail.com","subject":"Re: [PATCH v4] git-completion.bash: add support for path completion","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-12-21T17:59:17Z","receivedAt":"2012-12-21T17:59:17Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Manlio Perillo <manlio.perillo@gmail.com> writes:\n\n> +\t\tcase \"$path\" in\n> +\t\t?*/*) echo \"${path%%/*}/\" ;;\n> +\t\t*) echo $path ;;\n\n$path unquoted???\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> +#    slash.\n> +__git_index_files ()\n> +{\n> +\tlocal dir=\"$(__gitdir)\"\n> +\n> +\tif [ -d \"$dir\" ]; then\n> +\t\t# NOTE: $1 is not quoted in order to support multiple options\n\nGood thinking to document this.  Thanks.\n\nI take it that $1 never comes from the end user and it is known that\nit is correct to split them at $IFS?  That is the way I read callers\nof this function in this patch, but I am just double-checking.\n\n> @@ -998,7 +1093,13 @@ _git_commit ()\n>  \t\t\t\"\n>  \t\treturn\n>  \tesac\n> -\tCOMPREPLY=()\n> +\n> +\tif git rev-parse --verify --quiet HEAD 1>/dev/null; then\n\ns/1>/>/;\n\n> +\t\t__git_complete_diff_index_file \"HEAD\"\n\nAs this runs \"git diff-index\" without --cached, \n\nThe completion will give only for paths that have difference between\nthe working tree and the HEAD.  If the user has a bogus contents\nthat was \"git add\"ed earlier, (i.e. the index is different from\nHEAD), then realizes the mistake and fixes it in the working tree\nwith his editor to match \"HEAD\" (i.e. the working tree is the same\nas HEAD):\n\n\tgit commit the-prefix-to-that-file<TAB>\n\nto complete the filename will not give that file.  I do not think it\nis a show-stopper, but it may puzzle the users when they encounter\nthe situation.\n\nI am wondering if reading from \"git status --porcelain\" might be a\nbetter alternative, or if it is too much trouble and slow things\ndown to cover such a corner case.\n\n> @@ -1362,7 +1464,14 @@ _git_mv ()\n>  \t\treturn\n>  \t\t;;\n>  \tesac\n> -\tCOMPREPLY=()\n> +\n> +\tif [ $cword -gt 2 ]; then\n> +\t\t# We need to show both cached and untracked files (including\n> +\t\t# empty directories) since this may not be the last argument.\n> +\t\t__git_complete_index_file \"--cached --others --directory\"\n> +\telse\n> +\t\t__git_complete_index_file \"--cached\"\n> +\tfi\n\nIs $cword affected by the presense of \"-f\" in \"git mv [-f] foo bar\"?\nJust being curious.\n\nOther than that, I do not see anything majorly wrong from the coding\nand semantics point of view in the patch.  As to the interaction\nwith the rest of the completion machinery, I'll leave the review to\nthe area experts CC'ed and wait for their comments.\n\nThanks.\n"},{"id":"205365","messageId":"50D4B23D.2030507@gmail.com","threadId":"32432","inReplyTo":"7vmwx71e2y.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH v4] git-completion.bash: add support for path completion","fromName":"Manlio Perillo","fromEmail":"manlio.perillo@gmail.com","sentAt":"2012-12-21T19:02:21Z","receivedAt":"2012-12-21T19:02:21Z","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 21/12/2012 18:59, Junio C Hamano ha scritto:\n> Manlio Perillo <manlio.perillo@gmail.com> writes:\n> \n>> +\t\tcase \"$path\" in\n>> +\t\t?*/*) echo \"${path%%/*}/\" ;;\n>> +\t\t*) echo $path ;;\n> \n> $path unquoted???\n> \n\nMissed again, thanks.\nI hope this is really the last one!\n\n> [...]\n>> +__git_index_files ()\n>> +{\n>> +\tlocal dir=\"$(__gitdir)\"\n>> +\n>> +\tif [ -d \"$dir\" ]; then\n>> +\t\t# NOTE: $1 is not quoted in order to support multiple options\n> \n> Good thinking to document this.  Thanks.\n> \n> I take it that $1 never comes from the end user and it is known that\n> it is correct to split them at $IFS?  That is the way I read callers\n> of this function in this patch, but I am just double-checking.\n> \n\nYes, $1 is always set internally (but I will check again)\nProbably there are better solutions.\n\n\n>> @@ -998,7 +1093,13 @@ _git_commit ()\n>>  \t\t\t\"\n>>  \t\treturn\n>>  \tesac\n>> -\tCOMPREPLY=()\n>> +\n>> +\tif git rev-parse --verify --quiet HEAD 1>/dev/null; then\n> \n> s/1>/>/;\n> \n\nWhat is the reason?\nCoding style?\n\n>> +\t\t__git_complete_diff_index_file \"HEAD\"\n> \n> As this runs \"git diff-index\" without --cached, \n> \n> The completion will give only for paths that have difference between\n> the working tree and the HEAD.  If the user has a bogus contents\n> that was \"git add\"ed earlier, (i.e. the index is different from\n> HEAD), then realizes the mistake and fixes it in the working tree\n> with his editor to match \"HEAD\" (i.e. the working tree is the same\n> as HEAD):\n> \n> \tgit commit the-prefix-to-that-file<TAB>\n> \n> to complete the filename will not give that file.  I do not think it\n> is a show-stopper, but it may puzzle the users when they encounter\n> the situation.\n> \n\nUmh, I just checked this case.\n\n  0) git init test\n  1) Added a README file with \"Hello World.\", and committed.\n  2) Modified the README file with \"Hello World!\" and executed\n     git add README\n  3) Modified the README file with \"Hello World.\" (the original content)\n  4) $ git diff HEAD:README README\n     $ git diff-index --name-only HEAD\n     README\n\n     git commit <TAB> shows the README file.\n\nIf I understand correctly the documentation of diff-index, it will\nalways compare the content of the index with HEAD.\nIf --cached is specified, it will ignore the stat state of the file on disk.\n\n\n> I am wondering if reading from \"git status --porcelain\" might be a\n> better alternative, or if it is too much trouble and slow things\n> down to cover such a corner case.\n> \n\nIt have considered it.\n\nThe problem is that the output of \"git status --porcelain\" is not\ntrivial to parse.\n\n\n>> @@ -1362,7 +1464,14 @@ _git_mv ()\n>>  \t\treturn\n>>  \t\t;;\n>>  \tesac\n>> -\tCOMPREPLY=()\n>> +\n>> +\tif [ $cword -gt 2 ]; then\n>> +\t\t# We need to show both cached and untracked files (including\n>> +\t\t# empty directories) since this may not be the last argument.\n>> +\t\t__git_complete_index_file \"--cached --others --directory\"\n>> +\telse\n>> +\t\t__git_complete_index_file \"--cached\"\n>> +\tfi\n> \n> Is $cword affected by the presense of \"-f\" in \"git mv [-f] foo bar\"?\n> Just being curious.\n> \n\nYes, it is affected; I missed it, thanks.\nIt should count only non-option arguments.\n\n\n> Other than that, I do not see anything majorly wrong from the coding\n> and semantics point of view in the patch.  As to the interaction\n> with the rest of the completion machinery, I'll leave the review to\n> the area experts CC'ed and wait for their comments.\n> \n> Thanks.\n> \n\nThanks for your review.\n\n\nManlio\n-----BEGIN PGP SIGNATURE-----\nVersion: GnuPG v1.4.10 (GNU/Linux)\nComment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/\n\niEYEARECAAYFAlDUsjwACgkQscQJ24LbaUSGuwCffon7/VGFo98CCBsZlmOdNYYE\n91oAn3X8fbr5jtzMUOZkMp9CuGWCa7Cf\n=Qzsv\n-----END PGP SIGNATURE-----\n"},{"id":"205979","messageId":"E59706EF8DB1D147B15BECA3322E4BDC0672D1@eusaamb103.ericsson.se","threadId":"32432","inReplyTo":"1356108872-5881-1-git-send-email-manlio.perillo@gmail.com","subject":"RE: [PATCH v4] git-completion.bash: add support for path completion","fromName":"Marc Khouzam","fromEmail":"marc.khouzam@ericsson.com","sentAt":"2013-01-04T21:25:11Z","receivedAt":"2013-01-04T21:25:11Z","isPatch":true,"sender":{"key":"marc.khouzam@ericsson.com","avatar":"https://gravatar.com/avatar/de564e23ad14e2945f9f1cdb4d0227c935b5b54c39576a304d47caa3e23dcd33?d=mp&s=160"},"body":"\n> -----Original Message-----\n> From: git-owner@vger.kernel.org \n> [mailto:git-owner@vger.kernel.org] On Behalf Of Manlio Perillo\n> Sent: Friday, December 21, 2012 11:55 AM\n> To: git@vger.kernel.org\n> Cc: szeder@ira.uka.de; felipe.contreras@gmail.com; Manlio Perillo\n> Subject: [PATCH v4] git-completion.bash: add support for path \n> completion\n> \n> The git-completion.bash script did not implemented full, git aware,\n> support to complete paths, for git commands that operate on \n> files within\n> the current working directory or the index.\n\nI think this is a great improvement!  Very nice.\n\nI've been playing with it but I'm not getting the expected \nbehavior when I cd to a sub-directory.  Instead I get all files\nin the repo as proposals.  I'm trying it in the git git-repository\nitself.  Here is a sample:\n\n> git status\n# On branch pu\nnothing to commit, working directory clean\n> source contrib/completion/git-completion.bash\n> touch contrib/test1\n> touch contrib/test2\n> git status\n# On branch pu\n# Untracked files:\n#   (use \"git add <file>...\" to include in what will be committed)\n#\n#       contrib/test1\n#       contrib/test2\nnothing added to commit but untracked files present (use \"git add\" to track)\n> git add <TAB> # this works as expected and I get: contrib/test1  contrib/test2  \n> cd contrib/\n> git add <TAB>\nDisplay all 387 possibilities? (y or n)  # That is not right. Shouldn't I get\n                                         # the same two files only?\n\nMaybe I mis-understood what should happen?\n\nBesides that, without looking at the patch in detail, I put just a couple\nof minor points below.\n\n> As an example:\n> \n> \tgit add <TAB>\n> \n> will suggest all files in the current working directory, including\n> ignored files and files that have not been modified.\n> \n> Support path completion, for git commands where the \n> non-option arguments\n> always refer to paths within the current working directory or \n> the index, as the follow:\n\ns/as the follow/as follows/\n\n> * the path completion for the \"git rm\" and \"git ls-files\"\n>   commands will suggest all cached files.\n> \n> * the path completion for the \"git add\" command will suggest all\n>   untracked and modified files.  Ignored files are excluded.\n> \n> * the path completion for the \"git clean\" command will suggest all\n>   untracked files.  Ignored files are excluded.\n> \n> * the path completion for the \"git mv\" command will suggest all cached\n>   files when expanding the first argument, and all untracked \n> and cached\n>   files for subsequent arguments.  In the latter case, empty \n> directories\n>   are included and ignored files are excluded.\n> \n> * the path completion for the \"git commit\" command will suggest all\n>   files that have been modified from the HEAD, if HEAD \n> exists, otherwise\n>   it will suggest all cached files.\n> \n> For all affected commands, completion will always stop at directory\n> boundary.  Only standard ignored files are excluded, using the\n> --exclude-standard option of the ls-files command.\n> \n> Signed-off-by: Manlio Perillo <manlio.perillo@gmail.com>\n> ---\n> \n> Changes from version 3:\n> \n> \t* Fixed quoting issues\n> \t* Fixed default parameters handling\n> \t* Fixed a typo in the commit message: the affected \n> command was ls-files,\n> \t  not ls-tree.\n> \t* Fixed incorrect behavior when expanding a path in \"git commit\"\n> \t  command, for a newly created repository (when HEAD does not\n> \t  exists).\n> \t* Make sure to always execute git commands with stderr \n> redirected to\n> \t  /dev/null.\n> \t* Improved path completion for the git mv command.\n> \t  This required a small refactorization of the __git_index_files\n> \t  function, in order to support multiple options for ls-files.\n> \n>  contrib/completion/git-completion.bash | 140 \n> +++++++++++++++++++++++++++++----\n>  1 file changed, 124 insertions(+), 16 deletions(-)\n> \n> diff --git a/contrib/completion/git-completion.bash \n> b/contrib/completion/git-completion.bash\n> index 0b77eb1..c8c6464 100644\n> --- a/contrib/completion/git-completion.bash\n> +++ b/contrib/completion/git-completion.bash\n> @@ -13,6 +13,7 @@\n>  #    *) .git/remotes file names\n>  #    *) git 'subcommands'\n>  #    *) tree paths within 'ref:path/to/file' expressions\n> +#    *) file paths within current working directory and index\n>  #    *) common --long-options\n>  #\n>  # To use these routines:\n> @@ -233,6 +234,62 @@ __gitcomp_nl ()\n>  \tCOMPREPLY=($(compgen -P \"${2-}\" -S \"${4- }\" -W \"$1\" -- \n> \"${3-$cur}\"))\n>  }\n>  \n> +# Process path list returned by \"ls-files\" and \"diff-index \n> --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> +# It accepts 1 optional argument: a directory path.  The \n> path must have\n> +# a trailing slash.\n> +__git_index_file_list_filter ()\n> +{\n> +\tlocal pfx=\"${1-}\" offset=${#pfx} path\n> +\n> +\twhile read -r path; do\n> +\t\tpath=\"${path:$offset}\"\n> +\n> +\t\tcase \"$path\" in\n> +\t\t?*/*) echo \"${path%%/*}/\" ;;\n> +\t\t*) echo $path ;;\n> +\t\tesac\n> +\tdone\n> +}\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 \n> are listed.\n> +#    Sub directories are never recursed.  Path must have a trailing\n> +#    slash.\n> +__git_index_files ()\n> +{\n> +\tlocal dir=\"$(__gitdir)\"\n> +\n> +\tif [ -d \"$dir\" ]; then\n> +\t\t# NOTE: $1 is not quoted in order to support \n> multiple options\n> +\t\tgit --git-dir=\"$dir\" ls-files \n> --exclude-standard $1 ${2+\"$2\"} 2>/dev/null |\n> +\t\t\t__git_index_file_list_filter ${2+\"$2\"} |\n> +\t\t\tuniq\n\nWill the output piped to uniq always be sorted?  It has to be.\nIf it is not, you must use\n  sort | uniq\n\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 \n> 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)\"\n> +\n> +\tif [ -d \"$dir\" ]; then\n> +\t\tgit --git-dir=\"$dir\" diff-index --name-only \n> \"$1\" 2>/dev/null |\n> +\t\t\t__git_index_file_list_filter ${2+\"$2\"} |\n> +\t\t\tuniq\n\nWill the output piped to uniq always be sorted?  It has to be.\nIf it is not, you must use\n  sort | uniq\n\n> +\tfi\n> +}\n> +\n>  __git_heads ()\n>  {\n>  \tlocal dir=\"$(__gitdir)\"\n> @@ -430,6 +487,46 @@ __git_complete_revlist_file ()\n>  }\n>  \n>  \n> +# __git_complete_index_file requires 1 argument: the options \n> to pass to\n> +# ls-file\n> +__git_complete_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_nl \"$(__git_index_files \"$1\" \"$pfx\")\" \n> \"$pfx\" \"$cur_\" \"\"\n> +\t\t;;\n> +\t*)\n> +\t\t__gitcomp_nl \"$(__git_index_files \"$1\")\" \"\" \"$cur_\" \"\"\n> +\t\t;;\n> +\tesac\n> +}\n> +\n> +# __git_complete_diff_index_file requires 1 argument: the id \n> 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_nl \"$(__git_diff_index_files \"$1\" \n> \"$pfx\")\" \"$pfx\" \"$cur_\" \"\"\n> +\t\t;;\n> +\t*)\n> +\t\t__gitcomp_nl \"$(__git_diff_index_files \"$1\")\" \n> \"\" \"$cur_\" \"\"\n> +\t\t;;\n> +\tesac\n> +}\n> +\n>  __git_complete_file ()\n>  {\n>  \t__git_complete_revlist_file\n> @@ -770,8 +867,6 @@ _git_apply ()\n>  \n>  _git_add ()\n>  {\n> -\t__git_has_doubledash && return\n> -\n>  \tcase \"$cur\" in\n>  \t--*)\n>  \t\t__gitcomp \"\n> @@ -780,7 +875,9 @@ _git_add ()\n>  \t\t\t\"\n>  \t\treturn\n>  \tesac\n> -\tCOMPREPLY=()\n> +\n> +\t# XXX should we check for --update and --all options ?\n> +\t__git_complete_index_file \"--others --modified\"\n>  }\n>  \n>  _git_archive ()\n> @@ -930,15 +1027,15 @@ _git_cherry_pick ()\n>  \n>  _git_clean ()\n>  {\n> -\t__git_has_doubledash && return\n> -\n>  \tcase \"$cur\" in\n>  \t--*)\n>  \t\t__gitcomp \"--dry-run --quiet\"\n>  \t\treturn\n>  \t\t;;\n>  \tesac\n> -\tCOMPREPLY=()\n> +\n> +\t# XXX should we check for -x option ?\n> +\t__git_complete_index_file \"--others\"\n>  }\n>  \n>  _git_clone ()\n> @@ -969,8 +1066,6 @@ _git_clone ()\n>  \n>  _git_commit ()\n>  {\n> -\t__git_has_doubledash && return\n> -\n>  \tcase \"$cur\" in\n>  \t--cleanup=*)\n>  \t\t__gitcomp \"default strip verbatim whitespace\n> @@ -998,7 +1093,13 @@ _git_commit ()\n>  \t\t\t\"\n>  \t\treturn\n>  \tesac\n> -\tCOMPREPLY=()\n> +\n> +\tif git rev-parse --verify --quiet HEAD 1>/dev/null; then\n> +\t\t__git_complete_diff_index_file \"HEAD\"\n> +\telse\n> +\t\t# This is the first commit\n> +\t\t__git_complete_index_file \"--cached\"\n> +\tfi\n>  }\n>  \n>  _git_describe ()\n> @@ -1216,8 +1317,6 @@ _git_init ()\n>  \n>  _git_ls_files ()\n>  {\n> -\t__git_has_doubledash && return\n> -\n>  \tcase \"$cur\" in\n>  \t--*)\n>  \t\t__gitcomp \"--cached --deleted --modified \n> --others --ignored\n> @@ -1230,7 +1329,10 @@ _git_ls_files ()\n>  \t\treturn\n>  \t\t;;\n>  \tesac\n> -\tCOMPREPLY=()\n> +\n> +\t# XXX ignore options like --modified and always suggest \n> all cached\n> +\t# files.\n> +\t__git_complete_index_file \"--cached\"\n>  }\n>  \n>  _git_ls_remote ()\n> @@ -1362,7 +1464,14 @@ _git_mv ()\n>  \t\treturn\n>  \t\t;;\n>  \tesac\n> -\tCOMPREPLY=()\n> +\n> +\tif [ $cword -gt 2 ]; then\n> +\t\t# We need to show both cached and untracked \n> files (including\n> +\t\t# empty directories) since this may not be the \n> last argument.\n> +\t\t__git_complete_index_file \"--cached --others \n> --directory\"\n> +\telse\n> +\t\t__git_complete_index_file \"--cached\"\n> +\tfi\n>  }\n>  \n>  _git_name_rev ()\n> @@ -2068,15 +2177,14 @@ _git_revert ()\n>  \n>  _git_rm ()\n>  {\n> -\t__git_has_doubledash && return\n> -\n>  \tcase \"$cur\" in\n>  \t--*)\n>  \t\t__gitcomp \"--cached --dry-run --ignore-unmatch --quiet\"\n>  \t\treturn\n>  \t\t;;\n>  \tesac\n> -\tCOMPREPLY=()\n> +\n> +\t__git_complete_index_file \"--cached\"\n>  }\n>  \n>  _git_shortlog ()\n> -- \n> 1.8.1.rc1.18.g9db0d25\n> \n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n> "},{"id":"205989","messageId":"7vobh4sffw.fsf@alter.siamese.dyndns.org","threadId":"32432","inReplyTo":"E59706EF8DB1D147B15BECA3322E4BDC0672D1@eusaamb103.ericsson.se","subject":"Re: [PATCH v4] git-completion.bash: add support for path completion","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-01-04T23:20:51Z","receivedAt":"2013-01-04T23:20:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Marc Khouzam <marc.khouzam@ericsson.com> writes:\n\n> I've been playing with it but I'm not getting the expected \n> behavior when I cd to a sub-directory.\n\nThanks for testing.  Manlio?\n"},{"id":"206001","messageId":"7vehi0qh4x.fsf@alter.siamese.dyndns.org","threadId":"32432","inReplyTo":"7vobh4sffw.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH v4] git-completion.bash: add support for path completion","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-01-05T06:27:10Z","receivedAt":"2013-01-05T06:27:10Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Marc Khouzam <marc.khouzam@ericsson.com> writes:\n>\n>> I've been playing with it but I'm not getting the expected \n>> behavior when I cd to a sub-directory.\n>\n> Thanks for testing.  Manlio?\n\nCan you try the attached patch?\n\nAs I am not familiar with the completion machinery, take this with a\nlarge grain of salt.  Here is my explanation of what is going on in\nthis \"how about this\" fixup:\n\n * Giving --git-dir from the command line (or GIT_DIR environment)\n   without specifying GIT_WORK_TREE is to signal Git that you are at\n   the top of the working tree.  \"git ls-files\" will then show the\n   full tree even outside the real $cwd because you are lying to\n   Git.\n\n * \"git diff-index\" could be told to show only the $cwd and its\n   subdirectory with the \"--relative\" option, but it alone is not\n   sufficient if you throw --git-dir at it; again, you end up lying\n   that you are at the top.\n\n * As far as I can tell, there is no reason you would want to pass\n   \"--git-dir\" to these invocations of ls-files and diff-index.  If\n   the previous call to \"__gitdir\" could figure out where it is, the\n   command should be able to figure it out the same way.\n   \nThere seem to be millions of other existing \"git --git-dir=$there\"\nin this script.  As I already said, I am not familiar with the\ncompletion machinery, and I do not know what they are for in the\nfirst place.  Perhaps people put them there for a reason, but I do\nnot know what that reason is.\n\nI think the ones for \"for-each-ref\", \"config\" and \"stash\" should be\nharmless.  They are commands that do not care about the working\ntree.\n\nThere is one given to \"ls-tree\" used in __git_complete_revlist_file;\nI do not know if this was intended, what it is for, and if that is\nworking as intended, though.\n\nI've been CC'ing two people who touched this script rather heavily,\nare expected to know the completion machinery, and should be able to\nhelp polishing this topic and moving it forward.  Perhaps one of\nthem can shed light on this.\n\n-- >8 --\nSubject: completion: do not pass harmful \"--git-dir=$there\"\n\nThe recently added __git_index_files and __git_diff_index_files\nhelper functions invoke \"ls-files\" and \"diff_index\" while explicitly\npassing \"--git-dir=$there\", to tell them that the invocation is done\nat the top of the working tree, which may not be the case when the\nuser is in a subdirectory.  Remove the harmful use of this option,\n\nTell \"diff-index\" to show only the paths in the $cwd and show them\nrelative to the $cwd by passing \"--relative\". The \"ls-files\" does\nnot need this, as that is already its default mode of operation.\n\n---\n contrib/completion/git-completion.bash | 12 ++++++------\n 1 file changed, 6 insertions(+), 6 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex c8c6464..f4bd548 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -267,9 +267,9 @@ __git_index_files ()\n \n \tif [ -d \"$dir\" ]; then\n \t\t# NOTE: $1 is not quoted in order to support multiple options\n-\t\tgit --git-dir=\"$dir\" ls-files --exclude-standard $1 ${2+\"$2\"} 2>/dev/null |\n-\t\t\t__git_index_file_list_filter ${2+\"$2\"} |\n-\t\t\tuniq\n+\t\tgit ls-files --exclude-standard $1 ${2+\"$2\"} 2>/dev/null |\n+\t\t__git_index_file_list_filter ${2+\"$2\"} |\n+\t\tuniq\n \tfi\n }\n \n@@ -284,9 +284,9 @@ __git_diff_index_files ()\n \tlocal dir=\"$(__gitdir)\"\n \n \tif [ -d \"$dir\" ]; then\n-\t\tgit --git-dir=\"$dir\" diff-index --name-only \"$1\" 2>/dev/null |\n-\t\t\t__git_index_file_list_filter ${2+\"$2\"} |\n-\t\t\tuniq\n+\t\tgit diff-index --name-only --relative \"$1\" 2>/dev/null |\n+\t\t__git_index_file_list_filter ${2+\"$2\"} |\n+\t\tuniq\n \tfi\n }\n \n"},{"id":"206045","messageId":"E59706EF8DB1D147B15BECA3322E4BDC0681FA@eusaamb103.ericsson.se","threadId":"32432","inReplyTo":"7vehi0qh4x.fsf@alter.siamese.dyndns.org","subject":"RE: [PATCH v4] git-completion.bash: add support for path completion","fromName":"Marc Khouzam","fromEmail":"marc.khouzam@ericsson.com","sentAt":"2013-01-05T20:23:39Z","receivedAt":"2013-01-05T20:23:39Z","isPatch":true,"sender":{"key":"marc.khouzam@ericsson.com","avatar":"https://gravatar.com/avatar/de564e23ad14e2945f9f1cdb4d0227c935b5b54c39576a304d47caa3e23dcd33?d=mp&s=160"},"body":"\n> Junio C Hamano <gitster@pobox.com> writes:\n> \n>>  Marc Khouzam <marc.khouzam@ericsson.com> writes:\n>>\n>>> I've been playing with it but I'm not getting the expected\n>>> behavior when I cd to a sub-directory.\n>>\n>> Thanks for testing.  Manlio?\n> \n> Can you try the attached patch?\n\nThanks for this, it improves the situation dramatically.\nI did further testing with your patch and found some less obvious\nissues.  I didn't debug the script myself as I'm not that familiar with\nit either, but I think the testcases below should help Manlio or\nsomeone else look into some regressions.\n\n1- Using .. or . breaks completion when after the '/':\n> cd git/contrib\n> git rm ../contrib/completion/<tab>\n../contrib/completion/ion.bash  ../contrib/completion/ion.tcsh  ../contrib/completion/ion.zsh   ../contrib/completion/sh\nIt looks like the space taken by the path where we are located, eats up the same number of characters from the file name, e.g.,\n   ../contrib/completion/ion.bash\n   ../contrib/git-completion.bash\n\n2- Maybe related to problem 1.  Using .. breaks completion in other ways:\n> cd git/contrib\n> git rm ../con<tab>\n../config.c       ../config.mak.in  ../configure.ac   ../connect.c      ../connected.c    ../connected.h    ../convert.c      ../convert.h\nNotice that 'contrib' is not proposed.\nDon't be fooled by the fact that\n> git rm ../cont<tab>\nwill complete to \n> git rm ../contrib\nas it is only because the completion script returned nothing, and bash file-completion \nkicked-in instead (it fooled me :)).\n\n3- Also probably related to problems 1 and 2.  Using absolute paths behaves wierdly and \nworse than before:\ngit rm /home/marc/git/git/con<tab>\nwill give\ngit rm /home/marc/git/git/config-\nalthough there is the 'contrib' dir that should be shown, amongst others.\nSeems like the same problem as above with 'git rm ../con<tab>'\n\nIn my opinion, the above three cases are regressions.\n\n4- Completion choices include their entire path, which is not what bash does by default.  For example:\n> cd git/contrib\n> ls completion/git-<tab>\ngit-completion.bash  git-completion.tcsh  git-completion.zsh   git-prompt.sh\nbut\n> git rm completion/git-<tab>\ncompletion/git-completion.bash  completion/git-completion.tcsh  completion/git-completion.zsh   completion/git-prompt.sh\nnotice the extra 'completion/' before each completion.  This can get pretty large when completing with \nmany directory prefixes.  The current tcsh completion has the same problem which I couldn't fix.  However, I am \nnot sure if it can be fixed for bash.\n\nI personally don't think this is regression, just an slight annoyance.\n\n5- With this feature git-completion.bash will return directories as completions.  This is something\ngit-completion.tcsh is not handling very well.  I will post a patch to fix that.\n\nBelow are two suggestions that are in line with this effort but that are not regressions.\n\nA) It would be nice if \ngit commit -a <TAB>\nalso completed with untracked files\n\nB) Now that, for example, 'git rm' completion is smart about path completion \nit would be nice to somehow not trigger bash default file completion\nwhen 'git rm' does not report any completions.  \n\nFor example, if I have a file called zz.tar.gz (which is an ignored file) \nand I do 'git rm <tab>', I will get the proper list of files that can be\nremoved by git, excluding zz.tar.gz.  But if I complete\n'git rm zz.tar.<tab>' then the completion script will return nothing,\nsince git cannot remove that ignored file, but we will then fall-back\nto the bash default completion, which will complete the file to zz.tar.gz.\n\nAlthough there are some issues, I think this feature will greatly benefit the user\nand is worth the time needed to fix.\n\nThanks!\n\nMarc\n"},{"id":"206061","messageId":"50E89ACA.706@gmail.com","threadId":"32432","inReplyTo":"E59706EF8DB1D147B15BECA3322E4BDC0681FA@eusaamb103.ericsson.se","subject":"Re: [PATCH v4] git-completion.bash: add support for path completion","fromName":"Manlio Perillo","fromEmail":"manlio.perillo@gmail.com","sentAt":"2013-01-05T21:27:38Z","receivedAt":"2013-01-05T21:27:38Z","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 05/01/2013 21:23, Marc Khouzam ha scritto:\n> [...]\n> I did further testing with your patch and found some less obvious\n> issues.  I didn't debug the script myself as I'm not that familiar with\n> it either, but I think the testcases below should help Manlio or\n> someone else look into some regressions.\n> \n> 1- Using .. or . breaks completion when after the '/':\n> [...] \n> 2- Maybe related to problem 1.  Using .. breaks completion in other ways:\n> [...]\n> 3- Also probably related to problems 1 and 2.  Using absolute paths behaves wierdly and \n> worse than before:\n\nThanks for this.\n\nI begin to suspect that this is the reason why path completion has not\nbeen implemented by the original author of the bash completion script.\n\nThese issues seems hard to fix.\n\nTomorrow I will take some time to try to fix all the reported issues.\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\niEYEARECAAYFAlDomskACgkQscQJ24LbaUQJdwCfX0bMq3V88soqtf+xlypZ5D4f\nqwAAn3bK7UlcOK+hm+u06jmT05l1aJVf\n=IWap\n-----END PGP SIGNATURE-----\n"},{"id":"206163","messageId":"50E9BBB5.3000707@gmail.com","threadId":"32432","inReplyTo":"7vehi0qh4x.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH v4] git-completion.bash: add support for path completion","fromName":"Manlio Perillo","fromEmail":"manlio.perillo@gmail.com","sentAt":"2013-01-06T18:00:21Z","receivedAt":"2013-01-06T18:00:21Z","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 05/01/2013 07:27, Junio C Hamano ha scritto:\n> Junio C Hamano <gitster@pobox.com> writes:\n> \n>> Marc Khouzam <marc.khouzam@ericsson.com> writes:\n>>\n>>> I've been playing with it but I'm not getting the expected \n>>> behavior when I cd to a sub-directory.\n>>\n>> Thanks for testing.  Manlio?\n> \n> Can you try the attached patch?\n> \n\nThanks, it seems to fix the problem.\n\n> As I am not familiar with the completion machinery, take this with a\n> large grain of salt.  Here is my explanation of what is going on in\n> this \"how about this\" fixup:\n> \n>  * Giving --git-dir from the command line (or GIT_DIR environment)\n>    without specifying GIT_WORK_TREE is to signal Git that you are at\n>    the top of the working tree.  \"git ls-files\" will then show the\n>    full tree even outside the real $cwd because you are lying to\n>    Git.\n> \n\nI was not aware of this, and blindly copied the code from the other\nexisting functions.\nHowever the other completion functions never have to deal with paths in\nthe working directory.\n\n\nI have applied the patch to my local branch.\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\niEYEARECAAYFAlDpu7UACgkQscQJ24LbaUSmUACgl+OKUyvpp183kFZGmBpOfqm1\nyqEAnjxcqmZYvWSeIpOo6cNFl/dnMH76\n=oE/+\n-----END PGP SIGNATURE-----\n"},{"id":"206165","messageId":"50E9C4D1.4020608@gmail.com","threadId":"32432","inReplyTo":"E59706EF8DB1D147B15BECA3322E4BDC0681FA@eusaamb103.ericsson.se","subject":"Re: [PATCH v4] git-completion.bash: add support for path completion","fromName":"Manlio Perillo","fromEmail":"manlio.perillo@gmail.com","sentAt":"2013-01-06T18:39:13Z","receivedAt":"2013-01-06T18:39:13Z","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 05/01/2013 21:23, Marc Khouzam ha scritto:\n> [...]\n> Thanks for this, it improves the situation dramatically.\n> I did further testing with your patch and found some less obvious\n> issues.  I didn't debug the script myself as I'm not that familiar with\n> it either, but I think the testcases below should help Manlio or\n> someone else look into some regressions.\n> \n> 1- Using .. or . breaks completion when after the '/':\n> [...]\n> 2- Maybe related to problem 1.  Using .. breaks completion in other ways:\n> [...]\n> 3- Also probably related to problems 1 and 2.  Using absolute paths behaves wierdly and \n> worse than before:\n\n> In my opinion, the above three cases are regressions.\n>\n\nYes.\nI did not considered this use case, thanks!\nI have never done something like this when working with Mercurial.\n\nThe problem is caused by the __git_index_file_list_filter function.\n\nThe job of this function is to stop path completion at directory\nboundary (in order to avoid to suggest files in child\ndirectories [1]), and to make paths relative to current directory.\n\nUnfortunately, what it does is to simply remove the prefix string from\nthe path name; of course this will not work when the prefix is a non\ncanonical path name.\n\nThe solution is quite simple: canonicalize both the prefix path and each\nof the path name returned by git.\n\nThis can be done using `readlink -f \"$path\"` or `realpath $path`, but\nthe problem is that it is inefficient to execute an external command for\neach of the path returned by git; moreover readlink and realpath are not\nPOSIX and may not be supported on all platforms where git works (but I\nfound a portable implementation using pushd, popd, `pwd`,  `dirname`,\n`basename` -- not very efficient).\n\nIMHO, the best solution is to recode __git_index_file_list_filter in Perl.\n\nAnother possible solution (as suggested by Junio) is to use the\n- --relative option; unfortunately this is only supported by\n`git diff-index` and not by `git ls-files`.\nAnd it will not solve the problem when using absolute path names (but\nthis case can be handled by leaving path completion to bash).\n\n> 4- Completion choices include their entire path, which is not what bash does by default.  For example:\n>> cd git/contrib\n>> ls completion/git-<tab>\n> git-completion.bash  git-completion.tcsh  git-completion.zsh   git-prompt.sh\n> but\n>> git rm completion/git-<tab>\n> completion/git-completion.bash  completion/git-completion.tcsh  completion/git-completion.zsh   completion/git-prompt.sh\n> notice the extra 'completion/' before each completion.\n\nThis is another thing I missed.\nThe problem is that only the current directory is removed from the path\nnames returned by git.\n\n>  This can get pretty large when completing with \n> many directory prefixes.  The current tcsh completion has the same problem which I couldn't fix.  However, I am \n> not sure if it can be fixed for bash.\n> \n\nThe fix was very easy, and it seems to work.\nThe problem is in the __git_complete_index_files and\n__git_complete_diff_index_files function.\n\nWhen calling the __git_index_files and git_index_files, the \"$cur\"\nvariable should be used, instead of the computed \"$pfx\".\n\nNot sure if this is correct.\nI will post the patch, so you can test it.\n\n> I personally don't think this is regression, just an slight annoyance.\n> \n> 5- With this feature git-completion.bash will return directories as completions.  This is something\n> git-completion.tcsh is not handling very well.  I will post a patch to fix that.\n> \n\nI'll pass on this, thanks.\n\n> Below are two suggestions that are in line with this effort but that are not regressions.\n> \n> A) It would be nice if \n> git commit -a <TAB>\n> also completed with untracked files\n> \n\nI agree.\nAnd there are other places when it may be useful to check the passed\noptions (see the comments).\n\nBut I think it is better to leave these issues for the future.\nI will just add a comment to take note of this use case.\n\n> B) Now that, for example, 'git rm' completion is smart about path completion \n> it would be nice to somehow not trigger bash default file completion\n> when 'git rm' does not report any completions.  \n> \n\nNot sure how this can be done, but it is possible and should be easy.\n\n> For example, if I have a file called zz.tar.gz (which is an ignored file) \n> and I do 'git rm <tab>', I will get the proper list of files that can be\n> removed by git, excluding zz.tar.gz.  But if I complete\n> 'git rm zz.tar.<tab>' then the completion script will return nothing,\n> since git cannot remove that ignored file, but we will then fall-back\n> to the bash default completion, which will complete the file to zz.tar.gz.\n> \n> Although there are some issues, I think this feature will greatly benefit the user\n> and is worth the time needed to fix.\n> \n> Thanks!\n> \n> Marc\n\n\nThanks to you for the review!\n\nRegards   Manlio\n\n\n[1] this is what the Mercurial bash completion script does\n-----BEGIN PGP SIGNATURE-----\nVersion: GnuPG v1.4.10 (GNU/Linux)\nComment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/\n\niEYEARECAAYFAlDpxNEACgkQscQJ24LbaURZEgCcD2Uc+7/W+RCrMk3j+vrd5w36\n6ogAn1ou4pOarBSMywaQ3zQKdZmofyKA\n=iU13\n-----END PGP SIGNATURE-----\n"},{"id":"206224","messageId":"50EAD0FA.4050401@gmail.com","threadId":"32432","inReplyTo":"E59706EF8DB1D147B15BECA3322E4BDC0681FA@eusaamb103.ericsson.se","subject":"Re: [PATCH v4] git-completion.bash: add support for path completion","fromName":"Manlio Perillo","fromEmail":"manlio.perillo@gmail.com","sentAt":"2013-01-07T13:43:22Z","receivedAt":"2013-01-07T13:43:22Z","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 05/01/2013 21:23, Marc Khouzam ha scritto:\n> [...]\n> Below are two suggestions that are in line with this effort but that are not regressions.\n> \n> A) It would be nice if \n> git commit -a <TAB>\n> also completed with untracked files\n> \n\n$ git commit -a foo\nfatal: Paths with -a does not make sense.\n\nSo\n  git commit -a <TAB>\n\nshould not suggest untracked files; instead it should suggest nothing.\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\niEYEARECAAYFAlDq0PoACgkQscQJ24LbaUSTNwCfWt7a1Tdg9u5sd6B3FXCEFj1/\nsBwAoIv4B2y4MUQgLNafY2PTWx4giSfD\n=tb3O\n-----END PGP SIGNATURE-----\n"},{"id":"206227","messageId":"E59706EF8DB1D147B15BECA3322E4BDC068EE8@eusaamb103.ericsson.se","threadId":"32432","inReplyTo":"50EAD0FA.4050401@gmail.com","subject":"RE: [PATCH v4] git-completion.bash: add support for path completion","fromName":"Marc Khouzam","fromEmail":"marc.khouzam@ericsson.com","sentAt":"2013-01-07T15:26:26Z","receivedAt":"2013-01-07T15:26:26Z","isPatch":true,"sender":{"key":"marc.khouzam@ericsson.com","avatar":"https://gravatar.com/avatar/de564e23ad14e2945f9f1cdb4d0227c935b5b54c39576a304d47caa3e23dcd33?d=mp&s=160"},"body":"\n> -----Original Message-----\n> From: git-owner@vger.kernel.org \n> [mailto:git-owner@vger.kernel.org] On Behalf Of Manlio Perillo\n> Sent: Monday, January 07, 2013 8:43 AM\n> To: Marc Khouzam\n> Cc: Junio C Hamano; git@vger.kernel.org; szeder@ira.uka.de; \n> felipe.contreras@gmail.com\n> Subject: Re: [PATCH v4] git-completion.bash: add support for \n> path completion\n> \n> -----BEGIN PGP SIGNED MESSAGE-----\n> Hash: SHA1\n> \n> Il 05/01/2013 21:23, Marc Khouzam ha scritto:\n> > [...]\n> > Below are two suggestions that are in line with this effort \n> but that are not regressions.\n> > \n> > A) It would be nice if \n> > git commit -a <TAB>\n> > also completed with untracked files\n> > \n> \n> $ git commit -a foo\n> fatal: Paths with -a does not make sense.\n> \n> So\n>   git commit -a <TAB>\n> \n> should not suggest untracked files; instead it should suggest nothing.\n\nYou are right, I was confused.\n\ngit commit --all <TAB>\n\nshould also suggest nothing then.\n\nThanks\n\nMarc"},{"id":"206313","messageId":"50EC5D41.6030209@gmail.com","threadId":"32432","inReplyTo":"E59706EF8DB1D147B15BECA3322E4BDC0681FA@eusaamb103.ericsson.se","subject":"Re: [PATCH v4] git-completion.bash: add support for path completion","fromName":"Manlio Perillo","fromEmail":"manlio.perillo@gmail.com","sentAt":"2013-01-08T17:54:09Z","receivedAt":"2013-01-08T17:54:09Z","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 05/01/2013 21:23, Marc Khouzam ha scritto:\n> [...]\n> 4- Completion choices include their entire path, which is not what bash does by default.  For example:\n>> cd git/contrib\n>> ls completion/git-<tab>\n> git-completion.bash  git-completion.tcsh  git-completion.zsh   git-prompt.sh\n> but\n>> git rm completion/git-<tab>\n> completion/git-completion.bash  completion/git-completion.tcsh  completion/git-completion.zsh   completion/git-prompt.sh\n> notice the extra 'completion/' before each completion.  This can get pretty large when completing with \n> many directory prefixes.  The current tcsh completion has the same problem which I couldn't fix.  However, I am \n> not sure if it can be fixed for bash.\n> \n> I personally don't think this is regression, just an slight annoyance.\n> \n\nAfter some searching, I found how this is supposed to be done.\nIt is possible to use the -o filenames option to tell Bash completion\nthat \"the compspec generates filenames, so it can perform any\nfilename-specific processing\".\n\nUnfortunately this option must be passed to the complete builtin\ncommand, and we can not do this, since the comspec not always contains\nfilenames.\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\niEYEARECAAYFAlDsXUEACgkQscQJ24LbaURMlgCdEyeSRTRktKtGuDxq4HX1meWt\nIV4AmwS6wasCip+1u4vS2FwG8AlXXB7r\n=pN8F\n-----END PGP SIGNATURE-----\n"},{"id":"206315","messageId":"20130108180518.GO6440@serenity.lan","threadId":"32432","inReplyTo":"50EC5D41.6030209@gmail.com","subject":"Re: [PATCH v4] git-completion.bash: add support for path completion","fromName":"John Keeping","fromEmail":"john@keeping.me.uk","sentAt":"2013-01-08T18:05:18Z","receivedAt":"2013-01-08T18:05:18Z","isPatch":true,"sender":{"key":"john@keeping.me.uk","avatar":"https://avatars.githubusercontent.com/u/1702081?v=4"},"body":"On Tue, Jan 08, 2013 at 06:54:09PM +0100, Manlio Perillo wrote:\n> -----BEGIN PGP SIGNED MESSAGE-----\n> Hash: SHA1\n> \n> Il 05/01/2013 21:23, Marc Khouzam ha scritto:\n>> [...]\n>> 4- Completion choices include their entire path, which is not what bash does by default.  For example:\n>>> cd git/contrib\n>>> ls completion/git-<tab>\n>> git-completion.bash  git-completion.tcsh  git-completion.zsh   git-prompt.sh\n>> but\n>>> git rm completion/git-<tab>\n>> completion/git-completion.bash  completion/git-completion.tcsh  completion/git-completion.zsh   completion/git-prompt.sh\n>> notice the extra 'completion/' before each completion.  This can get pretty large when completing with \n>> many directory prefixes.  The current tcsh completion has the same problem which I couldn't fix.  However, I am \n>> not sure if it can be fixed for bash.\n>> \n>> I personally don't think this is regression, just an slight annoyance.\n>> \n> \n> After some searching, I found how this is supposed to be done.\n> It is possible to use the -o filenames option to tell Bash completion\n> that \"the compspec generates filenames, so it can perform any\n> filename-specific processing\".\n> \n> Unfortunately this option must be passed to the complete builtin\n> command, and we can not do this, since the comspec not always contains\n> filenames.\n\nYou should also be able to pass it to 'compopt' during completion in\norder to change the behaviour for only the current completion.\n\n\nJohn\n"},{"id":"206317","messageId":"50EC6558.6080608@gmail.com","threadId":"32432","inReplyTo":"20130108180518.GO6440@serenity.lan","subject":"Re: [PATCH v4] git-completion.bash: add support for path completion","fromName":"Manlio Perillo","fromEmail":"manlio.perillo@gmail.com","sentAt":"2013-01-08T18:28:40Z","receivedAt":"2013-01-08T18:28:40Z","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 08/01/2013 19:05, John Keeping ha scritto:\n> [...]\n>>\n>> After some searching, I found how this is supposed to be done.\n>> It is possible to use the -o filenames option to tell Bash completion\n>> that \"the compspec generates filenames, so it can perform any\n>> filename-specific processing\".\n>>\n>> Unfortunately this option must be passed to the complete builtin\n>> command, and we can not do this, since the comspec not always contains\n>> filenames.\n> \n> You should also be able to pass it to 'compopt' during completion in\n> order to change the behaviour for only the current completion.\n> \n\nThanks, compopt is what I wanted.\n\nI was reading an old Bash manual (for Bash 3.1), and compopt is only\navailable starting from Bash 4.0.\n\nI will do some test, being careful to not break the code for Bash < 4.0\nand the other supported shells.\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\niEYEARECAAYFAlDsZVgACgkQscQJ24LbaUQlAACdGbhOuGICCYFwkRTPJla+3JGT\nEcQAoINEGvdwtOz1QFbAA4FqoI3c7VSa\n=5Oqw\n-----END PGP SIGNATURE-----\n"}]}