]> git.ipfire.org Git - thirdparty/git.git/blobdiff - contrib/completion/git-completion.bash
completion: add __gitcomp_nl tests
[thirdparty/git.git] / contrib / completion / git-completion.bash
index 93eba467502282db2697e1cf6c93a6909d35ee5c..f7e9a56528590eeb1cb8d7650a5f910cd81288da 100644 (file)
@@ -195,6 +195,11 @@ _get_comp_words_by_ref ()
 }
 fi
 
+__gitcompadd ()
+{
+       COMPREPLY=($(compgen -W "$1" -P "$2" -S "$4" -- "$3"))
+}
+
 # Generates completion reply with compgen, appending a space to possible
 # completion words, if necessary.
 # It accepts 1 to 4 arguments:
@@ -208,13 +213,10 @@ __gitcomp ()
 
        case "$cur_" in
        --*=)
-               COMPREPLY=()
                ;;
        *)
                local IFS=$'\n'
-               COMPREPLY=($(compgen -P "${2-}" \
-                       -W "$(__gitcomp_1 "${1-}" "${4-}")" \
-                       -- "$cur_"))
+               __gitcompadd "$(__gitcomp_1 "${1-}" "${4-}")" "${2-}" "$cur_" ""
                ;;
        esac
 }
@@ -231,7 +233,7 @@ __gitcomp ()
 __gitcomp_nl ()
 {
        local IFS=$'\n'
-       COMPREPLY=($(compgen -P "${2-}" -S "${4- }" -W "$1" -- "${3-$cur}"))
+       __gitcompadd "$1" "${2-}" "${3-$cur}" "${4- }"
 }
 
 # Generates completion reply with compgen from newline-separated possible
@@ -614,7 +616,6 @@ __git_complete_remote_or_refspec ()
                        case "$cmd" in
                        push) no_complete_refspec=1 ;;
                        fetch)
-                               COMPREPLY=()
                                return
                                ;;
                        *) ;;
@@ -630,7 +631,6 @@ __git_complete_remote_or_refspec ()
                return
        fi
        if [ $no_complete_refspec = 1 ]; then
-               COMPREPLY=()
                return
        fi
        [ "$remote" = "." ] && remote=
@@ -951,7 +951,6 @@ _git_am ()
                        "
                return
        esac
-       COMPREPLY=()
 }
 
 _git_apply ()
@@ -971,7 +970,6 @@ _git_apply ()
                        "
                return
        esac
-       COMPREPLY=()
 }
 
 _git_add ()
@@ -1031,7 +1029,6 @@ _git_bisect ()
                __gitcomp_nl "$(__git_refs)"
                ;;
        *)
-               COMPREPLY=()
                ;;
        esac
 }
@@ -1124,9 +1121,14 @@ _git_cherry ()
 
 _git_cherry_pick ()
 {
+       local dir="$(__gitdir)"
+       if [ -f "$dir"/CHERRY_PICK_HEAD ]; then
+               __gitcomp "--continue --quit --abort"
+               return
+       fi
        case "$cur" in
        --*)
-               __gitcomp "--edit --no-commit"
+               __gitcomp "--edit --no-commit --signoff --strategy= --mainline"
                ;;
        *)
                __gitcomp_nl "$(__git_refs)"
@@ -1170,7 +1172,6 @@ _git_clone ()
                return
                ;;
        esac
-       COMPREPLY=()
 }
 
 _git_commit ()
@@ -1354,7 +1355,6 @@ _git_fsck ()
                return
                ;;
        esac
-       COMPREPLY=()
 }
 
 _git_gc ()
@@ -1365,7 +1365,6 @@ _git_gc ()
                return
                ;;
        esac
-       COMPREPLY=()
 }
 
 _git_gitk ()
@@ -1442,7 +1441,6 @@ _git_init ()
                return
                ;;
        esac
-       COMPREPLY=()
 }
 
 _git_ls_files ()
@@ -1578,7 +1576,6 @@ _git_mergetool ()
                return
                ;;
        esac
-       COMPREPLY=()
 }
 
 _git_merge_base ()
@@ -1831,7 +1828,7 @@ _git_config ()
                local remote="${prev#remote.}"
                remote="${remote%.fetch}"
                if [ -z "$cur" ]; then
-                       COMPREPLY=("refs/heads/")
+                       __gitcompadd "refs/heads/" "" "" ""
                        return
                fi
                __gitcomp_nl "$(__git_refs_remotes "$remote")"
@@ -1891,7 +1888,6 @@ _git_config ()
                return
                ;;
        *.*)
-               COMPREPLY=()
                return
                ;;
        esac
@@ -2272,7 +2268,6 @@ _git_remote ()
                __gitcomp "$c"
                ;;
        *)
-               COMPREPLY=()
                ;;
        esac
 }
@@ -2388,8 +2383,6 @@ _git_stash ()
                *)
                        if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
                                __gitcomp "$subcommands"
-                       else
-                               COMPREPLY=()
                        fi
                        ;;
                esac
@@ -2402,14 +2395,12 @@ _git_stash ()
                        __gitcomp "--index --quiet"
                        ;;
                show,--*|drop,--*|branch,--*)
-                       COMPREPLY=()
                        ;;
                show,*|apply,*|drop,*|pop,*|branch,*)
                        __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \
                                        | sed -n -e 's/:.*//p')"
                        ;;
                *)
-                       COMPREPLY=()
                        ;;
                esac
        fi
@@ -2419,7 +2410,7 @@ _git_submodule ()
 {
        __git_has_doubledash && return
 
-       local subcommands="add status init update summary foreach sync"
+       local subcommands="add status init deinit update summary foreach sync"
        if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
                case "$cur" in
                --*)
@@ -2526,7 +2517,6 @@ _git_svn ()
                        __gitcomp "--revision= --parent"
                        ;;
                *)
-                       COMPREPLY=()
                        ;;
                esac
        fi
@@ -2551,13 +2541,10 @@ _git_tag ()
 
        case "$prev" in
        -m|-F)
-               COMPREPLY=()
                ;;
        -*|tag)
                if [ $f = 1 ]; then
                        __gitcomp_nl "$(__git_tags)"
-               else
-                       COMPREPLY=()
                fi
                ;;
        *)