Merge branch 'ps/completion-with-reftable-fix'
Completion update to prepare for reftable * ps/completion-with-reftable-fix: completion: treat dangling symrefs as existing pseudorefs completion: silence pseudoref existence check completion: improve existence check for pseudo-refs t9902: verify that completion does not print anything completion: discover repo path in `__git_pseudoref_exists ()`
This commit is contained in:
@ -137,6 +137,9 @@ __git_eread ()
|
|||||||
__git_pseudoref_exists ()
|
__git_pseudoref_exists ()
|
||||||
{
|
{
|
||||||
local ref=$1
|
local ref=$1
|
||||||
|
local head
|
||||||
|
|
||||||
|
__git_find_repo_path
|
||||||
|
|
||||||
# If the reftable is in use, we have to shell out to 'git rev-parse'
|
# If the reftable is in use, we have to shell out to 'git rev-parse'
|
||||||
# to determine whether the ref exists instead of looking directly in
|
# to determine whether the ref exists instead of looking directly in
|
||||||
@ -144,9 +147,8 @@ __git_pseudoref_exists ()
|
|||||||
# Bash builtins since executing Git commands are expensive on some
|
# Bash builtins since executing Git commands are expensive on some
|
||||||
# platforms.
|
# platforms.
|
||||||
if __git_eread "$__git_repo_path/HEAD" head; then
|
if __git_eread "$__git_repo_path/HEAD" head; then
|
||||||
b="${head#ref: }"
|
if [ "$head" == "ref: refs/heads/.invalid" ]; then
|
||||||
if [ "$b" == "refs/heads/.invalid" ]; then
|
__git show-ref --exists "$ref"
|
||||||
__git -C "$__git_repo_path" rev-parse --verify --quiet "$ref" 2>/dev/null
|
|
||||||
return $?
|
return $?
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@ -1656,7 +1658,6 @@ __git_cherry_pick_inprogress_options=$__git_sequencer_inprogress_options
|
|||||||
|
|
||||||
_git_cherry_pick ()
|
_git_cherry_pick ()
|
||||||
{
|
{
|
||||||
__git_find_repo_path
|
|
||||||
if __git_pseudoref_exists CHERRY_PICK_HEAD; then
|
if __git_pseudoref_exists CHERRY_PICK_HEAD; then
|
||||||
__gitcomp "$__git_cherry_pick_inprogress_options"
|
__gitcomp "$__git_cherry_pick_inprogress_options"
|
||||||
return
|
return
|
||||||
@ -2966,7 +2967,6 @@ _git_reset ()
|
|||||||
|
|
||||||
_git_restore ()
|
_git_restore ()
|
||||||
{
|
{
|
||||||
__git_find_repo_path
|
|
||||||
case "$prev" in
|
case "$prev" in
|
||||||
-s)
|
-s)
|
||||||
__git_complete_refs
|
__git_complete_refs
|
||||||
@ -2995,7 +2995,6 @@ __git_revert_inprogress_options=$__git_sequencer_inprogress_options
|
|||||||
|
|
||||||
_git_revert ()
|
_git_revert ()
|
||||||
{
|
{
|
||||||
__git_find_repo_path
|
|
||||||
if __git_pseudoref_exists REVERT_HEAD; then
|
if __git_pseudoref_exists REVERT_HEAD; then
|
||||||
__gitcomp "$__git_revert_inprogress_options"
|
__gitcomp "$__git_revert_inprogress_options"
|
||||||
return
|
return
|
||||||
|
@ -5,6 +5,12 @@
|
|||||||
|
|
||||||
test_description='test bash completion'
|
test_description='test bash completion'
|
||||||
|
|
||||||
|
# The Bash completion scripts must not print anything to either stdout or
|
||||||
|
# stderr, which we try to verify. When tracing is enabled without support for
|
||||||
|
# BASH_XTRACEFD this assertion will fail, so we have to mark the test as
|
||||||
|
# untraceable with such ancient Bash versions.
|
||||||
|
test_untraceable=UnfortunatelyYes
|
||||||
|
|
||||||
. ./lib-bash.sh
|
. ./lib-bash.sh
|
||||||
|
|
||||||
complete ()
|
complete ()
|
||||||
@ -87,9 +93,11 @@ test_completion ()
|
|||||||
else
|
else
|
||||||
sed -e 's/Z$//' |sort >expected
|
sed -e 's/Z$//' |sort >expected
|
||||||
fi &&
|
fi &&
|
||||||
run_completion "$1" &&
|
run_completion "$1" >"$TRASH_DIRECTORY"/bash-completion-output 2>&1 &&
|
||||||
sort out >out_sorted &&
|
sort out >out_sorted &&
|
||||||
test_cmp expected out_sorted
|
test_cmp expected out_sorted &&
|
||||||
|
test_must_be_empty "$TRASH_DIRECTORY"/bash-completion-output &&
|
||||||
|
rm "$TRASH_DIRECTORY"/bash-completion-output
|
||||||
}
|
}
|
||||||
|
|
||||||
# Test __gitcomp.
|
# Test __gitcomp.
|
||||||
@ -1925,6 +1933,14 @@ test_expect_success 'git checkout - --orphan with branch already provided comple
|
|||||||
EOF
|
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' '
|
test_expect_success 'teardown after ref completion' '
|
||||||
git branch -d matching-branch &&
|
git branch -d matching-branch &&
|
||||||
git tag -d matching-tag &&
|
git tag -d matching-tag &&
|
||||||
@ -2720,4 +2736,31 @@ test_expect_success '__git_complete' '
|
|||||||
test_must_fail __git_complete ga missing
|
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 should exist, even if it points to an unborn branch.
|
||||||
|
__git_pseudoref_exists HEAD >output 2>&1 &&
|
||||||
|
test_must_be_empty output &&
|
||||||
|
|
||||||
|
# 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
|
test_done
|
||||||
|
Reference in New Issue
Block a user