]> git.ipfire.org Git - thirdparty/git.git/commitdiff
completion: silence pseudoref existence check
authorPatrick Steinhardt <ps@pks.im>
Mon, 15 Jan 2024 10:36:11 +0000 (11:36 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 16 Jan 2024 17:18:21 +0000 (09:18 -0800)
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.

Helped-by: Jeff King <peff@peff.net>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
contrib/completion/git-completion.bash
t/t9902-completion.sh

index d703e3e64ff5660b8f5c7fbdd1a4eaebe537081f..54ce58f73d70b444db9b0cf0c63d93c358812153 100644 (file)
@@ -148,7 +148,7 @@ __git_pseudoref_exists ()
        # platforms.
        if __git_eread "$__git_repo_path/HEAD" head; then
                if [ "$head" == "ref: refs/heads/.invalid" ]; then
-                       __git rev-parse --verify --quiet "$ref"
+                       __git rev-parse --verify --quiet "$ref" >/dev/null
                        return $?
                fi
        fi
index 95ec762a7445c8c3ca23aca5caa1f3fca78b0b00..56dc7343a2e5d7640456564dbadb1c472f746bba 100755 (executable)
@@ -1933,6 +1933,14 @@ test_expect_success 'git checkout - --orphan with branch already provided comple
        EOF
 '
 
+test_expect_success 'git restore 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 &&
@@ -2728,4 +2736,27 @@ test_expect_success '__git_complete' '
        test_must_fail __git_complete ga missing
 '
 
+test_expect_success '__git_pseudoref_exists' '
+       test_when_finished "rm -rf repo" &&
+       git init repo &&
+       (
+               cd repo &&
+               sane_unset __git_repo_path &&
+
+               # HEAD points to an existing branch, so it should exist.
+               test_commit A &&
+               __git_pseudoref_exists HEAD >output 2>&1 &&
+               test_must_be_empty output &&
+
+               # CHERRY_PICK_HEAD does not exist, so the existence check should fail.
+               ! __git_pseudoref_exists CHERRY_PICK_HEAD >output 2>&1 &&
+               test_must_be_empty output &&
+
+               # CHERRY_PICK_HEAD points to a commit, so it should exist.
+               git update-ref CHERRY_PICK_HEAD A &&
+               __git_pseudoref_exists CHERRY_PICK_HEAD >output 2>&1 &&
+               test_must_be_empty output
+       )
+'
+
 test_done