git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] completion: expand "push --delete <remote> <ref>" for refs on that <remote>

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Apr 18, 2017, 13:31 UTC
Message-ID
<20170418133152.3262-1-avarab@gmail.com>

Change the completion of "push --delete <remote> <ref>" to complete refs on that <remote>, not all refs. Before this e.g. cloning git.git and doing "git push --delete origin p<TAB>" will complete nothing, whereas origin/p<TAB> will uselessly complete origin/pu.

Now p<TAB> will complete as "pu". The completion of giving --delete later, e.g. "git push origin --delete p<TAB>" remains unchanged, this is a bug, but is a general existing limitation of the bash completion, and not how git-push is documented, so I'm not fixing that case.

I looked over t9902-completion.sh but couldn't quickly find out how to add a test for this, but all the existing tests pass, and all my manual testing of "git push --delete <remote> ..." does the right thing now.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 contrib/completion/git-completion.bash | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 1150164d5c..2e5b3ed776 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -701,7 +701,7 @@ __git_complete_revlist ()
 __git_complete_remote_or_refspec ()
 {
 	local cur_="$cur" cmd="${words[1]}"
-	local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
+	local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0 delete=0
 	if [ "$cmd" = "remote" ]; then
 		((c++))
 	fi
@@ -709,6 +709,7 @@ __git_complete_remote_or_refspec ()
 		i="${words[c]}"
 		case "$i" in
 		--mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
+		--delete) delete=1 ;;
 		--all)
 			case "$cmd" in
 			push) no_complete_refspec=1 ;;
@@ -761,7 +762,9 @@ __git_complete_remote_or_refspec ()
 		fi
 		;;
 	push)
-		if [ $lhs = 1 ]; then
+		if [ $delete = 1 ]; then
+			__git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
+		elif [ $lhs = 1 ]; then
 			__git_complete_refs --pfx="$pfx" --cur="$cur_"
 		else
 			__git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
-- 
2.11.0
Next: Junio C Hamano
Message 1 of 4 in “completion: expand "push --delete <remote> <ref>" for refs on that <remote>”
  1. completion: expand "push --delete <remote> <ref>" for refs on that <remote>Ævar Arnfjörð Bjarmason, Apr 18, 2017
  2. Junio C HamanoApr 19, 2017
  3. SZEDER GáborApr 21, 2017
  4. completion: expand "push --delete <remote> <ref>" for refs on that <remote>Ævar Arnfjörð Bjarmason, Apr 22, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.