Code

Merge branch 'maint'
[git.git] / contrib / completion / git-completion.bash
index 2edb341b570315b6ac1500775e03897a24afb23e..78189c1b7bca120d896bab7a6160da1f436b4ff1 100755 (executable)
@@ -349,14 +349,32 @@ __git_complete_revlist ()
        esac
 }
 
-__git_commands ()
+__git_all_commands ()
 {
-       if [ -n "$__git_commandlist" ]; then
-               echo "$__git_commandlist"
+       if [ -n "$__git_all_commandlist" ]; then
+               echo "$__git_all_commandlist"
                return
        fi
        local i IFS=" "$'\n'
        for i in $(git help -a|egrep '^ ')
+       do
+               case $i in
+               *--*)             : helper pattern;;
+               *) echo $i;;
+               esac
+       done
+}
+__git_all_commandlist=
+__git_all_commandlist="$(__git_all_commands 2>/dev/null)"
+
+__git_porcelain_commands ()
+{
+       if [ -n "$__git_porcelain_commandlist" ]; then
+               echo "$__git_porcelain_commandlist"
+               return
+       fi
+       local i IFS=" "$'\n'
+       for i in "help" $(__git_all_commands)
        do
                case $i in
                *--*)             : helper pattern;;
@@ -427,8 +445,8 @@ __git_commands ()
                esac
        done
 }
-__git_commandlist=
-__git_commandlist="$(__git_commands 2>/dev/null)"
+__git_porcelain_commandlist=
+__git_porcelain_commandlist="$(__git_porcelain_commands 2>/dev/null)"
 
 __git_aliases ()
 {
@@ -489,7 +507,7 @@ _git_am ()
 {
        local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
        if [ -d "$dir"/rebase-apply ]; then
-               __gitcomp "--skip --resolved"
+               __gitcomp "--skip --resolved --abort"
                return
        fi
        case "$cur" in
@@ -543,6 +561,29 @@ _git_add ()
        COMPREPLY=()
 }
 
+_git_archive ()
+{
+       local cur="${COMP_WORDS[COMP_CWORD]}"
+       case "$cur" in
+       --format=*)
+               __gitcomp "$(git archive --list)" "" "${cur##--format=}"
+               return
+               ;;
+       --remote=*)
+               __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
+               return
+               ;;
+       --*)
+               __gitcomp "
+                       --format= --list --verbose
+                       --prefix= --remote= --exec=
+                       "
+               return
+               ;;
+       esac
+       __git_complete_file
+}
+
 _git_bisect ()
 {
        __git_has_doubledash && return
@@ -626,6 +667,8 @@ _git_bundle ()
 
 _git_checkout ()
 {
+       __git_has_doubledash && return
+
        __gitcomp "$(__git_refs)"
 }
 
@@ -647,6 +690,45 @@ _git_cherry_pick ()
        esac
 }
 
+_git_clean ()
+{
+       __git_has_doubledash && return
+
+       local cur="${COMP_WORDS[COMP_CWORD]}"
+       case "$cur" in
+       --*)
+               __gitcomp "--dry-run --quiet"
+               return
+               ;;
+       esac
+       COMPREPLY=()
+}
+
+_git_clone ()
+{
+       local cur="${COMP_WORDS[COMP_CWORD]}"
+       case "$cur" in
+       --*)
+               __gitcomp "
+                       --local
+                       --no-hardlinks
+                       --shared
+                       --reference
+                       --quiet
+                       --no-checkout
+                       --bare
+                       --mirror
+                       --origin
+                       --upload-pack
+                       --template=
+                       --depth
+                       "
+               return
+               ;;
+       esac
+       COMPREPLY=()
+}
+
 _git_commit ()
 {
        __git_has_doubledash && return
@@ -665,6 +747,15 @@ _git_commit ()
 
 _git_describe ()
 {
+       local cur="${COMP_WORDS[COMP_CWORD]}"
+       case "$cur" in
+       --*)
+               __gitcomp "
+                       --all --tags --contains --abbrev= --candidates=
+                       --exact-match --debug --long --match --always
+                       "
+               return
+       esac
        __gitcomp "$(__git_refs)"
 }
 
