Merge branch 'bc/mktag'
[gitweb.git] / contrib / completion / git-completion.bash
index f2b10fa5f67942dc1c8d9d4f16048a6e7e976084..791e30f6d78b06429f239defc76aaa0d09db4e09 100755 (executable)
@@ -64,12 +64,52 @@ __gitdir ()
 
 __git_ps1 ()
 {
-       local b="$(git symbolic-ref HEAD 2>/dev/null)"
-       if [ -n "$b" ]; then
+       local g="$(git rev-parse --git-dir 2>/dev/null)"
+       if [ -n "$g" ]; then
+               local r
+               local b
+               if [ -d "$g/../.dotest" ]
+               then
+                       if test -f "$g/../.dotest/rebasing"
+                       then
+                               r="|REBASE"
+                       elif test -f "$g/../.dotest/applying"
+                       then
+                               r="|AM"
+                       else
+                               r="|AM/REBASE"
+                       fi
+                       b="$(git symbolic-ref HEAD 2>/dev/null)"
+               elif [ -f "$g/.dotest-merge/interactive" ]
+               then
+                       r="|REBASE-i"
+                       b="$(cat "$g/.dotest-merge/head-name")"
+               elif [ -d "$g/.dotest-merge" ]
+               then
+                       r="|REBASE-m"
+                       b="$(cat "$g/.dotest-merge/head-name")"
+               elif [ -f "$g/MERGE_HEAD" ]
+               then
+                       r="|MERGING"
+                       b="$(git symbolic-ref HEAD 2>/dev/null)"
+               else
+                       if [ -f "$g/BISECT_LOG" ]
+                       then
+                               r="|BISECTING"
+                       fi
+                       if ! b="$(git symbolic-ref HEAD 2>/dev/null)"
+                       then
+                               if ! b="$(git describe --exact-match HEAD 2>/dev/null)"
+                               then
+                                       b="$(cut -c1-7 "$g/HEAD")..."
+                               fi
+                       fi
+               fi
+
                if [ -n "$1" ]; then
-                       printf "$1" "${b##refs/heads/}"
+                       printf "$1" "${b##refs/heads/}$r"
                else
-                       printf " (%s)" "${b##refs/heads/}"
+                       printf " (%s)" "${b##refs/heads/}$r"
                fi
        fi
 }
@@ -81,13 +121,21 @@ __gitcomp ()
        if [ $# -gt 2 ]; then
                cur="$3"
        fi
-       for c in $1; do
-               case "$c$4" in
-               --*=*) all="$all$c$4$s" ;;
-               *.)    all="$all$c$4$s" ;;
-               *)     all="$all$c$4 $s" ;;
-               esac
-       done
+       case "$cur" in
+       --*=)
+               COMPREPLY=()
+               return
+               ;;
+       *)
+               for c in $1; do
+                       case "$c$4" in
+                       --*=*) all="$all$c$4$s" ;;
+                       *.)    all="$all$c$4$s" ;;
+                       *)     all="$all$c$4 $s" ;;
+                       esac
+               done
+               ;;
+       esac
        IFS=$s
        COMPREPLY=($(compgen -P "$2" -W "$all" -- "$cur"))
        return
@@ -114,6 +162,27 @@ __git_heads ()
        done
 }
 
+__git_tags ()
+{
+       local cmd i is_hash=y dir="$(__gitdir "$1")"
+       if [ -d "$dir" ]; then
+               for i in $(git --git-dir="$dir" \
+                       for-each-ref --format='%(refname)' \
+                       refs/tags ); do
+                       echo "${i#refs/tags/}"
+               done
+               return
+       fi
+       for i in $(git-ls-remote "$1" 2>/dev/null); do
+               case "$is_hash,$i" in
+               y,*) is_hash=n ;;
+               n,*^{}) is_hash=y ;;
+               n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
+               n,*) is_hash=y; echo "$i" ;;
+               esac
+       done
+}
+
 __git_refs ()
 {
        local cmd i is_hash=y dir="$(__gitdir "$1")"
@@ -270,7 +339,7 @@ __git_commands ()
        for i in $(git help -a|egrep '^ ')
        do
                case $i in
-               add--interactive) : plumbing;;
+               *--*)             : helper pattern;;
                applymbox)        : ask gittus;;
                applypatch)       : ask gittus;;
                archimport)       : import;;
@@ -278,7 +347,6 @@ __git_commands ()
                check-attr)       : plumbing;;
                check-ref-format) : plumbing;;
                commit-tree)      : plumbing;;
