Skip to content

Commit 9a9c311

Browse files
pks-tgitster
authored andcommitted
completion: silence pseudoref existence check
In 44dbb3b (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 <[email protected]> Helped-by: Johannes Schindelin <[email protected]> Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7b9cda2 commit 9a9c311

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

contrib/completion/git-completion.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ __git_pseudoref_exists ()
148148
# platforms.
149149
if __git_eread "$__git_repo_path/HEAD" head; then
150150
if [ "$head" == "ref: refs/heads/.invalid" ]; then
151-
__git rev-parse --verify --quiet "$ref"
151+
__git rev-parse --verify --quiet "$ref" >/dev/null
152152
return $?
153153
fi
154154
fi

t/t9902-completion.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,6 +1933,14 @@ test_expect_success 'git checkout - --orphan with branch already provided comple
19331933
EOF
19341934
'
19351935

1936+
test_expect_success 'git restore completes modified files' '
1937+
test_commit A a.file &&
1938+
echo B >a.file &&
1939+
test_completion "git restore a." <<-\EOF
1940+
a.file
1941+
EOF
1942+
'
1943+
19361944
test_expect_success 'teardown after ref completion' '
19371945
git branch -d matching-branch &&
19381946
git tag -d matching-tag &&
@@ -2728,4 +2736,27 @@ test_expect_success '__git_complete' '
27282736
test_must_fail __git_complete ga missing
27292737
'
27302738

2739+
test_expect_success '__git_pseudoref_exists' '
2740+
test_when_finished "rm -rf repo" &&
2741+
git init repo &&
2742+
(
2743+
cd repo &&
2744+
sane_unset __git_repo_path &&
2745+
2746+
# HEAD points to an existing branch, so it should exist.
2747+
test_commit A &&
2748+
__git_pseudoref_exists HEAD >output 2>&1 &&
2749+
test_must_be_empty output &&
2750+
2751+
# CHERRY_PICK_HEAD does not exist, so the existence check should fail.
2752+
! __git_pseudoref_exists CHERRY_PICK_HEAD >output 2>&1 &&
2753+
test_must_be_empty output &&
2754+
2755+
# CHERRY_PICK_HEAD points to a commit, so it should exist.
2756+
git update-ref CHERRY_PICK_HEAD A &&
2757+
__git_pseudoref_exists CHERRY_PICK_HEAD >output 2>&1 &&
2758+
test_must_be_empty output
2759+
)
2760+
'
2761+
27312762
test_done

0 commit comments

Comments
 (0)