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

[PATCH 2/2] completion: silence pseudoref existence check

From
Patrick Steinhardt <ps@pks.im>
Date
Jan 11, 2024, 10:41 UTC
Message-ID
<24563975fca8df6ae73917e9ee3534933d47c429.1704969119.git.ps@pks.im>
In-Reply-To
<cover.1704969119.git.ps@pks.im>

In 44dbb3bf29 (completion: support pseudoref existence checks for reftables, 2023-12-19), we have extended the Bash completion script to support future ref backends better by using git-rev-parse(1) to check for pseudo-ref existence. This conversion has introduced a bug, because even though we pass `--quiet` to git-rev-parse(1) it would still output the resolved object ID of the ref in question if it exists.

Fix this by redirecting its stdout to `/dev/null` and add a test that catches this behaviour. Note that the test passes even without the fix for the "files" backend because we parse pseudo refs via the filesystem directly in that case. But the test will fail with the "reftable" backend.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 contrib/completion/git-completion.bash | 2 +-
 t/t9902-completion.sh                  | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 8c40ade494..8872192e2b 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -146,7 +146,7 @@ __git_pseudoref_exists ()
 	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
+			__git -C "$__git_repo_path" rev-parse --verify --quiet "$ref" >/dev/null 2>&1
 			return $?
 		fi
 	fi
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 78cb93bea7..b14ae4de14 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -1927,6 +1927,14 @@ test_expect_success 'git checkout - --orphan with branch already provided comple
 	EOF
 '
 
+test_expect_success 'git reset completes modified files' '
+	test_commit A a.file &&
+	echo B >a.file &&
+	test_completion "git restore a." <<-\EOF
+	a.file
+	EOF
+'
+
 test_expect_success 'teardown after ref completion' '
 	git branch -d matching-branch &&
 	git tag -d matching-tag &&
-- 
2.43.GIT
Previous: Patrick SteinhardtNext: Junio C Hamano
Message 10 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.