completion: simplify completing 'git worktree' subcommands and options
The completion function for 'git worktree' uses separate but very similar case arms to complete --options for each subcommand. Combine these into a single case arm to avoid repetition. Note that after this change we won't complete 'git worktree remove's '--force' option, but that is consistent with our general stance on not offering '--force', as it should be used with care. Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
SZEDER Gábor committed
Dec 19, 2019 at 16:09 UTC
3c86f6cde85216808cddce9d4947de53d590474c
1 file changed
+8
-22
contrib/completion/git-completion.bash
+8
-22
@@ -2990,29 +2990,15 @@ _git_worktree ()
2990
{
2991
local subcommands="add list lock move prune remove unlock"
2992
local subcommand="$(__git_find_on_cmdline "$subcommands")"
2993
- if [ -z "$subcommand" ]; then
2993
+
2994
+ case "$subcommand,$cur" in
2995
+ ,*)
2996
__gitcomp "$subcommands"
2995
- else
2996
- case "$subcommand,$cur" in
2997
- add,--*)
2998
- __gitcomp_builtin worktree_add
2999
- ;;
3000
- list,--*)
3001
- __gitcomp_builtin worktree_list
3002
- ;;
3003
- lock,--*)
3004
- __gitcomp_builtin worktree_lock
3005
- ;;
3006
- prune,--*)
3007
- __gitcomp_builtin worktree_prune
3008
- ;;
3009
- remove,--*)
3010
- __gitcomp "--force"
3011
- ;;
3012
- *)
3013
- ;;
3014
- esac
3015
- fi
2997
+ ;;
2998
+ *,--*)
2999
+ __gitcomp_builtin worktree_$subcommand
3000
+ ;;
3001
+ esac
3002
}
3003
3004
__git_complete_common () {