Re: [PATCH v2 2/2] completion: checkout: complete paths when ref given
From: Cornelius Weig <hidden>
Date: 2017-02-15 10:47:00
Subsystem:
the rest · Maintainer:
Linus Torvalds
Although I'm not convinced that completion of modified files is unnecessary, I'm at least persuaded that not all users would welcome such a change. Given the hint from Gabor that Alt-/ forces filesystem completion, there is even no big win in stopping to offer further refnames after one has already been given. If you think that this would be desirable, find a revised version below. Otherwise drop it. On 02/15/2017 04:11 AM, SZEDER Gábor wrote:
On Tue, Feb 14, 2017 at 10:24 PM, [off-list ref] wrote:quoted
From: Cornelius Weig <redacted> Note that one corner-case is not covered by the current implementation: if a refname contains a ':' and is followed by '--' the completion would not recognize the valid refname.I'm not sure what you mean here. Refnames can't contain ':'.
Yes, my bad. I was confusing it with the case where filename and ref name are identical.
quoted
+ while [ $c -lt $cword ]; do + i="${words[c]}" + case "$i" in + --) seen_double_dash=1 ;; + -*|?*:*) ;; + *) ref="$i"; break ;;I haven't tried it, but this would trigger on e.g. 'git checkout -b new-feature <TAB>', wouldn't it?
Correct, good eyes.
What about $ echo "unintentional change" >>tracked-file && git add -u $ git rm important-file $ git checkout HEAD <TAB> ? It seems it will offer neither 'tracked-file' nor 'important-file', but I think it should offer both.
Ideally yes. The latter of the two would also not work with Alt/. ------------------------------------------------------------------- From d0e0c9af8a30dec479c393ae7fe75205c9b3b229 Mon Sep 17 00:00:00 2001 From: Cornelius Weig <redacted> Date: Tue, 14 Feb 2017 21:01:45 +0100 Subject: [PATCH] completion: checkout: complete paths when ref given Git-checkout completes words starting with '--' as options and other words as refs. Even after specifying a ref, further words not starting with '--' are completed as refs, which is invalid for git-checkout. With this commit completion suppresses refname suggestion after finding what looks like a refname. Words before a '--' not starting with a '-' and containing no ':' are considered to be refnames. Signed-off-by: Cornelius Weig <redacted> --- contrib/completion/git-completion.bash | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 6c6e1c774d..42e6463b67 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash@@ -1059,7 +1059,16 @@ _git_bundle () _git_checkout () { - __git_has_doubledash && return + local c=2 seen_ref="" + while [ $c -lt $cword ]; do + case "${words[c]}" in + --) return ;; + -b|-B|--orphan|--branch) ((c++)) ;; + -*|*:*) ;; + *) seen_ref="y" ;; + esac + ((c++)) + done case "$cur" in --conflict=*)
@@ -1072,13 +1081,16 @@ _git_checkout () " ;; *) - # check if --track, --no-track, or --no-guess was specified - # if so, disable DWIM mode - local flags="--track --no-track --no-guess" track=1 - if [ -n "$(__git_find_on_cmdline "$flags")" ]; then - track='' + if [ -z "$seen_ref" ] + then + # check for --track, --no-track, or --no-guess + # if so, disable DWIM mode + local flags="--track --no-track --no-guess" track=1 + if [ -n "$(__git_find_on_cmdline "$flags")" ]; then + track='' + fi + __gitcomp_nl "$(__git_refs '' $track)" fi - __gitcomp_nl "$(__git_refs '' $track)" ;; esac }
--
2.11.1