]> git.ipfire.org Git - thirdparty/git.git/blobdiff - contrib/completion/git-completion.bash
completion: perform DWIM logic directly in __git_complete_refs
[thirdparty/git.git] / contrib / completion / git-completion.bash
index 1feb5165cff807793883808f5c7eb0c528ff1d7c..fb50b4d0755ae12c288dd8c93f5826617437a5e0 100644 (file)
@@ -301,6 +301,19 @@ __gitcomp_direct ()
        COMPREPLY=($1)
 }
 
+# Similar to __gitcomp_direct, but appends to COMPREPLY instead.
+# Callers must take care of providing only words that match the current word
+# to be completed and adding any prefix and/or suffix (trailing space!), if
+# necessary.
+# 1: List of newline-separated matching completion words, complete with
+#    prefix and suffix.
+__gitcomp_direct_append ()
+{
+       local IFS=$'\n'
+
+       COMPREPLY+=($1)
+}
+
 __gitcompappend ()
 {
        local x i=${#COMPREPLY[@]}
@@ -787,7 +800,11 @@ __git_complete_refs ()
                shift
        done
 
-       __gitcomp_direct "$(__git_refs "$remote" "$dwim" "$pfx" "$cur_" "$sfx")"
+       __gitcomp_direct "$(__git_refs "$remote" "" "$pfx" "$cur_" "$sfx")"
+
+       if [ "$dwim" = "yes" ]; then
+               __gitcomp_direct_append "$(__git_dwim_remote_heads "$pfx" "$cur_" "$sfx")"
+       fi
 }
 
 # __git_refs2 requires 1 argument (to pass to __git_refs)