Skip to content

Commit 48e1c69

Browse files
pcloudsgitster
authored andcommitted
completion: factor out _git_xxx calling code
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d23bb38 commit 48e1c69

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

contrib/completion/git-completion.bash

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3035,6 +3035,17 @@ _git_worktree ()
30353035
fi
30363036
}
30373037

3038+
__git_complete_command () {
3039+
local command="$1"
3040+
local completion_func="_git_${command//-/_}"
3041+
if declare -f $completion_func >/dev/null 2>/dev/null; then
3042+
$completion_func
3043+
return 0
3044+
else
3045+
return 1
3046+
fi
3047+
}
3048+
30383049
__git_main ()
30393050
{
30403051
local i c=1 command __git_dir __git_repo_path
@@ -3094,14 +3105,12 @@ __git_main ()
30943105
return
30953106
fi
30963107

3097-
local completion_func="_git_${command//-/_}"
3098-
declare -f $completion_func >/dev/null 2>/dev/null && $completion_func && return
3108+
__git_complete_command "$command" && return
30993109

31003110
local expansion=$(__git_aliased_command "$command")
31013111
if [ -n "$expansion" ]; then
31023112
words[1]=$expansion
3103-
completion_func="_git_${expansion//-/_}"
3104-
declare -f $completion_func >/dev/null 2>/dev/null && $completion_func
3113+
__git_complete_command "$expansion"
31053114
fi
31063115
}
31073116

0 commit comments

Comments
 (0)