bash completion: add options for 'git fsck'
[gitweb.git] / contrib / completion / git-completion.bash
index 056e43e4ad5410dfa42e20016e592b8825c48a41..10e36a7b0dc574eae9a6a5465a5b19506909251d 100755 (executable)
@@ -391,10 +391,11 @@ __git_complete_remote_or_refspec ()
 {
        local cmd="${COMP_WORDS[1]}"
        local cur="${COMP_WORDS[COMP_CWORD]}"
-       local i c=2 remote="" pfx="" lhs=1
+       local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
        while [ $c -lt $COMP_CWORD ]; do
                i="${COMP_WORDS[c]}"
                case "$i" in
+               --all|--mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
                -*) ;;
                *) remote="$i"; break ;;
                esac
@@ -404,6 +405,10 @@ __git_complete_remote_or_refspec ()
                __gitcomp "$(__git_remotes)"
                return
        fi
+       if [ $no_complete_refspec = 1 ]; then
+               COMPREPLY=()
+               return
+       fi
        [ "$remote" = "." ] && remote=
        case "$cur" in
        *:*)
@@ -894,7 +899,7 @@ _git_diff ()
        local cur="${COMP_WORDS[COMP_CWORD]}"
        case "$cur" in
        --*)
-               __gitcomp "--cached --pickaxe-all --pickaxe-regex
+               __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
                        --base --ours --theirs
                        $__git_diff_common_options
                        "
@@ -904,8 +909,20 @@ _git_diff ()
        __git_complete_file
 }
 
+__git_fetch_options="
+       --quiet --verbose --append --upload-pack --force --keep --depth=
+       --tags --no-tags
+"
+
 _git_fetch ()
 {
+       local cur="${COMP_WORDS[COMP_CWORD]}"
+       case "$cur" in
+       --*)
+               __gitcomp "$__git_fetch_options"
+               return
+               ;;
+       esac
        __git_complete_remote_or_refspec
 }
 
@@ -935,6 +952,21 @@ _git_format_patch ()
        __git_complete_revlist
 }
 
+_git_fsck ()
+{
+       local cur="${COMP_WORDS[COMP_CWORD]}"
+       case "$cur" in
+       --*)
+               __gitcomp "
+                       --tags --root --unreachable --cache --no-reflogs --full
+                       --strict --verbose --lost-found
+                       "
+               return
+               ;;
+       esac
+       COMPREPLY=()
+}
+
 _git_gc ()
 {
        local cur="${COMP_WORDS[COMP_CWORD]}"
@@ -1110,6 +1142,11 @@ _git_log ()
        __git_complete_revlist
 }
 
+__git_merge_options="
+       --no-commit --no-stat --log --no-log --squash --strategy
+       --commit --stat --no-squash --ff --no-ff
+"
+
 _git_merge ()
 {
        __git_complete_strategy && return
@@ -1117,10 +1154,7 @@ _git_merge ()
        local cur="${COMP_WORDS[COMP_CWORD]}"
        case "$cur" in
        --*)
-               __gitcomp "
-                       --no-commit --no-stat --log --no-log --squash --strategy
-                       --commit --stat --no-squash --ff --no-ff
-                       "
+               __gitcomp "$__git_merge_options"
                return
        esac
        __gitcomp "$(__git_refs)"
@@ -1169,11 +1203,43 @@ _git_name_rev ()
 
 _git_pull ()
 {
+       __git_complete_strategy && return
+
+       local cur="${COMP_WORDS[COMP_CWORD]}"
+       case "$cur" in
+       --*)
+               __gitcomp "
+                       --rebase --no-rebase
+                       $__git_merge_options
+                       $__git_fetch_options
+               "
+               return
+               ;;
+       esac
        __git_complete_remote_or_refspec
 }
 
 _git_push ()
 {
+       local cur="${COMP_WORDS[COMP_CWORD]}"
+       case "${COMP_WORDS[COMP_CWORD-1]}" in
+       --repo)
+               __gitcomp "$(__git_remotes)"
+               return
+       esac
+       case "$cur" in
+       --repo=*)
+               __gitcomp "$(__git_remotes)" "" "${cur##--repo=}"
+               return
+               ;;
+       --*)
+               __gitcomp "
+                       --all --mirror --tags --dry-run --force --verbose
+                       --receive-pack= --repo=
+               "
+               return
+               ;;
+       esac
        __git_complete_remote_or_refspec
 }
 
@@ -1465,7 +1531,7 @@ _git_config ()
 
 _git_remote ()
 {
-       local subcommands="add rename rm show prune update"
+       local subcommands="add rename rm show prune update set-head"
        local subcommand="$(__git_find_subcommand "$subcommands")"
        if [ -z "$subcommand" ]; then
                __gitcomp "$subcommands"
@@ -1829,6 +1895,7 @@ _git ()
        diff)        _git_diff ;;
        fetch)       _git_fetch ;;
        format-patch) _git_format_patch ;;
+       fsck)        _git_fsck ;;
        gc)          _git_gc ;;
        grep)        _git_grep ;;
        help)        _git_help ;;