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

[PATCH] contrib/completion: deprecate __git_remotes in bash completion

From
Matt Korostoff <mkorostoff@gmail.com>
Date
Feb 10, 2015, 15:25 UTC
Message-ID
<1423581907-88600-1-git-send-email-MKorostoff@gmail.com>
In-Reply-To
<20150210031008.Horde.1WYJ_81O2E96Rgv2xrVmqw1@webmail.informatik.kit.edu>

Bash auto completion supplies a function __git_remotes which lists the git remotes of a repository by reading the .git/remotes directory. As of git 1.7.6 this is handled natively by the `git remote` command. This function is now deprecated.

Signed-off-by: Matt Korostoff <MKorostoff@gmail.com>
---
*****

Great point Gabor! I would hesitate a little about removing the function entirely, because users may have external scripts that rely on this function, but certainly for our internal purposes the __git_remotes shell function can be replaced with the native. Here's a short screen cast of the included patch working on my local http://i.imgur.com/6ZSMXCO.gif

*****
 contrib/completion/git-completion.bash |   30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 2fece98..8b41871 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -409,14 +409,14 @@ __git_refs_remotes ()
 	done
 }
 
+# Deprecated wrapper function around git remote.  Supplied for legacy purposes,
+# to avoid breaking any external scripts which rely on this function.
+# Originally this function was used to programmatically generate a list of git
+# remotes by reading the .git/remotes directory, but as of git 1.7.6 that is
+# natively handled by the git remote command
 __git_remotes ()
 {
-	local i IFS=$'\n' d="$(__gitdir)"
-	test -d "$d/remotes" && ls -1 "$d/remotes"
-	for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
-		i="${i#remote.}"
-		echo "${i/.url*/}"
-	done
+	git remote
 }
 
 __git_list_merge_strategies ()
@@ -558,7 +558,7 @@ __git_complete_remote_or_refspec ()
 		((c++))
 	done
 	if [ -z "$remote" ]; then
-		__gitcomp_nl "$(__git_remotes)"
+		__gitcomp_nl "$(git remote)"
 		return
 	fi
 	if [ $no_complete_refspec = 1 ]; then
@@ -927,7 +927,7 @@ _git_archive ()
 		return
 		;;
 	--remote=*)
-		__gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
+		__gitcomp_nl "$(git remote)" "" "${cur##--remote=}"
 		return
 		;;
 	--*)
@@ -1397,7 +1397,7 @@ _git_ls_files ()
 
 _git_ls_remote ()
 {
-	__gitcomp_nl "$(__git_remotes)"
+	__gitcomp_nl "$(git remote)"
 }
 
 _git_ls_tree ()
@@ -1639,7 +1639,7 @@ _git_push ()
 {
 	case "$prev" in
 	--repo)
-		__gitcomp_nl "$(__git_remotes)"
+		__gitcomp_nl "$(git remote)"
 		return
 		;;
 	--recurse-submodules)
@@ -1649,7 +1649,7 @@ _git_push ()
 	esac
 	case "$cur" in
 	--repo=*)
-		__gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
+		__gitcomp_nl "$(git remote)" "" "${cur##--repo=}"
 		return
 		;;
 	--recurse-submodules=*)
@@ -1797,7 +1797,7 @@ _git_config ()
 {
 	case "$prev" in
 	branch.*.remote|branch.*.pushremote)
-		__gitcomp_nl "$(__git_remotes)"
+		__gitcomp_nl "$(git remote)"
 		return
 		;;
 	branch.*.merge)
@@ -1809,7 +1809,7 @@ _git_config ()
 		return
 		;;
 	remote.pushdefault)
-		__gitcomp_nl "$(__git_remotes)"
+		__gitcomp_nl "$(git remote)"
 		return
 		;;
 	remote.*.fetch)
@@ -1944,7 +1944,7 @@ _git_config ()
 		;;
 	remote.*)
 		local pfx="${cur%.*}." cur_="${cur#*.}"
-		__gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
+		__gitcomp_nl "$(git remote)" "$pfx" "$cur_" "."
 		__gitcomp_nl_append "pushdefault" "$pfx" "$cur_"
 		return
 		;;
@@ -2250,7 +2250,7 @@ _git_remote ()
 
 	case "$subcommand" in
 	rename|remove|set-url|show|prune)
-		__gitcomp_nl "$(__git_remotes)"
+		__gitcomp_nl "$(git remote)"
 		;;
 	set-head|set-branches)
 		__git_complete_remote_or_refspec
-- 
1.7.10.2 (Apple Git-33)
Previous: SZEDER GáborNext: Junio C Hamano
Message 6 of 11 in “contrib/completion: suppress stderror in bash completion of git remotes”
  1. contrib/completion: suppress stderror in bash completion of git remotesMatt Korostoff, Feb 9, 2015
  2. Matt KorostoffFeb 9, 2015
  3. Junio C HamanoFeb 9, 2015
  4. Matt KorostoffFeb 10, 2015
  5. SZEDER GáborFeb 10, 2015
  6. contrib/completion: deprecate __git_remotes in bash completionMatt Korostoff, Feb 10, 2015
  7. Junio C HamanoFeb 10, 2015
  8. SZEDER GáborFeb 10, 2015
  9. SZEDER GáborMar 4, 2015
  10. 1/2 completion: add a test for __git_remotes() helper functionSZEDER Gábor, Mar 4, 2015
  11. 2/2 completion: simplify __git_remotes()SZEDER Gábor, Mar 4, 2015

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.