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

Re: [PATCH v4] completion: ignore chpwd_functions when cding on zsh

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 9, 2014, 20:45 UTC
Message-ID
<xmqqk34955we.fsf@gitster.dls.corp.google.com>
In-Reply-To
<1412881298-64117-1-git-send-email-bt@brandonturner.net>
Brandon Turner <bt@brandonturner.net> writes:
> As Øystein pointed out, on zsh we can use "cd -q" to ignore
> chpwd_functions.
>
> Junio - from my testing, unsetting CDPATH is sufficient on zsh.
Let's do this instead, though.

Bugs are mine; as I do not use zsh myself, some testing is very much appreciated.

Thanks.
-- >8 --
Subject: [PATCH] completion: use "git -C $there" instead of (cd $there && git ...)

We have had "git -C $there" to first go to a different directory and run a Git command without changing the arguments for quite some time. Use it instead of (cd $there && git ...) in the completion script.

This allows us to lose the work-around for misfeatures of modern interactive-minded shells that make "cd" unusable in scripts (e.g. end users' $CDPATH taking us to unexpected places in any POSIX shell, and chpwd functions spewing unwanted output in zsh).

Based on Øystein Walle's idea, which was raised during the discussion on the solution by Brandon Turner for a problem zsh users had with RVM which mucks with chpwd_functions in users' environments (https://github.com/wayneeseguin/rvm/issues/3076).

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 contrib/completion/git-completion.bash | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index dba3c15..42f7308 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -263,16 +263,12 @@ __gitcomp_file ()
 # argument, and using the options specified in the second argument.
 __git_ls_files_helper ()
 {
-	(
-		test -n "${CDPATH+set}" && unset CDPATH
-		cd "$1"
-		if [ "$2" == "--committable" ]; then
-			git diff-index --name-only --relative HEAD
-		else
-			# NOTE: $2 is not quoted in order to support multiple options
-			git ls-files --exclude-standard $2
-		fi
-	) 2>/dev/null
+	if [ "$2" == "--committable" ]; then
+		git -C "$1" diff-index --name-only --relative HEAD
+	else
+		# NOTE: $2 is not quoted in order to support multiple options
+		git -C "$1" ls-files --exclude-standard $2
+	fi 2>/dev/null
 }
 
 
-- 
2.1.2-464-g5e996a3
Previous: Junio C HamanoNext: Brandon Turner
Message 10 of 16 in “completion: ignore chpwd_functions when cding”
  1. completion: ignore chpwd_functions when cdingBrandon Turner, Oct 8, 2014
  2. Junio C HamanoOct 8, 2014
  3. completion: ignore chpwd_functions when cdingBrandon Turner, Oct 8, 2014
  4. completion: ignore chpwd_functions when cding on zshBrandon Turner, Oct 8, 2014
  5. Øystein WalleOct 9, 2014
  6. Junio C HamanoOct 9, 2014
  7. completion: ignore chpwd_functions when cding on zshBrandon Turner, Oct 9, 2014
  8. Øystein WalleOct 9, 2014
  9. Junio C HamanoOct 9, 2014
  10. Junio C HamanoOct 9, 2014
  11. Brandon TurnerOct 9, 2014
  12. Junio C HamanoOct 9, 2014
  13. Brandon TurnerOct 9, 2014
  14. Øystein WalleOct 16, 2014
  15. Øystein WalleOct 9, 2014
  16. Brandon TurnerOct 8, 2014

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.