completion: load completion file for external subcommand
[gitweb.git] / contrib / completion / git-completion.bash
index 6da95b8095d9a18694f6a3cda139fe4ba832f4ee..604ba2b039a240ea868fdb2e4667055e607ad181 100644 (file)
@@ -280,6 +280,10 @@ __gitcomp ()
        esac
 }
 
+# Clear the variables caching builtins' options when (re-)sourcing
+# the completion script.
+unset $(set |sed -ne 's/^\(__gitcomp_builtin_[a-zA-Z0-9_][a-zA-Z0-9_]*\)=.*/\1/p') 2>/dev/null
+
 # This function is equivalent to
 #
 #    __gitcomp "$(git xxx --git-completion-helper) ..."
@@ -2967,7 +2971,7 @@ _git_tag ()
        while [ $c -lt $cword ]; do
                i="${words[c]}"
                case "$i" in
-               -d|-v)
+               -d|--delete|-v|--verify)
                        __gitcomp_direct "$(__git_tags "" "$cur" " ")"
                        return
                        ;;
@@ -3092,12 +3096,22 @@ __git_main ()
        fi
 
        local completion_func="_git_${command//-/_}"
+       if ! declare -f $completion_func >/dev/null 2>/dev/null &&
+               declare -f _completion_loader >/dev/null 2>/dev/null
+       then
+               _completion_loader "git-$command"
+       fi
        declare -f $completion_func >/dev/null 2>/dev/null && $completion_func && return
 
        local expansion=$(__git_aliased_command "$command")
        if [ -n "$expansion" ]; then
                words[1]=$expansion
                completion_func="_git_${expansion//-/_}"
+               if ! declare -f $completion_func >/dev/null 2>/dev/null &&
+                       declare -f _completion_loader >/dev/null 2>/dev/null
+               then
+                       _completion_loader "git-$expansion"
+               fi
                declare -f $completion_func >/dev/null 2>/dev/null && $completion_func
        fi
 }