[PATCH v2] completion: remote set-* <name> and <branch>

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Complete <name> only for set-url. For set-branches and
set-head, complete <name> and <branch> over the network,
like e.g. git pull already does.

The style used for incrementing and decrementing variables was fairly
inconsistenty and was normalized to use ++x, or ((++x)) in contexts
where the former would otherwise be interpreted as a command. This is a
bash-ism, but for obvious reasons this script is already bash-specific.

Finally, remove out-of-date documentation for how to submit patches and
(silently) defer to Documentation/SubmittingPatches like all other code.

Signed-off-by: Philip Jägenstedt <philip@xxxxxxxxxx>
---
 contrib/completion/git-completion.bash |   42 +++++++++++++------------------
 1 files changed, 18 insertions(+), 24 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 1505cff..9dac084 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -60,18 +60,6 @@
 #       per-repository basis by setting the bash.showUpstream config
 #       variable.
 #
-#
-# To submit patches:
-#
-#    *) Read Documentation/SubmittingPatches
-#    *) Send all patches to the current maintainer:
-#
-#       "Shawn O. Pearce" <spearce@xxxxxxxxxxx>
-#
-#    *) Always CC the Git mailing list:
-#
-#       git@xxxxxxxxxxxxxxx
-#
 
 if [[ -n ${ZSH_VERSION-} ]]; then
 	autoload -U +X bashcompinit && bashcompinit
@@ -395,7 +383,7 @@ __git_reassemble_comp_words_by_ref()
 	fi
 	# List of word completion separators has shrunk;
 	# re-assemble words to complete.
-	for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
+	for ((i=0, j=0; i < ${#COMP_WORDS[@]}; ++i, ++j)); do
 		# Append each nonempty word consisting of just
 		# word separator characters to the current word.
 		first=t
@@ -408,7 +396,7 @@ __git_reassemble_comp_words_by_ref()
 			# Attach to the previous token,
 			# unless the previous token is the command name.
 			if [ $j -ge 2 ] && [ -n "$first" ]; then
-				((j--))
+				((--j))
 			fi
 			first=
 			words_[$j]=${words_[j]}${COMP_WORDS[i]}
@@ -416,7 +404,7 @@ __git_reassemble_comp_words_by_ref()
 				cword_=$j
 			fi
 			if (($i < ${#COMP_WORDS[@]} - 1)); then
-				((i++))
+				((++i))
 			else
 				# Done.
 				return
@@ -738,6 +726,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
 	while [ $c -lt $cword ]; do
 		i="${words[c]}"
 		case "$i" in
@@ -755,7 +746,7 @@ __git_complete_remote_or_refspec ()
 		-*) ;;
 		*) remote="$i"; break ;;
 		esac
-		c=$((++c))
+		((++c))
 	done
 	if [ -z "$remote" ]; then
 		__gitcomp_nl "$(__git_remotes)"
@@ -788,7 +779,7 @@ __git_complete_remote_or_refspec ()
 			__gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
 		fi
 		;;
-	pull)
+	pull|remote)
 		if [ $lhs = 1 ]; then
 			__gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
 		else
@@ -995,7 +986,7 @@ __git_find_on_cmdline ()
 				return
 			fi
 		done
-		c=$((++c))
+		((++c))
 	done
 }
 
@@ -1006,7 +997,7 @@ __git_has_doubledash ()
 		if [ "--" = "${words[c]}" ]; then
 			return 0
 		fi
-		c=$((++c))
+		((++c))
 	done
 	return 1
 }
@@ -1129,7 +1120,7 @@ _git_branch ()
 		-d|-m)	only_local_ref="y" ;;
 		-r)	has_r="y" ;;
 		esac
-		c=$((++c))
+		((++c))
 	done
 
 	case "$cur" in
@@ -2289,7 +2280,7 @@ _git_config ()
 
 _git_remote ()
 {
-	local subcommands="add rename rm show prune update set-head"
+	local subcommands="add rename rm set-head set-branches set-url show prune update"
 	local subcommand="$(__git_find_on_cmdline "$subcommands")"
 	if [ -z "$subcommand" ]; then
 		__gitcomp "$subcommands"
@@ -2297,9 +2288,12 @@ _git_remote ()
 	fi
 
 	case "$subcommand" in
-	rename|rm|show|prune)
+	rename|rm|set-url|show|prune)
 		__gitcomp_nl "$(__git_remotes)"
 		;;
+	set-head|set-branches)
+		__git_complete_remote_or_refspec
+		;;
 	update)
 		local i c='' IFS=$'\n'
 		for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
@@ -2580,7 +2574,7 @@ _git_tag ()
 			f=1
 			;;
 		esac
-		c=$((++c))
+		((++c))
 	done
 
 	case "$prev" in
@@ -2633,7 +2627,7 @@ _git ()
 		--help) command="help"; break ;;
 		*) command="$i"; break ;;
 		esac
-		c=$((++c))
+		((++c))
 	done
 
 	if [ -z "$command" ]; then
-- 
1.7.5.4

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]