bash: Properly quote the GIT_DIR at all times to fix subdirectory paths with spaces
[gitweb.git] / contrib / completion / git-completion.bash
index 599b2fc5711bf6022fdb635b08baac16068de7dd..c29569c6247c346ceb409f72ff8e135929e11141 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
 }
@@ -291,7 +331,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;;
@@ -308,7 +348,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;;
@@ -334,7 +373,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;;
@@ -475,7 +514,33 @@ _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 ()
@@ -551,6 +616,20 @@ _git_describe ()
 
 _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
 }
 
@@ -603,6 +682,7 @@ _git_format_patch ()
                        --in-reply-to=
                        --full-index --binary
                        --not --all
+                       --cover-letter
                        "
                return
                ;;
@@ -957,18 +1037,18 @@ _git_remote ()
        while [ $c -lt $COMP_CWORD ]; do
                i="${COMP_WORDS[c]}"
                case "$i" in
-               add|show|prune|update) command="$i"; break ;;
+               add|rm|show|prune|update) command="$i"; break ;;
                esac
                c=$((++c))
        done
 
        if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
-               __gitcomp "add show prune update"
+               __gitcomp "add rm show prune update"
                return
        fi
 
        case "$command" in
-       show|prune)
+       rm|show|prune)
                __gitcomp "$(__git_remotes)"
                ;;
        update)