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

[PATCH v2 3/5] completion: improve existence check for pseudo-refs

From
Patrick Steinhardt <ps@pks.im>
Date
Jan 15, 2024, 10:36 UTC
Message-ID
<ab6e9118a552308d7121b6a1c12a8f04c4788326.1705314554.git.ps@pks.im>
In-Reply-To
<cover.1705314554.git.ps@pks.im>
Improve the existence check along the following lines:
  - Stop stripping the "ref :" prefix and compare to the expected value
    directly. This allows us to drop a now-unused variable that was
    previously leaking into the user's shell.
  - Mark the "head" variable as local so that we don't leak its value
    into the user's shell.
  - Stop manually handling the `-C $__git_repo_path` option, which the
    `__git ()` wrapper aleady does for us.
  - In simlar spirit, stop redirecting stderr, which is also handled by
    the wrapper already.
Suggested-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 contrib/completion/git-completion.bash | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 06a9107449..d703e3e64f 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -137,6 +137,7 @@ __git_eread ()
 __git_pseudoref_exists ()
 {
 	local ref=$1
+	local head
 
 	__git_find_repo_path
 
@@ -146,9 +147,8 @@ __git_pseudoref_exists ()
 	# Bash builtins since executing Git commands are expensive on some
 	# platforms.
 	if __git_eread "$__git_repo_path/HEAD" head; then
-		b="${head#ref: }"
-		if [ "$b" == "refs/heads/.invalid" ]; then
-			__git -C "$__git_repo_path" rev-parse --verify --quiet "$ref" 2>/dev/null
+		if [ "$head" == "ref: refs/heads/.invalid" ]; then
+			__git rev-parse --verify --quiet "$ref"
 			return $?
 		fi
 	fi
-- 
2.43.GIT
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 16 of 18 in “completion: silence pseudo-ref existence check”
  1. 0/2 completion: silence pseudo-ref existence checkPatrick Steinhardt, Jan 11, 2024
  2. 1/2 t9902: verify that completion does not print anythingPatrick Steinhardt, Jan 11, 2024
  3. Junio C HamanoJan 11, 2024
  4. Johannes SchindelinJan 12, 2024
  5. Patrick SteinhardtJan 12, 2024
  6. Johannes SchindelinJan 12, 2024
  7. Jeff KingJan 12, 2024
  8. Junio C HamanoJan 12, 2024
  9. Patrick SteinhardtJan 15, 2024
  10. 2/2 completion: silence pseudoref existence checkPatrick Steinhardt, Jan 11, 2024
  11. Junio C HamanoJan 11, 2024
  12. SZEDER GáborJan 13, 2024
  13. 0/5 completion: silence pseudo-ref existence checkPatrick Steinhardt, Jan 15, 2024
  14. 1/5 completion: discover repo path in `__git_pseudoref_exists ()`Patrick Steinhardt, Jan 15, 2024
  15. 2/5 t9902: verify that completion does not print anythingPatrick Steinhardt, Jan 15, 2024
  16. 3/5 completion: improve existence check for pseudo-refsPatrick Steinhardt, Jan 15, 2024
  17. 4/5 completion: silence pseudoref existence checkPatrick Steinhardt, Jan 15, 2024
  18. 5/5 completion: treat dangling symrefs as existing pseudorefsPatrick Steinhardt, Jan 15, 2024

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.