-               convert-objects)  : plumbing;;
                cvsexportcommit)  : export;;
                cvsimport)        : import;;
                cvsserver)        : daemon;;
@@ -288,7 +356,6 @@ __git_commands ()
                diff-tree)        : plumbing;;
                fast-import)      : import;;
                fsck-objects)     : plumbing;;
-               fetch--tool)      : plumbing;;
                fetch-pack)       : plumbing;;
                fmt-merge-msg)    : plumbing;;
                for-each-ref)     : plumbing;;
@@ -314,7 +381,7 @@ __git_commands ()
                read-tree)        : plumbing;;
                receive-pack)     : plumbing;;
                reflog)           : plumbing;;
-               repo-config)      : plumbing;;
+               repo-config)      : deprecated;;
                rerere)           : plumbing;;
                rev-list)         : plumbing;;
                rev-parse)        : plumbing;;
@@ -325,8 +392,6 @@ __git_commands ()
                show-index)       : plumbing;;
                ssh-*)            : transport;;
                stripspace)       : plumbing;;
-               svn)              : import export;;
-               svnimport)        : import;;
                symbolic-ref)     : plumbing;;
                tar-tree)         : deprecated;;
                unpack-file)      : plumbing;;
@@ -370,6 +435,22 @@ __git_aliased_command ()
        done
 }
 
+__git_find_subcommand ()
+{
+       local word subcommand c=1
+
+       while [ $c -lt $COMP_CWORD ]; do
+               word="${COMP_WORDS[c]}"
+               for subcommand in $1; do
+                       if [ "$subcommand" = "$word" ]; then
+                               echo "$subcommand"
+                               return
+                       fi
+               done
+               c=$((++c))
+       done
+}
+
 __git_whitespacelist="nowarn warn error error-all strip"
 
 _git_am ()
@@ -419,7 +500,7 @@ _git_add ()
        local cur="${COMP_WORDS[COMP_CWORD]}"
        case "$cur" in
        --*)
-               __gitcomp "--interactive"
+               __gitcomp "--interactive --refresh"
                return
        esac
        COMPREPLY=()
@@ -427,24 +508,14 @@ _git_add ()
 
 _git_bisect ()
 {
-       local i c=1 command
-       while [ $c -lt $COMP_CWORD ]; do
-               i="${COMP_WORDS[c]}"
-               case "$i" in
-               start|bad|good|reset|visualize|replay|log)
-                       command="$i"
-                       break
-                       ;;
-               esac
-               c=$((++c))
-       done
-
-       if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
-               __gitcomp "start bad good reset visualize replay log"
+       local subcommands="start bad good reset visualize replay log"
+       local subcommand="$(__git_find_subcommand "$subcommands")"
+       if [ -z "$subcommand" ]; then
+               __gitcomp "$subcommands"
                return
        fi
 
-       case "$command" in
+       case "$subcommand" in
        bad|good|reset)
                __gitcomp "$(__git_refs)"
                ;;
@@ -456,7 +527,62 @@ _git_bisect ()
 
 _git_branch ()
 {
-       __gitcomp "$(__git_refs)"
+       local i c=1 only_local_ref="n" has_r="n"
+
+       while [ $c -lt $COMP_CWORD ]; do
+               i="${COMP_WORDS[c]}"
+               case "$i" in
+               -d|-m)  only_local_ref="y" ;;
+               -r)     has_r="y" ;;
+               esac
+               c=$((++c))
+       done
+
+       case "${COMP_WORDS[COMP_CWORD]}" in
+       --*=*)  COMPREPLY=() ;;
+       --*)
+               __gitcomp "
+                       --color --no-color --verbose --abbrev= --no-abbrev
+                       --track --no-track
+                       "
+               ;;
+       *)
+               if [ $only_local_ref = "y" -a $has_r = "n" ]; then
+                       __gitcomp "$(__git_heads)"
+               else
+                       __gitcomp "$(__git_refs)"
+               fi
+               ;;
+       esac
+}
+
+_git_bundle ()
+{
+       local mycword="$COMP_CWORD"
+       case "${COMP_WORDS[0]}" in
+       git)
+               local cmd="${COMP_WORDS[2]}"
+               mycword="$((mycword-1))"
+               ;;
+       git-bundle*)
+               local cmd="${COMP_WORDS[1]}"
+               ;;
+       esac
+       case "$mycword" in
+       1)
+               __gitcomp "create list-heads verify unbundle"
+               ;;
+       2)
+               # looking for a file
+               ;;
+       *)
+               case "$cmd" in
+                       create)
+                               __git_complete_revlist
+                       ;;
+               esac
+               ;;
+       esac
 }
 
 _git_checkout ()
