completion: fix completion of git <TAB><TAB>
PATCH 1/2 completion: fix completion of git <TAB><TAB>
After commit 511a3fc (wrap git's main usage string., 2009-09-12), the bash completion for git commands includes COMMAND and [ARGS] when it shouldn't. Fix this by grepping more strictly for a line with git commands. It's doubtful whether git will ever have commands starting with anything besides numbers and letters so this should be fine. At least by being stricter we'll know when we break the completion earlier.
---
contrib/completion/git-completion.bash | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
contrib/completion/git-completion.bash +1 -1
@@ -496,7 +496,7 @@ __git_all_commands () return fi local i IFS=" "$'\n' - for i in $(git help -a|egrep '^ ') + for i in $(git help -a|egrep '^ [a-zA-Z0-9]') do case $i in *--*) : helper pattern;;
Signature · 1 line
1.6.5.rc3
PATCH v2 2/2 completion: fix alias listings with newlines
Aliases with newlines have been a problem since commit 56fc25f (Bash completion support for remotes in .git/config., 2006-11-05). The chance of the problem occurring has been slim at best, until commit 518ef8f (completion: Replace config --list with --get-regexp, 2009-09-11) removed the case statement introduced by commit 56fc25f. Before removing the case statement, most aliases with newlines would work unless they were specially crafted as follows
[alias]
foo = "log -1 --pretty='format:%s\nalias.error=broken'"
After removing the case statement, a more benign alias like
[alias]
whowhat = "log -1 --pretty='format:%an <%ae>\n%s'" wont-complete = ...
would cause the completion to break badly.
For now, revert the removal of the case statement until someone comes up with a better way to get keys from git-config.
---
This is an alternate fix to my previous 1/3 patch.
Hannes has convinced me to go this route. I don't really see a problem, it basically reverts to broken behavior that nobody's complained about in 3 years. At least it's less broken?
contrib/completion/git-completion.bash | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-)
contrib/completion/git-completion.bash +6 -2
@@ -602,8 +602,12 @@ __git_aliases () { local i IFS=$'\n' for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do - i="${i#alias.}" - echo "${i/ */}" + case "$i" in + alias.*) + i="${i#alias.}" + echo "${i/ */}" + ;; + esac done }
Signature · 1 line
1.6.5.rc3
Re: [PATCHv2 2/2] completion: fix alias listings with newlines
Quoted 7 lines · Stephen Boyd
Aliases with newlines have been a problem since commit 56fc25f (Bash completion support for remotes in .git/config., 2006-11-05). The chance of the problem occurring has been slim at best, until commit 518ef8f (completion: Replace config --list with --get-regexp, 2009-09-11) removed the case statement introduced by commit 56fc25f. Before removing the case statement, most aliases with newlines would work unless they were specially crafted as follows
...
Quoted 3 lines
Hannes has convinced me to go this route. I don't really see a problem, it basically reverts to broken behavior that nobody's complained about in 3 years. At least it's less broken?
Yay. Given that we have no better solution easily available, I like the idea of just reverting to the behavior we have had for the past 3 years. Thanks.
Signature · 1 line
Shawn.
Quoted 8 lines · Stephen Boyd
After commit 511a3fc (wrap git's main usage string., 2009-09-12), the bash completion for git commands includes COMMAND and [ARGS] when it shouldn't. Fix this by grepping more strictly for a line with git commands. It's doubtful whether git will ever have commands starting with anything besides numbers and letters so this should be fine. At least by being stricter we'll know when we break the completion earlier.
Signed-off-by Stephen Boyd <[email protected]>
Signature · 1 line
Shawn.