completion: list refs from remote when remote's name matches a directory
[gitweb.git] / contrib / completion / git-completion.bash
index 46ac6a613839ec5c5615ab4c1d653d6c9c66937d..af5ad52bb189273ed77072ba473ed0871992538a 100644 (file)
@@ -347,12 +347,16 @@ __git_refs ()
        local format refs pfx
 
        if [ -n "$remote" ]; then
-               if [ -d "$remote/.git" ]; then
+               if __git_is_configured_remote "$remote"; then
+                       # configured remote takes precedence over a
+                       # local directory with the same name
+                       list_refs_from=remote
+               elif [ -d "$remote/.git" ]; then
                        dir="$remote/.git"
                elif [ -d "$remote" ]; then
                        dir="$remote"
                else
-                       list_refs_from=remote
+                       list_refs_from=url
                fi
        fi
 
@@ -435,6 +439,18 @@ __git_remotes ()
        git --git-dir="$d" remote
 }
 
+# Returns true if $1 matches the name of a configured remote, false otherwise.
+__git_is_configured_remote ()
+{
+       local remote
+       for remote in $(__git_remotes); do
+               if [ "$remote" = "$1" ]; then
+                       return 0
+               fi
+       done
+       return 1
+}
+
 __git_list_merge_strategies ()
 {
        git merge -s help 2>&1 |