completion: load completion file for external subcommand
[gitweb.git] / contrib / completion / git-completion.bash
index 37bf4a64d390d5d3ea7a3fea4ea3cd4ad4e3cf11..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) ..."
@@ -472,7 +476,7 @@ __git_refs ()
                        track=""
                        ;;
                *)
-                       for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
+                       for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD; do
                                case "$i" in
                                $match*)
                                        if [ -e "$dir/$i" ]; then
@@ -627,7 +631,7 @@ __git_is_configured_remote ()
 
 __git_list_merge_strategies ()
 {
-       git merge -s help 2>&1 |
+       LANG=C LC_ALL=C git merge -s help 2>&1 |
        sed -n -e '/[Aa]vailable strategies are: /,/^$/{
                s/\.$//
                s/.*://
@@ -1105,7 +1109,7 @@ __git_count_arguments ()
 }
 
 __git_whitespacelist="nowarn warn error error-all fix"
-__git_am_inprogress_options="--skip --continue --resolved --abort"
+__git_am_inprogress_options="--skip --continue --resolved --abort --quit --show-current-patch"
 
 _git_am ()
 {
@@ -1815,7 +1819,7 @@ _git_name_rev ()
 
 _git_notes ()
 {
-       local subcommands='add append copy edit list prune remove show'
+       local subcommands='add append copy edit get-ref list merge prune remove show'
        local subcommand="$(__git_find_on_cmdline "$subcommands")"
 
        case "$subcommand,$cur" in
@@ -1832,14 +1836,13 @@ _git_notes ()
                        ;;
                esac
                ;;
-       add,--reuse-message=*|append,--reuse-message=*|\
-       add,--reedit-message=*|append,--reedit-message=*)
+       *,--reuse-message=*|*,--reedit-message=*)
                __git_complete_refs --cur="${cur#*=}"
                ;;
        *,--*)
                __gitcomp_builtin notes_$subcommand
                ;;
-       prune,*)
+       prune,*|get-ref,*)
                # this command does not take a ref, do not complete it
                ;;
        *)
@@ -1930,11 +1933,11 @@ _git_rebase ()
 {
        __git_find_repo_path
        if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
-               __gitcomp "--continue --skip --abort --quit --edit-todo"
+               __gitcomp "--continue --skip --abort --quit --edit-todo --show-current-patch"
                return
        elif [ -d "$__git_repo_path"/rebase-apply ] || \
             [ -d "$__git_repo_path"/rebase-merge ]; then
-               __gitcomp "--continue --skip --abort --quit"
+               __gitcomp "--continue --skip --abort --quit --show-current-patch"
                return
        fi
        __git_complete_strategy && return
@@ -2020,7 +2023,7 @@ _git_send_email ()
                        --compose --confirm= --dry-run --envelope-sender
                        --from --identity
                        --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
-                       --no-suppress-from --no-thread --quiet
+                       --no-suppress-from --no-thread --quiet --reply-to
                        --signed-off-by-cc --smtp-pass --smtp-server
                        --smtp-server-port --smtp-encryption= --smtp-user
                        --subject --suppress-cc= --suppress-from --thread --to
@@ -2968,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
                        ;;
@@ -3006,7 +3009,7 @@ _git_whatchanged ()
 
 _git_worktree ()
 {
-       local subcommands="add list lock prune unlock"
+       local subcommands="add list lock move prune remove unlock"
        local subcommand="$(__git_find_on_cmdline "$subcommands")"
        if [ -z "$subcommand" ]; then
                __gitcomp "$subcommands"
@@ -3024,6 +3027,9 @@ _git_worktree ()
                prune,--*)
                        __gitcomp_builtin worktree_prune
                        ;;
+               remove,--*)
+                       __gitcomp "--force"
+                       ;;
                *)
                        ;;
                esac
@@ -3090,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
 }