{"thread":{"id":"16499","subject":"[PATCH] bash: complete full refs","startedAt":"2008-11-27T13:35:47Z","lastAt":"2008-11-28T00:51:36Z","messageCount":4,"participants":["SZEDER Gábor","Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"96621","messageId":"1227792947-4055-1-git-send-email-szeder@ira.uka.de","threadId":"16499","inReplyTo":null,"subject":"[PATCH] bash: complete full refs","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2008-11-27T13:35:47Z","receivedAt":"2008-11-27T13:35:47Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Sometimes it's handy to complete full refs, e.g. the user has some\nrefs outside of refs/{heads,remotes,tags} or the user wants to\ncomplete some git command's special refs (like 'git show\nrefs/bisect/bad').\n\nTo do that, we check whether the ref to be completed starts with\n'refs'.  If it does, then we offer full refs for completion; otherwise\neverything works as usual.\n\nThis way the impact on the common case is fairly small (hopefully not\nmany users have branches or tags starting with 'refs'), and in the\nspecial case the cost of typing out 'refs' is bearable.\n\nWhile at it, also remove the unused 'cmd' variable from '__git_refs'.\n\nSigned-off-by: SZEDER Gábor <szeder@ira.uka.de>\n---\n contrib/completion/git-completion.bash |   19 +++++++++++++++----\n 1 files changed, 15 insertions(+), 4 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 0ee071b..39bf18b 100755\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -188,11 +188,22 @@ __git_tags ()\n \n __git_refs ()\n {\n-\tlocal cmd i is_hash=y dir=\"$(__gitdir \"$1\")\"\n+\tlocal i is_hash=y dir=\"$(__gitdir \"$1\")\"\n+\tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\" format refs\n \tif [ -d \"$dir\" ]; then\n-\t\tif [ -e \"$dir/HEAD\" ]; then echo HEAD; fi\n-\t\tgit --git-dir=\"$dir\" for-each-ref --format='%(refname:short)' \\\n-\t\t\trefs/tags refs/heads refs/remotes\n+\t\tcase \"$cur\" in\n+\t\trefs*)\n+\t\t\tformat=\"refname\"\n+\t\t\trefs=\"${cur%/*}\"\n+\t\t\t;;\n+\t\t*)\n+\t\t\tif [ -e \"$dir/HEAD\" ]; then echo HEAD; fi\n+\t\t\tformat=\"refname:short\"\n+\t\t\trefs=\"refs/tags refs/heads refs/remotes\"\n+\t\t\t;;\n+\t\tesac\n+\t\tgit --git-dir=\"$dir\" for-each-ref --format=\"%($format)\" \\\n+\t\t\t$refs\n \t\treturn\n \tfi\n \tfor i in $(git ls-remote \"$dir\" 2>/dev/null); do\n-- \n1.6.0.4.814.gfe502\n"},{"id":"96649","messageId":"20081127212938.GB23984@spearce.org","threadId":"16499","inReplyTo":"1227792947-4055-1-git-send-email-szeder@ira.uka.de","subject":"Re: [PATCH] bash: complete full refs","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-11-27T21:29:38Z","receivedAt":"2008-11-27T21:29:38Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"SZEDER GGGbor <szeder@ira.uka.de> wrote:\n> Sometimes it's handy to complete full refs, [...]\n> \n> To do that, we check whether the ref to be completed starts with\n> 'refs'.\n...\n> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n> index 0ee071b..39bf18b 100755\n> --- a/contrib/completion/git-completion.bash\n> +++ b/contrib/completion/git-completion.bash\n> @@ -188,11 +188,22 @@ __git_tags ()\n>  \n>  __git_refs ()\n>  {\n> -\tlocal cmd i is_hash=y dir=\"$(__gitdir \"$1\")\"\n> +\tlocal i is_hash=y dir=\"$(__gitdir \"$1\")\"\n> +\tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\" format refs\n>  \tif [ -d \"$dir\" ]; then\n> -\t\tif [ -e \"$dir/HEAD\" ]; then echo HEAD; fi\n> -\t\tgit --git-dir=\"$dir\" for-each-ref --format='%(refname:short)' \\\n> -\t\t\trefs/tags refs/heads refs/remotes\n> +\t\tcase \"$cur\" in\n> +\t\trefs*)\n\nI wonder if the pattern shouldn't be:\n\n\trefs|refs/*)\n\nto reduce the risk of matching \"refs-\" and trying to do a full ref\nmatch instead of a short ref match.\n\nOtherwise,\n\nAcked-by: Shawn O. Pearce <spearce@spearce.org>\n\n-- \nShawn.\n"},{"id":"96662","messageId":"20081128004638.GA6854@neumann","threadId":"16499","inReplyTo":"20081127212938.GB23984@spearce.org","subject":"[PATCH] bash: complete full refs","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2008-11-28T00:46:38Z","receivedAt":"2008-11-28T00:46:38Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Sometimes it's handy to complete full refs, e.g. the user has some\nrefs outside of refs/{heads,remotes,tags} or the user wants to\ncomplete some git command's special refs (like 'git show\nrefs/bisect/bad').\n\nTo do that, we check whether the ref to be completed starts with\n'refs/' or is 'refs' (to reduce the risk of matching 'refs-').  If it\ndoes, then we offer full refs for completion; otherwise everything\nworks as usual.\n\nThis way the impact on the common case is fairly small (hopefully not\nmany users have branches or tags starting with 'refs'), and in the\nspecial case the cost of typing out 'refs' is bearable.\n\nWhile at it, also remove the unused 'cmd' variable from '__git_refs'.\n\nSigned-off-by: SZEDER Gábor <szeder@ira.uka.de>\n---\n\nOn Thu, Nov 27, 2008 at 01:29:38PM -0800, Shawn O. Pearce wrote:\n> I wonder if the pattern shouldn't be:\n> \n> \trefs|refs/*)\n> \n> to reduce the risk of matching \"refs-\" and trying to do a full ref\n> match instead of a short ref match.\nGood point.  Adjusted the code and commit message accordingly.\n\n\n contrib/completion/git-completion.bash |   19 +++++++++++++++----\n 1 files changed, 15 insertions(+), 4 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 0ee071b..244ed41 100755\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -188,11 +188,22 @@ __git_tags ()\n \n __git_refs ()\n {\n-\tlocal cmd i is_hash=y dir=\"$(__gitdir \"$1\")\"\n+\tlocal i is_hash=y dir=\"$(__gitdir \"$1\")\"\n+\tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\" format refs\n \tif [ -d \"$dir\" ]; then\n-\t\tif [ -e \"$dir/HEAD\" ]; then echo HEAD; fi\n-\t\tgit --git-dir=\"$dir\" for-each-ref --format='%(refname:short)' \\\n-\t\t\trefs/tags refs/heads refs/remotes\n+\t\tcase \"$cur\" in\n+\t\trefs|refs/*)\n+\t\t\tformat=\"refname\"\n+\t\t\trefs=\"${cur%/*}\"\n+\t\t\t;;\n+\t\t*)\n+\t\t\tif [ -e \"$dir/HEAD\" ]; then echo HEAD; fi\n+\t\t\tformat=\"refname:short\"\n+\t\t\trefs=\"refs/tags refs/heads refs/remotes\"\n+\t\t\t;;\n+\t\tesac\n+\t\tgit --git-dir=\"$dir\" for-each-ref --format=\"%($format)\" \\\n+\t\t\t$refs\n \t\treturn\n \tfi\n \tfor i in $(git ls-remote \"$dir\" 2>/dev/null); do\n-- \n1.6.0.4.814.gfe502\n"},{"id":"96661","messageId":"20081128005136.GE23984@spearce.org","threadId":"16499","inReplyTo":"20081128004638.GA6854@neumann","subject":"Re: [PATCH] bash: complete full refs","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-11-28T00:51:36Z","receivedAt":"2008-11-28T00:51:36Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"SZEDER GGGbor <szeder@ira.uka.de> wrote:\n> Sometimes it's handy to complete full refs, e.g. the user has some\n> refs outside of refs/{heads,remotes,tags} or the user wants to\n> complete some git command's special refs (like 'git show\n> refs/bisect/bad').\n...\n> On Thu, Nov 27, 2008 at 01:29:38PM -0800, Shawn O. Pearce wrote:\n> > I wonder if the pattern shouldn't be:\n> > \n> > \trefs|refs/*)\n> > \n> > to reduce the risk of matching \"refs-\" and trying to do a full ref\n> > match instead of a short ref match.\n> Good point.  Adjusted the code and commit message accordingly.\n\nThanks.\n\nAcked-by: Shawn O. Pearce <spearce@spearce.org>\n\n \n>  contrib/completion/git-completion.bash |   19 +++++++++++++++----\n>  1 files changed, 15 insertions(+), 4 deletions(-)\n> \n> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n> index 0ee071b..244ed41 100755\n> --- a/contrib/completion/git-completion.bash\n> +++ b/contrib/completion/git-completion.bash\n> @@ -188,11 +188,22 @@ __git_tags ()\n>  \n>  __git_refs ()\n>  {\n> -\tlocal cmd i is_hash=y dir=\"$(__gitdir \"$1\")\"\n> +\tlocal i is_hash=y dir=\"$(__gitdir \"$1\")\"\n> +\tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\" format refs\n>  \tif [ -d \"$dir\" ]; then\n> -\t\tif [ -e \"$dir/HEAD\" ]; then echo HEAD; fi\n> -\t\tgit --git-dir=\"$dir\" for-each-ref --format='%(refname:short)' \\\n> -\t\t\trefs/tags refs/heads refs/remotes\n> +\t\tcase \"$cur\" in\n> +\t\trefs|refs/*)\n> +\t\t\tformat=\"refname\"\n> +\t\t\trefs=\"${cur%/*}\"\n> +\t\t\t;;\n> +\t\t*)\n> +\t\t\tif [ -e \"$dir/HEAD\" ]; then echo HEAD; fi\n> +\t\t\tformat=\"refname:short\"\n> +\t\t\trefs=\"refs/tags refs/heads refs/remotes\"\n> +\t\t\t;;\n> +\t\tesac\n> +\t\tgit --git-dir=\"$dir\" for-each-ref --format=\"%($format)\" \\\n> +\t\t\t$refs\n>  \t\treturn\n>  \tfi\n>  \tfor i in $(git ls-remote \"$dir\" 2>/dev/null); do\n> -- \n> 1.6.0.4.814.gfe502\n> \n\n-- \nShawn.\n"}]}