help / color / mirror / code / Atom feed
From: "Øystein Walle" <oystwa@gmail.com>
To: zsh-workers@zsh.org
Cc: "Øystein Walle" <oystwa@gmail.com>
Subject: [PATCH] _git-push: complete remote branch names respecting --delete
Date: Fri, 10 Feb 2023 08:23:01 +0100	[thread overview]
Message-ID: <20230210072301.30349-1-oystwa@gmail.com> (raw)

If you want to delete the branch foo from origin and type:

    git push --delete origin f<TAB>

it might get completed as:

    git push --delete origin origin/foo

which will lead Git into erroring out saying the remote ref doesn't
exist. If -d or --delete is given on the command line then complete
remote branches without their prefix, otherwise proceed as before.
 Completion/Unix/Command/_git | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index b3ed7b5c8..a2555cbf0 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -1459,6 +1459,14 @@ _git-push () {
   # only complete files on the local end, not the remote end.  Still, it may be
   # helpful to get some sort of completion going, perhaps modifying the path
   # later on to match the remote end.
+  local ref_arg
+  if (( words[(I)-d|--delete] )); then
+      ref_arg='*: :__git_remote_branch_names_noprefix'
+  else
+      ref_arg='*: :__git_ref_specs_pushy'
+  fi
   _arguments -S -s $endopt \
     '--all[push all refs under refs/heads/]' \
     '--prune[remove remote branches that do not have a local counterpart]' \
@@ -1494,7 +1502,7 @@ _git-push () {
     '(-4 --ipv4 -6 --ipv6)'{-4,--ipv4}'[use IPv4 addresses only]' \
     '(-4 --ipv4 -6 --ipv6)'{-6,--ipv6}'[use IPv6 addresses only]' \
     ': :__git_any_repositories' \
-    '*: :__git_ref_specs_pushy' && ret=0
+    $ref_arg && ret=0
   case $state in

                 reply	other threads:[~2023-02-10  7:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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:

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

  git send-email \
    --in-reply-to=20230210072301.30349-1-oystwa@gmail.com \
    --to=oystwa@gmail.com \
    --cc=zsh-workers@zsh.org \


* 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


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).