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

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

From
Philip Jägenstedt <philip@foolip.org>
Date
Feb 21, 2012, 21:54 UTC
Message-ID
<1329861274-21418-1-git-send-email-philip@foolip.org>
In-Reply-To
<CAKHWUkZjQYnf=LwS_RC-E_7gV73AzbWjxs33E5-FL25s6_qX4g@mail.gmail.com>

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@foolip.org>
---
 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@spearce.org>
-#
-#    *) Always CC the Git mailing list:
-#
-#       git@vger.kernel.org
-#
 
 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
Previous: Philip JägenstedtNext: SZEDER Gábor
Message 4 of 14 in “completion: remote set-* <name> and <branch>”
  1. completion: remote set-* <name> and <branch>Philip Jägenstedt, Feb 18, 2012
  2. Junio C HamanoFeb 20, 2012
  3. Philip JägenstedtFeb 21, 2012
  4. completion: remote set-* <name> and <branch>Philip Jägenstedt, Feb 21, 2012
  5. SZEDER GáborFeb 22, 2012
  6. completion: remote set-* <name> and <branch>Philip Jägenstedt, Feb 22, 2012
  7. 1/4 completion: remote set-* <name> and <branch>Philip Jägenstedt, Feb 22, 2012
  8. 2/4 completion: normalize increment/decrement stylePhilip Jägenstedt, Feb 22, 2012
  9. Junio C HamanoFeb 22, 2012
  10. 3/4 completion: remove stale "to submit patches" documentationPhilip Jägenstedt, Feb 22, 2012
  11. 4/4 completion: use tabs for indentationPhilip Jägenstedt, Feb 22, 2012
  12. Thomas RastFeb 22, 2012
  13. Junio C HamanoFeb 21, 2012
  14. SZEDER GáborFeb 22, 2012

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.