zsh-workers
 help / color / mirror / code / Atom feed
From: "Øystein Walle" <oystwa@gmail.com>
To: zsh-workers@zsh.org
Cc: m0viefreak.cm@googlemail.com
Subject: [PATCH 09/16] _git: support completing remote branches without <remote>/ prefix
Date: Sun, 28 Jul 2013 18:22:06 +0200	[thread overview]
Message-ID: <69f645e1c5c26dbfdcccc4849a75853a848e99da.1375006129.git.oystwa@gmail.com> (raw)
In-Reply-To: <cover.1375006129.git.oystwa@gmail.com>
In-Reply-To: <cover.1375006129.git.oystwa@gmail.com>

From: m0viefreak <m0viefreak.cm@googlemail.com>

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
---
 Completion/Unix/Command/_git | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 2c74f2c..87edae9 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
@@ -5372,6 +5377,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.,
-- 
1.8.2.2


  parent reply	other threads:[~2013-07-28 16:23 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-28 16:21 [PATCH 00/16] Improvements to the Git completion functions Øystein Walle
2013-07-28 16:21 ` [PATCH 01/16] _git: fix a wrong variable in __git_config_values Øystein Walle
2013-07-28 16:21 ` [PATCH 02/16] _git: fix usage of ->int: for some entries in _git-config Øystein Walle
2013-07-28 16:22 ` [PATCH 03/16] _git: make git submodule <cmd> completion work Øystein Walle
2013-07-28 16:22 ` [PATCH 04/16] _git: correctly use __git_guard_number in some cases Øystein Walle
2013-07-28 16:22 ` [PATCH 05/16] _git: completion updates to match latest git v1.8.3 Øystein Walle
2013-07-28 16:22 ` [PATCH 06/16] _git: completion updates to match latest git v1.8.3 part 2 Øystein Walle
2013-07-28 16:22 ` [PATCH 07/16] _git: add new configuration options to match latest git v1.8.3 Øystein Walle
2013-07-28 16:22 ` [PATCH 08/16] _git: reword _git-config TODO Øystein Walle
2013-07-28 16:22 ` Øystein Walle [this message]
2013-07-28 16:22 ` [PATCH 10/16] _git: fix some typos Øystein Walle
2013-07-28 16:22 ` [PATCH 11/16] _git: remove TODOs of actually documented options Øystein Walle
2013-07-30 14:40   ` Nikolai Weibull
2013-07-30 18:01     ` Øystein Walle
2013-07-30 20:41       ` Nikolai Weibull
2013-07-28 16:22 ` [PATCH 12/16] _git: correct some "undocumented" options Øystein Walle
2013-07-30 14:39   ` Nikolai Weibull
2013-07-30 16:06     ` m0viefreak
2013-07-30 20:45       ` Nikolai Weibull
2013-07-28 16:22 ` [PATCH 13/16] _git: change completion text for consistency Øystein Walle
2013-07-28 16:22 ` [PATCH 14/16] _git: move --(no-)follow to be log-specific option Øystein Walle
2013-07-28 16:22 ` [PATCH 15/16] _git: git rm: make git rm --cached work as intended Øystein Walle
2013-07-30 14:37   ` Nikolai Weibull
2013-07-30 15:04     ` Aaron Schrab
2013-07-30 15:47       ` Nikolai Weibull
2013-07-28 16:22 ` [PATCH 16/16] _git: Document --early-output Øystein Walle
2013-07-30 14:35   ` Nikolai Weibull
2013-07-30 16:31     ` Øystein Walle
2013-07-30 20:42       ` Nikolai Weibull
2013-07-28 17:25 ` [PATCH 00/16] Improvements to the Git completion functions Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=69f645e1c5c26dbfdcccc4849a75853a848e99da.1375006129.git.oystwa@gmail.com \
    --to=oystwa@gmail.com \
    --cc=m0viefreak.cm@googlemail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).