{"thread":{"id":"32409","subject":"[PATCH v3] git-completion.bash: add support for path completion","startedAt":"2012-12-19T18:58:16Z","lastAt":"2012-12-19T23:43:25Z","messageCount":4,"participants":["Manlio Perillo","Junio C Hamano"],"isPatch":true,"patchVersion":3,"patchTotal":null},"messages":[{"id":"205207","messageId":"1355943496-5533-1-git-send-email-manlio.perillo@gmail.com","threadId":"32409","inReplyTo":null,"subject":"[PATCH v3] git-completion.bash: add support for path completion","fromName":"Manlio Perillo","fromEmail":"manlio.perillo@gmail.com","sentAt":"2012-12-19T18:58:16Z","receivedAt":"2012-12-19T18:58:16Z","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 mv\", \"git rm\" and \"git ls-tree\"\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 commit\" command will suggest all\n  files that have been modified from the HEAD.\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 2:\n\n\t* Perl is no more used.\n\t* Fixed some coding style issues.\n\t* Refactorized code, to improve future path completion support for\n\t  the \"git reset\" command.\n\n contrib/completion/git-completion.bash | 127 ++++++++++++++++++++++++++++-----\n 1 file changed, 111 insertions(+), 16 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 0b77eb1..fc12d0f 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,58 @@ __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 path\n+\n+\twhile read -r path; do\n+\t\tpath=${path#$1}\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: A string for file index status mode (\"c\", \"m\", \"d\", \"o\"), as\n+#    supported by git ls-files command.\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\tgit --git-dir=\"$dir\" ls-files --exclude-standard \"-${1}\" \"${2}\" |\n+\t\t\t__git_index_file_list_filter ${2} | uniq\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}\" |\n+\t\t\t__git_index_file_list_filter \"${2}\" | uniq\n+\tfi\n+}\n+\n __git_heads ()\n {\n \tlocal dir=\"$(__gitdir)\"\n@@ -430,6 +483,46 @@ __git_complete_revlist_file ()\n }\n \n \n+# __git_complete_index_file requires 1 argument: the file index\n+# status mode\n+__git_complete_index_file ()\n+{\n+\tlocal pfx cur_=\"$cur\"\n+\n+\tcase \"$cur_\" in\n+\t\t?*/*)\n+\t\t\tpfx=\"${cur_%/*}\"\n+\t\t\tcur_=\"${cur_##*/}\"\n+\t\t\tpfx=\"${pfx}/\"\n+\n+\t\t\t__gitcomp_nl \"$(__git_index_files ${1} ${pfx})\" \"$pfx\" \"$cur_\" \"\"\n+\t\t\t;;\n+\t\t*)\n+\t\t\t__gitcomp_nl \"$(__git_index_files ${1})\" \"\" \"$cur_\" \"\"\n+\t\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\t?*/*)\n+\t\t\tpfx=\"${cur_%/*}\"\n+\t\t\tcur_=\"${cur_##*/}\"\n+\t\t\tpfx=\"${pfx}/\"\n+\n+\t\t\t__gitcomp_nl \"$(__git_diff_index_files ${1} ${pfx})\" \"$pfx\" \"$cur_\" \"\"\n+\t\t\t;;\n+\t\t*)\n+\t\t\t__gitcomp_nl \"$(__git_diff_index_files ${1})\" \"\" \"$cur_\" \"\"\n+\t\t\t;;\n+\tesac\n+}\n+\n __git_complete_file ()\n {\n \t__git_complete_revlist_file\n@@ -770,8 +863,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 +871,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 \"om\"\n }\n \n _git_archive ()\n@@ -930,15 +1023,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 \"o\"\n }\n \n _git_clone ()\n@@ -969,8 +1062,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@@ -997,8 +1088,10 @@ _git_commit ()\n \t\t\t--verbose --quiet --fixup= --squash=\n \t\t\t\"\n \t\treturn\n+\t\t;;\n \tesac\n-\tCOMPREPLY=()\n+\n+\t__git_complete_diff_index_file \"HEAD\"\n }\n \n _git_describe ()\n@@ -1216,8 +1309,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 +1321,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 \"c\"\n }\n \n _git_ls_remote ()\n@@ -1362,7 +1456,9 @@ _git_mv ()\n \t\treturn\n \t\t;;\n \tesac\n-\tCOMPREPLY=()\n+\n+\t# XXX needs more work\n+\t__git_complete_index_file \"c\"\n }\n \n _git_name_rev ()\n@@ -2068,15 +2164,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 \"c\"\n }\n \n _git_shortlog ()\n-- \n1.8.1.rc1.18.g9db0d25\n"},{"id":"205208","messageId":"7vzk1995mx.fsf@alter.siamese.dyndns.org","threadId":"32409","inReplyTo":"1355943496-5533-1-git-send-email-manlio.perillo@gmail.com","subject":"Re: [PATCH v3] git-completion.bash: add support for path completion","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-12-19T19:57:42Z","receivedAt":"2012-12-19T19:57:42Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"[jch: again, adding area experts to Cc]\n\nManlio Perillo <manlio.perillo@gmail.com> writes:\n\n> Changes from version 2:\n>\n> \t* Perl is no more used.\n> \t* Fixed some coding style issues.\n> \t* Refactorized code, to improve future path completion support for\n> \t  the \"git reset\" command.\n\nThanks.  Will replace what was queued on 'pu'.\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\nThe callsites that call this function, and the way the argument is\nused, do not make it look like it is an optional argument to me.\n\nAfter reading later parts of the patch, I think the callers are\nwrong (see below) and you did intend to make \"$1\" optional.\n\n> +__git_index_file_list_filter ()\n> +{\n> +\tlocal path\n> +\n> +\twhile read -r path; do\n> +\t\tpath=${path#$1}\n\nThis will work correctly only if $1 does not have any shell\nmetacharacter that removes prefix of $path that matches $1 as a\npathname expansion pattern.  As this file is for bash completion,\nusing string-oriented Bash-isms like ${#1} (to get the length of the\nprefix) and ${path:$offset} (to get substring) are perfectly fine\nway to correct it.\n\nAlso, as $1 is optional, won't this barf if it is run under \"set -u\"?\n\n> +# __git_index_files accepts 1 or 2 arguments:\n> +# 1: A string for file index status mode (\"c\", \"m\", \"d\", \"o\"), as\n> +#    supported by git ls-files command.\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\tgit --git-dir=\"$dir\" ls-files --exclude-standard \"-${1}\" \"${2}\" |\n> +\t\t\t__git_index_file_list_filter ${2} | uniq\n\nEven though everywhere else you seem to quote the variables with dq,\nbut this ${2} is not written as \"${2}\", which looks odd.  Deliberate?\n\nIf you wanted to call __git_index_file_list_filter without parameter\nwhen the caller did not give you the optional $2, then the above is\nnot the way to write it.  It would be ${2+\"$2\"}.  The upstream of\nthe pipe (ls-files) also is getting an empty string as the pathspec\nwhen $2 is omitted, and the call will break if this is run under\n\"set -u\".\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}\" |\n> +\t\t\t__git_index_file_list_filter \"${2}\" | uniq\n\nThis one, when the optional $2 is absent, will call __git_index_file_list_filter\nwith an empty string in its \"$1\".  Intended, or is it also ${2+\"$2\"}?\n\n> +# __git_complete_index_file requires 1 argument: the file index\n> +# status mode\n> +__git_complete_index_file ()\n> +{\n> +\tlocal pfx cur_=\"$cur\"\n> +\n> +\tcase \"$cur_\" in\n> +\t\t?*/*)\n> +\t\t\tpfx=\"${cur_%/*}\"\n> +\t\t\tcur_=\"${cur_##*/}\"\n> +\t\t\tpfx=\"${pfx}/\"\n> +\n> +\t\t\t__gitcomp_nl \"$(__git_index_files ${1} ${pfx})\" \"$pfx\" \"$cur_\" \"\"\n> +\t\t\t;;\n> +\t\t*)\n> +\t\t\t__gitcomp_nl \"$(__git_index_files ${1})\" \"\" \"$cur_\" \"\"\n> +\t\t\t;;\n> +\tesac\n\nPlease dedent the case arms by one level, i.e.\n\n\tcase $value in\n        $pattern1)\n        \taction1\n                ;;\n                ...\n\t\t;;\n\tesac\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\t?*/*)\n> +\t\t\tpfx=\"${cur_%/*}\"\n> +\t\t\tcur_=\"${cur_##*/}\"\n> +\t\t\tpfx=\"${pfx}/\"\n> +\n> +\t\t\t__gitcomp_nl \"$(__git_diff_index_files ${1} ${pfx})\" \"$pfx\" \"$cur_\" \"\"\n> +\t\t\t;;\n> +\t\t*)\n> +\t\t\t__gitcomp_nl \"$(__git_diff_index_files ${1})\" \"\" \"$cur_\" \"\"\n> +\t\t\t;;\n\nUnquoted $1 looks fishy, even if the only caller of this function\nalways gives \"HEAD\" to it (in which case you can do without making\nit a parameter in the first place).\n\nUnquoted ${pfx} given to __git_diff_index_files also looks fishy.\n"},{"id":"205219","messageId":"50D2377D.90100@gmail.com","threadId":"32409","inReplyTo":"7vzk1995mx.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH v3] git-completion.bash: add support for path completion","fromName":"Manlio Perillo","fromEmail":"manlio.perillo@gmail.com","sentAt":"2012-12-19T21:54:05Z","receivedAt":"2012-12-19T21:54:05Z","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 19/12/2012 20:57, Junio C Hamano ha scritto:\n> [jch: again, adding area experts to Cc]\n> \n> Manlio Perillo <manlio.perillo@gmail.com> writes:\n> \n>> Changes from version 2:\n>>\n>> \t* Perl is no more used.\n>> \t* Fixed some coding style issues.\n>> \t* Refactorized code, to improve future path completion support for\n>> \t  the \"git reset\" command.\n> \n> Thanks.  Will replace what was queued on 'pu'.\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> \n> The callsites that call this function, and the way the argument is\n> used, do not make it look like it is an optional argument to me.\n> \n> After reading later parts of the patch, I think the callers are\n> wrong (see below) and you did intend to make \"$1\" optional.\n> \n\nThanks for the corrections.\nAs you can see, I'm not very expert in bash programming.\nI will review the code to use proper escaping and correct optional\nparameters handling, based on your review.\n\nIn this case, I incorrectly assumed that bash expands ${1} to an empty\nstring, in case no arguments are passed to the function.\n\n>> +__git_index_file_list_filter ()\n>> +{\n>> +\tlocal path\n>> +\n>> +\twhile read -r path; do\n>> +\t\tpath=${path#$1}\n> \n> This will work correctly only if $1 does not have any shell\n> metacharacter that removes prefix of $path that matches $1 as a\n> pathname expansion pattern.  As this file is for bash completion,\n> using string-oriented Bash-isms like ${#1} (to get the length of the\n> prefix) and ${path:$offset} (to get substring) are perfectly fine\n> way to correct it.\n> \n\nOk.\n\n> Also, as $1 is optional, won't this barf if it is run under \"set -u\"?\n>\n\nOk.\nHere I should use ${1-}.\n\n>> +# __git_index_files accepts 1 or 2 arguments:\n>> +# 1: A string for file index status mode (\"c\", \"m\", \"d\", \"o\"), as\n>> +#    supported by git ls-files command.\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\tgit --git-dir=\"$dir\" ls-files --exclude-standard \"-${1}\" \"${2}\" |\n>> +\t\t\t__git_index_file_list_filter ${2} | uniq\n> \n> Even though everywhere else you seem to quote the variables with dq,\n> but this ${2} is not written as \"${2}\", which looks odd.  Deliberate?\n> \n\nNo, I simply missed it.\n\n> If you wanted to call __git_index_file_list_filter without parameter\n> when the caller did not give you the optional $2, then the above is\n> not the way to write it.  It would be ${2+\"$2\"}.\n\nYes, this seems the better solution.\n\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}\" |\n>> +\t\t\t__git_index_file_list_filter \"${2}\" | uniq\n> \n> This one, when the optional $2 is absent, will call __git_index_file_list_filter\n> with an empty string in its \"$1\".  Intended, or is it also ${2+\"$2\"}?\n\nNo, it was not intended. But here it should probably be ${2-}.\n\nOne possible rule is:\n    * ${n+\"$n\"} should be used by the _git_complete_xxx_file function;\n    * ${n-} should be used by the _git_xxx_file functions\n\nThe alternative is for each function to use ${n-}, or {n+\"$n\"}.\n\nBut I'm not sure.  What is the best practice in bash for optional\nparameters \"propagation\"?\n\n\n> \n>> +# __git_complete_index_file requires 1 argument: the file index\n>> +# status mode\n>> +__git_complete_index_file ()\n>> +{\n>> +\tlocal pfx cur_=\"$cur\"\n>> +\n>> +\tcase \"$cur_\" in\n>> +\t\t?*/*)\n>> +\t\t\tpfx=\"${cur_%/*}\"\n>> +\t\t\tcur_=\"${cur_##*/}\"\n>> +\t\t\tpfx=\"${pfx}/\"\n>> +\n>> +\t\t\t__gitcomp_nl \"$(__git_index_files ${1} ${pfx})\" \"$pfx\" \"$cur_\" \"\"\n>> +\t\t\t;;\n>> +\t\t*)\n>> +\t\t\t__gitcomp_nl \"$(__git_index_files ${1})\" \"\" \"$cur_\" \"\"\n>> +\t\t\t;;\n>> +\tesac\n> \n> Please dedent the case arms by one level, i.e.\n>\n\nI missed it.\nVim do not intent correctly this, and I forgot to dedent.\n\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\t?*/*)\n>> +\t\t\tpfx=\"${cur_%/*}\"\n>> +\t\t\tcur_=\"${cur_##*/}\"\n>> +\t\t\tpfx=\"${pfx}/\"\n>> +\n>> +\t\t\t__gitcomp_nl \"$(__git_diff_index_files ${1} ${pfx})\" \"$pfx\" \"$cur_\" \"\"\n>> +\t\t\t;;\n>> +\t\t*)\n>> +\t\t\t__gitcomp_nl \"$(__git_diff_index_files ${1})\" \"\" \"$cur_\" \"\"\n>> +\t\t\t;;\n> \n> Unquoted $1 looks fishy, even if the only caller of this function\n> always gives \"HEAD\" to it (in which case you can do without making\n> it a parameter in the first place).\n> \n\nCurrently it is always \"HEAD\", but in future it may contain an arbitrary\ntree-ish (for my planned \"git reset\" path completion support).\nThis is the reason why in version 3 of the patch I added this new\n__git_complete_diff_index_file function.\n\nBetter to quote it.\n\n> Unquoted ${pfx} given to __git_diff_index_files also looks fishy.\n\nI missed it.\n\n\nThanks   Manlio\n-----BEGIN PGP SIGNATURE-----\nVersion: GnuPG v1.4.10 (GNU/Linux)\nComment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/\n\niEYEARECAAYFAlDSN30ACgkQscQJ24LbaUQPRQCgkQaDyBeXjk5gMJsufGoe9FCe\nyDkAn2M4d1xRYSkF6P0lQQmENlbYiCb8\n=iml7\n-----END PGP SIGNATURE-----\n"},{"id":"205230","messageId":"50D2511D.3020705@gmail.com","threadId":"32409","inReplyTo":"7vzk1995mx.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH v3] git-completion.bash: add support for path completion","fromName":"Manlio Perillo","fromEmail":"manlio.perillo@gmail.com","sentAt":"2012-12-19T23:43:25Z","receivedAt":"2012-12-19T23:43:25Z","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 19/12/2012 20:57, Junio C Hamano ha scritto:\n> [...]\n\nI just found a serious bug with \"git commit\" path completion.\n\nWhen doing the first commit on an empty repository, completion will\ncause an error:\n\n$git commit -m init <TAB>fatal: ambiguous argument 'HEAD': unknown\nrevision or path not in the working tree.\nUse '--' to separate paths from revisions, like this:\n'git <command> [<revision>...] -- [<file>...]'\n\nThe problem is that for a newly created repository there is no HEAD.\n\nIf HEAD does not exists, code must use ls-files instead of diff-index\nto get the completion list.\n\nAnother change is to always call git commands with stderr redirected to\n/dev/null.\n\n\nBy the way, this is also a bug of current bash completion code:\n\n    $ git show does-not-exists:<TAB>fatal: Not a valid object name\n      does-not-exists\n\nI will write a patch (based on master) to fix this.\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\niEYEARECAAYFAlDSUR0ACgkQscQJ24LbaUSkRwCfVKk9JhSD4sKDFm4heAkVbN0o\nKAAAn3paTXyUiFlfY/UBpnkwiARegLsE\n=7Q5s\n-----END PGP SIGNATURE-----\n"}]}