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

[PATCH] completion: teach to complete git-subtree

From
Ccornelius.weig@tngtech.com <cornelius.weig@tngtech.com>
Date
Feb 13, 2017, 01:07 UTC
Message-ID
<20170213010722.28518-1-cornelius.weig@tngtech.com>
From: Cornelius Weig <cornelius.weig@tngtech.com>

Git-subtree is a contrib-command without completion, making it cumbersome to use.

Teach bash completion to complete the subcommands of subtree (add, merge, pull, push, split) and options thereof. For subcommands supporting it (add, push, pull) also complete remote names and refspec.

Signed-off-by: Cornelius Weig <cornelius.weig@tngtech.com>
---
 contrib/completion/git-completion.bash | 35 ++++++++++++++++++++++++++++++----
 1 file changed, 31 insertions(+), 4 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 6c6e1c7..430bfed 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -535,9 +535,9 @@ __git_complete_remote_or_refspec ()
 {
 	local cur_="$cur" cmd="${words[1]}"
 	local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
-	if [ "$cmd" = "remote" ]; then
-		((c++))
-	fi
+	case "$cmd" in
+	remote|subtree) ((c++)) ;;
+	esac
 	while [ $c -lt $cword ]; do
 		i="${words[c]}"
 		case "$i" in
@@ -586,7 +586,7 @@ __git_complete_remote_or_refspec ()
 			__gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
 		fi
 		;;
-	pull|remote)
+	pull|remote|subtree)
 		if [ $lhs = 1 ]; then
 			__gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
 		else
@@ -2569,6 +2569,33 @@ _git_submodule ()
 	fi
 }
 
+_git_subtree ()
+{
+	local subcommands="add merge pull push split"
+	local subcommand="$(__git_find_on_cmdline "$subcommands")"
+	if [ -z "$subcommand" ]; then
+		__gitcomp "$subcommands"
+		return
+	fi
+	case "$subcommand,$cur" in
+	add,--*|merge,--*|pull,--*)
+		__gitcomp "--prefix= --squash --message="
+		;;
+	push,--*)
+		__gitcomp "--prefix="
+		;;
+	split,--*)
+		__gitcomp "
+			--annotate= --branch= --ignore-joins
+			--onto= --prefix= --rejoin
+			"
+		;;
+	add,*|push,*|pull,*)
+		__git_complete_remote_or_refspec
+		;;
+	esac
+}
+
 _git_svn ()
 {
 	local subcommands="
-- 
2.10.2
Message 1 of 1 in “completion: teach to complete git-subtree”
  1. completion: teach to complete git-subtreecornelius.weig@tngtech.com, Feb 13, 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.