Merge branch 'jc/read-tree-ignore'
[gitweb.git] / contrib / completion / git-completion.bash
index be978cf3d3d5f4368a882596ed152f94f6affb32..9c4d23a23c899798613978c1766d08a80ced6f2e 100755 (executable)
 
 __gitdir ()
 {
-       echo "${__git_dir:-$(git rev-parse --git-dir 2>/dev/null)}"
+       if [ -z "$1" ]; then
+               if [ -n "$__git_dir" ]; then
+                       echo "$__git_dir"
+               elif [ -d .git ]; then
+                       echo .git
+               else
+                       git rev-parse --git-dir 2>/dev/null
+               fi
+       elif [ -d "$1/.git" ]; then
+               echo "$1/.git"
+       else
+               echo "$1"
+       fi
 }
 
 __git_ps1 ()
@@ -51,7 +63,7 @@ __git_ps1 ()
 
 __git_heads ()
 {
-       local cmd i is_hash=y dir="${1:-$(__gitdir)}"
+       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)' \
@@ -60,7 +72,7 @@ __git_heads ()
                done
                return
        fi
-       for i in $(git-ls-remote "$dir" 2>/dev/null); do
+       for i in $(git-ls-remote "$1" 2>/dev/null); do
                case "$is_hash,$i" in
                y,*) is_hash=n ;;
                n,*^{}) is_hash=y ;;
@@ -72,7 +84,7 @@ __git_heads ()
 
 __git_refs ()
 {
-       local cmd i is_hash=y dir="${1:-$(__gitdir)}"
+       local cmd i is_hash=y dir="$(__gitdir "$1")"
        if [ -d "$dir" ]; then
                if [ -e "$dir/HEAD" ]; then echo HEAD; fi
                for i in $(git --git-dir="$dir" \
@@ -101,20 +113,9 @@ __git_refs ()
 
 __git_refs2 ()
 {
-       local cmd i is_hash=y dir="${1:-$(__gitdir)}"
-       if [ -d "$dir" ]; then
-               cmd=git-peek-remote
-       else
-               cmd=git-ls-remote
-       fi
-       for i in $($cmd "$dir" 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/}:${i#refs/tags/}" ;;
-               n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}:${i#refs/heads/}" ;;
-               n,*) is_hash=y; echo "$i:$i" ;;
-               esac
+       local i
+       for i in $(__git_refs "$1"); do
+               echo "$i:$i"
        done
 }
 
@@ -711,10 +712,13 @@ _git_repo_config ()
                core.legacyHeaders
                i18n.commitEncoding
                diff.color
+               color.diff
                diff.renameLimit
                diff.renames
                pager.color
+               color.pager
                status.color
+               color.status
                log.showroot
                show.difftree
                showbranch.default