about summary refs log tree commit diff
path: root/Completion/Unix/Command
diff options
context:
space:
mode:
authorm0viefreak <m0viefreak.cm@googlemail.com>2013-09-22 12:48:23 +0200
committerFrank Terbeck <ft@bewatermyfriend.org>2013-09-22 14:01:12 +0200
commit735e7becb9291b4feb0a55e903edf2f0e66fec37 (patch)
treefe83d4aa81f3c0852778956e06801e5fa32540e3 /Completion/Unix/Command
parente45f685d4addb4d1ae13ed8353e5ff95b7010d3a (diff)
downloadzsh-735e7becb9291b4feb0a55e903edf2f0e66fec37.tar.gz
zsh-735e7becb9291b4feb0a55e903edf2f0e66fec37.tar.xz
zsh-735e7becb9291b4feb0a55e903edf2f0e66fec37.zip
31748: _git: support completing remote branches without <remote>/ prefix
this is used in git 1.8's
git checkout <branch>
as a shorthand for
git checkout -b <branch> --track <remote>/<branch>
in case <branch> exists on exactly one remote and is not a local branch
Diffstat (limited to 'Completion/Unix/Command')
-rw-r--r--Completion/Unix/Command/_git16
1 files changed, 16 insertions, 0 deletions
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 0d0cb02c0..9d074536a 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -440,22 +440,27 @@ _git-checkout () {
       if (( CURRENT == 1 )) && [[ -z $opt_args[(I)--] ]]; then
         # TODO: Allow A...B
         local branch_arg='branches::__git_revisions' \
+              remote_branch_noprefix_arg='remote branches::__git_remote_branch_names_noprefix' \
               tree_ish_arg='tree-ishs::__git_tree_ishs' \
               file_arg='modified-files::__git_modified_files'
 
         if [[ -n ${opt_args[(I)-b|-B|--orphan]} ]]; then
+          remote_branch_noprefix_arg=
           tree_ish_arg=
           file_arg=
         elif [[ -n $opt_args[(I)--track] ]]; then
           branch_arg='remote-branches::__git_remote_branch_names'
+          remote_branch_noprefix_arg=
           tree_ish_arg=
           file_arg=
         elif [[ -n ${opt_args[(I)--ours|--theirs|-m|--conflict|--patch]} ]]; then
           branch_arg=
+          remote_branch_noprefix_arg=
         fi
 
         _alternative \
           $branch_arg \
+          $remote_branch_noprefix_arg \
           $tree_ish_arg \
           $file_arg && ret=0
       elif [[ -n ${opt_args[(I)-b|-B|-t|--track|--orphan]} ]]; then
@@ -5371,6 +5376,17 @@ __git_remote_branch_names () {
   _wanted remote-branch-names expl 'remote branch name' compadd $* - $branch_names
 }
 
+(( $+functions[__git_remote_branch_names_noprefix] )) ||
+__git_remote_branch_names_noprefix () {
+  local expl
+  declare -a heads
+
+  branch_names=(${${${(f)"$(_call_program remote-branch-refs-noprefix git for-each-ref --format='"%(refname)"' refs/remotes 2>/dev/null)"}##*/}:#HEAD})
+  __git_command_successful $pipestatus || return 1
+
+  _wanted remote-branch-names-noprefix expl 'remote branch name' compadd $* - $branch_names
+}
+
 (( $+functions[__git_commits] )) ||
 __git_commits () {
   # TODO: deal with things that __git_heads and __git_tags has in common (i.e.,