@@ -496,8 +622,27 @@ _git_commit ()
        COMPREPLY=()
 }
 
+_git_describe ()
+{
+       __gitcomp "$(__git_refs)"
+}
+
 _git_diff ()
 {
+       local cur="${COMP_WORDS[COMP_CWORD]}"
+       case "$cur" in
+       --*)
+               __gitcomp "--cached --stat --numstat --shortstat --summary
+                       --patch-with-stat --name-only --name-status --color
+                       --no-color --color-words --no-renames --check
+                       --full-index --binary --abbrev --diff-filter
+                       --find-copies-harder --pickaxe-all --pickaxe-regex
+                       --text --ignore-space-at-eol --ignore-space-change
+                       --ignore-all-space --exit-code --quiet --ext-diff
+                       --no-ext-diff"
+               return
+               ;;
+       esac
        __git_complete_file
 }
 
@@ -544,11 +689,13 @@ _git_format_patch ()
                        --stdout --attach --thread
                        --output-directory
                        --numbered --start-number
+                       --numbered-files
                        --keep-subject
                        --signoff
                        --in-reply-to=
                        --full-index --binary
                        --not --all
+                       --cover-letter
                        "
                return
                ;;
@@ -561,7 +708,7 @@ _git_gc ()
        local cur="${COMP_WORDS[COMP_CWORD]}"
        case "$cur" in
        --*)
-               __gitcomp "--prune"
+               __gitcomp "--prune --aggressive"
                return
                ;;
        esac
@@ -588,18 +735,25 @@ _git_log ()
                        " "" "${cur##--pretty=}"
                return
                ;;
+       --date=*)
+               __gitcomp "
+                       relative iso8601 rfc2822 short local default
+               " "" "${cur##--date=}"
+               return
+               ;;
        --*)
                __gitcomp "
                        --max-count= --max-age= --since= --after=
                        --min-age= --before= --until=
                        --root --topo-order --date-order --reverse
-                       --no-merges
+                       --no-merges --follow
                        --abbrev-commit --abbrev=
-                       --relative-date
+                       --relative-date --date=
                        --author= --committer= --grep=
                        --all-match
                        --pretty= --name-status --name-only --raw
                        --not --all
+                       --left-right --cherry-pick
                        "
                return
                ;;
@@ -695,8 +849,8 @@ _git_push ()
 
 _git_rebase ()
 {
-       local cur="${COMP_WORDS[COMP_CWORD]}"
-       if [ -d .dotest ] || [ -d .git/.dotest-merge ]; then
+       local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
+       if [ -d .dotest ] || [ -d "$dir"/.dotest-merge ]; then
                __gitcomp "--continue --skip --abort"
                return
        fi
@@ -767,7 +921,7 @@ _git_config ()
        case "$cur" in
        --*)
                __gitcomp "
-                       --global --system
+                       --global --system --file=
                        --list --replace-all
                        --get --get-all --get-regexp
                        --add --unset --unset-all
@@ -810,11 +964,11 @@ _git_config ()
                core.ignoreStat
                core.preferSymlinkRefs
                core.logAllRefUpdates
+               core.loosecompression
                core.repositoryFormatVersion
                core.sharedRepository
                core.warnAmbiguousRefs
                core.compression
-               core.legacyHeaders
                core.packedGitWindowSize
                core.packedGitLimit
                clean.requireForce
@@ -841,10 +995,12 @@ _git_config ()
                diff.renames
                fetch.unpackLimit
                format.headers
+               format.subjectprefix
                gitcvs.enabled
                gitcvs.logfile
                gitcvs.allbinary
-               gitcvs.dbname gitcvs.dbdriver gitcvs.dbuser gitcvs.dvpass
+               gitcvs.dbname gitcvs.dbdriver gitcvs.dbuser gitcvs.dbpass
+               gitcvs.dbtablenameprefix
                gc.packrefs
                gc.reflogexpire
                gc.reflogexpireunreachable
@@ -867,6 +1023,10 @@ _git_config ()
                merge.verbosity
                pack.window
                pack.depth
+               pack.windowMemory
+               pack.compression
+               pack.deltaCacheSize
+               pack.deltaCacheLimit
                pull.octopus
                pull.twohead
                repack.useDeltaBaseOffset
