git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matt Korostoff <mkorostoff@gmail.com>
To: git@vger.kernel.org
Cc: Matt Korostoff <MKorostoff@gmail.com>
Subject: [PATCH] contrib/completion: deprecate __git_remotes in bash completion
Date: Tue, 10 Feb 2015 10:25:07 -0500	[thread overview]
Message-ID: <1423581907-88600-1-git-send-email-MKorostoff@gmail.com> (raw)
In-Reply-To: <20150210031008.Horde.1WYJ_81O2E96Rgv2xrVmqw1@webmail.informatik.kit.edu>
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)

  reply	other threads:[~2015-02-10 15:24 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-09 20:58 [PATCH] contrib/completion: suppress stderror in bash completion of git remotes Matt Korostoff
2015-02-09 21:00 ` Matt Korostoff
2015-02-09 21:09 ` Junio C Hamano
2015-02-10  0:08   ` Matt Korostoff
2015-02-10  2:10   ` [PATCH] contrib/completion: suppress stderror in bash SZEDER Gábor
2015-02-10 15:25     ` Matt Korostoff [this message]
2015-02-10 18:31     ` Junio C Hamano
2015-02-10 19:16       ` SZEDER Gábor
2015-03-04 14:04         ` SZEDER Gábor
2015-03-04 14:10           ` [PATCH 1/2] completion: add a test for __git_remotes() helper function SZEDER Gábor
2015-03-04 14:10             ` [PATCH 2/2] completion: simplify __git_remotes() SZEDER Gábor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1423581907-88600-1-git-send-email-MKorostoff@gmail.com \
    --to=mkorostoff@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).