Skip to content

Commit 666270a

Browse files
stanhugitster
authored andcommitted
completion: refactor existence checks for pseudorefs
In preparation for the reftable backend, this commit introduces a '__git_pseudoref_exists' function that continues to use 'test -f' to determine whether a given pseudoref exists in the local filesystem. Signed-off-by: Stan Hu <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 564d025 commit 666270a

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

contrib/completion/git-completion.bash

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,15 @@ __git ()
122122
${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev/null
123123
}
124124

125+
# Runs git in $__git_repo_path to determine whether a pseudoref exists.
126+
# 1: The pseudo-ref to search
127+
__git_pseudoref_exists ()
128+
{
129+
local ref=$1
130+
131+
[ -f "$__git_repo_path/$ref" ]
132+
}
133+
125134
# Removes backslash escaping, single quotes and double quotes from a word,
126135
# stores the result in the variable $dequoted_word.
127136
# 1: The word to dequote.
@@ -1625,7 +1634,7 @@ __git_cherry_pick_inprogress_options=$__git_sequencer_inprogress_options
16251634
_git_cherry_pick ()
16261635
{
16271636
__git_find_repo_path
1628-
if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD ]; then
1637+
if __git_pseudoref_exists CHERRY_PICK_HEAD; then
16291638
__gitcomp "$__git_cherry_pick_inprogress_options"
16301639
return
16311640
fi
@@ -2067,7 +2076,7 @@ _git_log ()
20672076
__git_find_repo_path
20682077

20692078
local merge=""
2070-
if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
2079+
if __git_pseudoref_exists MERGE_HEAD; then
20712080
merge="--merge"
20722081
fi
20732082
case "$prev,$cur" in
@@ -2934,6 +2943,7 @@ _git_reset ()
29342943

29352944
_git_restore ()
29362945
{
2946+
__git_find_repo_path
29372947
case "$prev" in
29382948
-s)
29392949
__git_complete_refs
@@ -2952,7 +2962,7 @@ _git_restore ()
29522962
__gitcomp_builtin restore
29532963
;;
29542964
*)
2955-
if __git rev-parse --verify --quiet HEAD >/dev/null; then
2965+
if __git_pseudoref_exists HEAD; then
29562966
__git_complete_index_file "--modified"
29572967
fi
29582968
esac
@@ -2963,7 +2973,7 @@ __git_revert_inprogress_options=$__git_sequencer_inprogress_options
29632973
_git_revert ()
29642974
{
29652975
__git_find_repo_path
2966-
if [ -f "$__git_repo_path"/REVERT_HEAD ]; then
2976+
if __git_pseudoref_exists REVERT_HEAD; then
29672977
__gitcomp "$__git_revert_inprogress_options"
29682978
return
29692979
fi
@@ -3592,7 +3602,7 @@ __gitk_main ()
35923602
__git_find_repo_path
35933603

35943604
local merge=""
3595-
if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
3605+
if __git_pseudoref_exists MERGE_HEAD; then
35963606
merge="--merge"
35973607
fi
35983608
case "$cur" in

0 commit comments

Comments
 (0)