@@ -886,22 +1046,14 @@ _git_config ()
 
 _git_remote ()
 {
-       local i c=1 command
-       while [ $c -lt $COMP_CWORD ]; do
-               i="${COMP_WORDS[c]}"
-               case "$i" in
-               add|show|prune|update) command="$i"; break ;;
-               esac
-               c=$((++c))
-       done
-
-       if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
-               __gitcomp "add show prune update"
+       local subcommands="add rm show prune update"
+       local subcommand="$(__git_find_subcommand "$subcommands")"
+       if [ -z "$subcommand" ]; then
                return
        fi
 
-       case "$command" in
-       show|prune)
+       case "$subcommand" in
+       rm|show|prune)
                __gitcomp "$(__git_remotes)"
                ;;
        update)
@@ -972,6 +1124,143 @@ _git_show ()
        __git_complete_file
 }
 
+_git_stash ()
+{
+       local subcommands='save list show apply clear drop pop create'
+       if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
+               __gitcomp "$subcommands"
+       fi
+}
+
+_git_submodule ()
+{
+       local subcommands="add status init update"
+       if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
+               local cur="${COMP_WORDS[COMP_CWORD]}"
+               case "$cur" in
+               --*)
+                       __gitcomp "--quiet --cached"
+                       ;;
+               *)
+                       __gitcomp "$subcommands"
+                       ;;
+               esac
+               return
+       fi
+}
+
+_git_svn ()
+{
+       local subcommands="
+               init fetch clone rebase dcommit log find-rev
+               set-tree commit-diff info create-ignore propget
+               proplist show-ignore show-externals
+               "
+       local subcommand="$(__git_find_subcommand "$subcommands")"
+       if [ -z "$subcommand" ]; then
+               __gitcomp "$subcommands"
+       else
+               local remote_opts="--username= --config-dir= --no-auth-cache"
+               local fc_opts="
+                       --follow-parent --authors-file= --repack=
+                       --no-metadata --use-svm-props --use-svnsync-props
+                       --log-window-size= --no-checkout --quiet
+                       --repack-flags --user-log-author $remote_opts
+                       "
+               local init_opts="
+                       --template= --shared= --trunk= --tags=
+                       --branches= --stdlayout --minimize-url
+                       --no-metadata --use-svm-props --use-svnsync-props
+                       --rewrite-root= $remote_opts
+                       "
+               local cmt_opts="
+                       --edit --rmdir --find-copies-harder --copy-similarity=
+                       "
+
+               local cur="${COMP_WORDS[COMP_CWORD]}"
+               case "$subcommand,$cur" in
+               fetch,--*)
+                       __gitcomp "--revision= --fetch-all $fc_opts"
+                       ;;
+               clone,--*)
+                       __gitcomp "--revision= $fc_opts $init_opts"
+                       ;;
+               init,--*)
+                       __gitcomp "$init_opts"
+                       ;;
+               dcommit,--*)
+                       __gitcomp "
+                               --merge --strategy= --verbose --dry-run
+                               --fetch-all --no-rebase $cmt_opts $fc_opts
+                               "
+                       ;;
+               set-tree,--*)
+                       __gitcomp "--stdin $cmt_opts $fc_opts"
+                       ;;
+               create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
+               show-externals,--*)
+                       __gitcomp "--revision="
+                       ;;
+               log,--*)
+                       __gitcomp "
+                               --limit= --revision= --verbose --incremental
+                               --oneline --show-commit --non-recursive
+                               --authors-file=
+                               "
+                       ;;
+               rebase,--*)
+                       __gitcomp "
+                               --merge --verbose --strategy= --local
+                               --fetch-all $fc_opts
+                               "
+                       ;;
+               commit-diff,--*)
+                       __gitcomp "--message= --file= --revision= $cmt_opts"
+                       ;;
+               info,--*)
+                       __gitcomp "--url"
+                       ;;
+               *)
+                       COMPREPLY=()
+                       ;;
+               esac
+       fi
+}
+
+_git_tag ()
+{
+       local i c=1 f=0
+       while [ $c -lt $COMP_CWORD ]; do
+               i="${COMP_WORDS[c]}"
+               case "$i" in
+               -d|-v)
+                       __gitcomp "$(__git_tags)"
+                       return
+                       ;;
+               -f)
+                       f=1
+                       ;;
+               esac
+               c=$((++c))
+       done
+
+       case "${COMP_WORDS[COMP_CWORD-1]}" in
+       -m|-F)
+               COMPREPLY=()
+               ;;
+       -*|tag|git-tag)
+               if [ $f = 1 ]; then
+                       __gitcomp "$(__git_tags)"
+               else
+                       COMPREPLY=()
+               fi
+               ;;
+       *)
+               __gitcomp "$(__git_refs)"
+               ;;
+       esac
+}
+
 _git ()
 {
        local i c=1 command __git_dir
@@ -987,10 +1276,20 @@ _git ()
                c=$((++c))
        done
 
-       if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
+       if [ -z "$command" ]; then
                case "${COMP_WORDS[COMP_CWORD]}" in
                --*=*) COMPREPLY=() ;;