@@ -692,11 +783,6 @@ _git_diff ()
        __git_complete_file
 }
 
-_git_diff_tree ()
-{
-       __gitcomp "$(__git_refs)"
-}
-
 _git_fetch ()
 {
        local cur="${COMP_WORDS[COMP_CWORD]}"
@@ -767,6 +853,79 @@ _git_gc ()
        COMPREPLY=()
 }
 
+_git_grep ()
+{
+       __git_has_doubledash && return
+
+       local cur="${COMP_WORDS[COMP_CWORD]}"
+       case "$cur" in
+       --*)
+               __gitcomp "
+                       --cached
+                       --text --ignore-case --word-regexp --invert-match
+                       --full-name
+                       --extended-regexp --basic-regexp --fixed-strings
+                       --files-with-matches --name-only
+                       --files-without-match
+                       --count
+                       --and --or --not --all-match
+                       "
+               return
+               ;;
+       esac
+       COMPREPLY=()
+}
+
+_git_help ()
+{
+       local cur="${COMP_WORDS[COMP_CWORD]}"
+       case "$cur" in
+       --*)
+               __gitcomp "--all --info --man --web"
+               return
+               ;;
+       esac
+       __gitcomp "$(__git_all_commands)"
+}
+
+_git_init ()
+{
+       local cur="${COMP_WORDS[COMP_CWORD]}"
+       case "$cur" in
+       --shared=*)
+               __gitcomp "
+                       false true umask group all world everybody
+                       " "" "${cur##--shared=}"
+               return
+               ;;
+       --*)
+               __gitcomp "--quiet --bare --template= --shared --shared="
+               return
+               ;;
+       esac
+       COMPREPLY=()
+}
+
+_git_ls_files ()
+{
+       __git_has_doubledash && return
+
+       local cur="${COMP_WORDS[COMP_CWORD]}"
+       case "$cur" in
+       --*)
+               __gitcomp "--cached --deleted --modified --others --ignored
+                       --stage --directory --no-empty-directory --unmerged
+                       --killed --exclude= --exclude-from=
+                       --exclude-per-directory= --exclude-standard
+                       --error-unmatch --with-tree= --full-name
+                       --abbrev --ignored --exclude-per-directory
+                       "
+               return
+               ;;
+       esac
+       COMPREPLY=()
+}
+
 _git_ls_remote ()
 {
        __gitcomp "$(__git_remotes)"
@@ -812,6 +971,7 @@ _git_log ()
                        --stat --numstat --shortstat
                        --decorate --diff-filter=
                        --color-words --walk-reflogs
+                       --parents --children --full-history
                        "
                return
                ;;
@@ -846,6 +1006,18 @@ _git_merge_base ()
        __gitcomp "$(__git_refs)"
 }
 
+_git_mv ()
+{
+       local cur="${COMP_WORDS[COMP_CWORD]}"
+       case "$cur" in
+       --*)
+               __gitcomp "--dry-run"
+               return
+               ;;
+       esac
+       COMPREPLY=()
+}
+
 _git_name_rev ()
 {
        __gitcomp "--tags --all --stdin"
@@ -1170,6 +1342,32 @@ _git_reset ()
        __gitcomp "$(__git_refs)"
 }
 
+_git_revert ()
+{
+       local cur="${COMP_WORDS[COMP_CWORD]}"
+       case "$cur" in
+       --*)
+               __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
+               return
+               ;;
+       esac
+       COMPREPLY=()
+}
+
+_git_rm ()
+{
+       __git_has_doubledash && return
+
+       local cur="${COMP_WORDS[COMP_CWORD]}"
+       case "$cur" in
+       --*)
+               __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
+               return
+               ;;
+       esac
+       COMPREPLY=()
+}
+
 _git_shortlog ()
 {
        __git_has_doubledash && return
@@ -1210,9 +1408,25 @@ _git_show ()
        __git_complete_file
 }
 
+_git_show_branch ()
+{
+       local cur="${COMP_WORDS[COMP_CWORD]}"
+       case "$cur" in
+       --*)
+               __gitcomp "
+                       --all --remotes --topo-order --current --more=
+                       --list --independent --merge-base --no-name
+                       --sha1-name --topics --reflog
+                       "
+               return
+               ;;
+       esac
+       __git_complete_revlist
+}
+
 _git_stash ()
 {
-       local subcommands='save list show apply clear drop pop create'
+       local subcommands='save list show apply clear drop pop create branch'
        local subcommand="$(__git_find_subcommand "$subcommands")"
        if [ -z "$subcommand" ]; then
                __gitcomp "$subcommands"
@@ -1222,6 +1436,16 @@ _git_stash ()
                save,--*)
                        __gitcomp "--keep-index"
                        ;;
+               apply,--*)
+                       __gitcomp "--index"
+                       ;;
+               show,--*|drop,--*|pop,--*|branch,--*)
+                       COMPREPLY=()
+                       ;;
+               show,*|apply,*|drop,*|pop,*|branch,*)
+                       __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
+                                       | sed -n -e 's/:.*//p')"
+                       ;;
                *)
                        COMPREPLY=()
                        ;;
@@ -1369,7 +1593,8 @@ _git ()
                case "$i" in
                --git-dir=*) __git_dir="${i#--git-dir=}" ;;
                --bare)      __git_dir="." ;;
-               --version|--help|-p|--paginate) ;;
+               --version|-p|--paginate) ;;
+               --help) command="help"; break ;;
                *) command="$i"; break ;;
                esac
                c=$((++c))
@@ -1389,7 +1614,7 @@ _git ()
                        --help
                        "
                        ;;
-               *)     __gitcomp "$(__git_commands) $(__git_aliases)" ;;
+               *)     __gitcomp "$(__git_porcelain_commands) $(__git_aliases)" ;;
                esac
                return
        fi
@@ -1401,12 +1626,15 @@ _git ()
        am)          _git_am ;;
        add)         _git_add ;;
        apply)       _git_apply ;;
+       archive)     _git_archive ;;
        bisect)      _git_bisect ;;
        bundle)      _git_bundle ;;
        branch)      _git_branch ;;
        checkout)    _git_checkout ;;
        cherry)      _git_cherry ;;
        cherry-pick) _git_cherry_pick ;;
+       clean)       _git_clean ;;
+       clone)       _git_clone ;;
        commit)      _git_commit ;;
        config)      _git_config ;;
        describe)    _git_describe ;;
@@ -1414,21 +1642,28 @@ _git ()
        fetch)       _git_fetch ;;
        format-patch) _git_format_patch ;;
        gc)          _git_gc ;;
+       grep)        _git_grep ;;
+       help)        _git_help ;;
+       init)        _git_init ;;
        log)         _git_log ;;
+       ls-files)    _git_ls_files ;;
        ls-remote)   _git_ls_remote ;;
        ls-tree)     _git_ls_tree ;;
        merge)       _git_merge;;
        merge-base)  _git_merge_base ;;
+       mv)          _git_mv ;;
        name-rev)    _git_name_rev ;;
        pull)        _git_pull ;;
        push)        _git_push ;;
        rebase)      _git_rebase ;;
        remote)      _git_remote ;;
        reset)       _git_reset ;;
+       revert)      _git_revert ;;
+       rm)          _git_rm ;;
        send-email)  _git_send_email ;;
        shortlog)    _git_shortlog ;;
        show)        _git_show ;;
-       show-branch) _git_log ;;
+       show-branch) _git_show_branch ;;
        stash)       _git_stash ;;
        submodule)   _git_submodule ;;
        svn)         _git_svn ;;