-               --*)   __gitcomp "--git-dir= --bare --version --exec-path" ;;
+               --*)   __gitcomp "
+                       --paginate
+                       --no-pager
+                       --git-dir=
+                       --bare
+                       --version
+                       --exec-path
+                       --work-tree=
+                       --help
+                       "
+                       ;;
                *)     __gitcomp "$(__git_commands) $(__git_aliases)" ;;
                esac
                return
@@ -1004,12 +1303,14 @@ _git ()
        add)         _git_add ;;
        apply)       _git_apply ;;
        bisect)      _git_bisect ;;
+       bundle)      _git_bundle ;;
        branch)      _git_branch ;;
        checkout)    _git_checkout ;;
        cherry)      _git_cherry ;;
        cherry-pick) _git_cherry_pick ;;
        commit)      _git_commit ;;
        config)      _git_config ;;
+       describe)    _git_describe ;;
        diff)        _git_diff ;;
        fetch)       _git_fetch ;;
        format-patch) _git_format_patch ;;
@@ -1028,6 +1329,10 @@ _git ()
        shortlog)    _git_shortlog ;;
        show)        _git_show ;;
        show-branch) _git_log ;;
+       stash)       _git_stash ;;
+       submodule)   _git_submodule ;;
+       svn)         _git_svn ;;
+       tag)         _git_tag ;;
        whatchanged) _git_log ;;
        *)           COMPREPLY=() ;;
        esac
@@ -1051,10 +1356,12 @@ complete -o default -o nospace -F _git_am git-am
 complete -o default -o nospace -F _git_apply git-apply
 complete -o default -o nospace -F _git_bisect git-bisect
 complete -o default -o nospace -F _git_branch git-branch
+complete -o default -o nospace -F _git_bundle git-bundle
 complete -o default -o nospace -F _git_checkout git-checkout
 complete -o default -o nospace -F _git_cherry git-cherry
 complete -o default -o nospace -F _git_cherry_pick git-cherry-pick
 complete -o default -o nospace -F _git_commit git-commit
+complete -o default -o nospace -F _git_describe git-describe
 complete -o default -o nospace -F _git_diff git-diff
 complete -o default -o nospace -F _git_fetch git-fetch
 complete -o default -o nospace -F _git_format_patch git-format-patch
@@ -1073,7 +1380,11 @@ complete -o default -o nospace -F _git_remote git-remote
 complete -o default -o nospace -F _git_reset git-reset
 complete -o default -o nospace -F _git_shortlog git-shortlog
 complete -o default -o nospace -F _git_show git-show
+complete -o default -o nospace -F _git_stash git-stash
+complete -o default -o nospace -F _git_submodule git-submodule
+complete -o default -o nospace -F _git_svn git-svn
 complete -o default -o nospace -F _git_log git-show-branch
+complete -o default -o nospace -F _git_tag git-tag
 complete -o default -o nospace -F _git_log git-whatchanged
 
 # The following are necessary only for Cygwin, and only are needed
@@ -1085,7 +1396,9 @@ complete -o default -o nospace -F _git_add git-add.exe
 complete -o default -o nospace -F _git_apply git-apply.exe
 complete -o default -o nospace -F _git git.exe
 complete -o default -o nospace -F _git_branch git-branch.exe
+complete -o default -o nospace -F _git_bundle git-bundle.exe
 complete -o default -o nospace -F _git_cherry git-cherry.exe
+complete -o default -o nospace -F _git_describe git-describe.exe
 complete -o default -o nospace -F _git_diff git-diff.exe
 complete -o default -o nospace -F _git_format_patch git-format-patch.exe
 complete -o default -o nospace -F _git_log git-log.exe
@@ -1097,5 +1410,6 @@ complete -o default -o nospace -F _git_config git-config
 complete -o default -o nospace -F _git_shortlog git-shortlog.exe
 complete -o default -o nospace -F _git_show git-show.exe
 complete -o default -o nospace -F _git_log git-show-branch.exe
+complete -o default -o nospace -F _git_tag git-tag.exe
 complete -o default -o nospace -F _git_log git-whatchanged.exe
 fi