Skip to content

Commit

Permalink
bash completion: refactor --strategy completion
Browse files Browse the repository at this point in the history
The code to complete --strategy was duplicated between _git_rebase and
_git_merge, and is about to gain a third caller (_git_pull). This patch
factors it into its own function.

Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
Acked-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jay Soffian authored and Junio C Hamano committed Mar 8, 2009
1 parent 52d5c3b commit 3c7b480
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions contrib/completion/git-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,23 @@ __git_complete_remote_or_refspec ()
esac
}

__git_complete_strategy ()
{
case "${COMP_WORDS[COMP_CWORD-1]}" in
-s|--strategy)
__gitcomp "$(__git_merge_strategies)"
return 0
esac
local cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in
--strategy=*)
__gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
return 0
;;
esac
return 1
}

__git_all_commands ()
{
if [ -n "${__git_all_commandlist-}" ]; then
Expand Down Expand Up @@ -1095,17 +1112,10 @@ _git_log ()

_git_merge ()
{
__git_complete_strategy && return

local cur="${COMP_WORDS[COMP_CWORD]}"
case "${COMP_WORDS[COMP_CWORD-1]}" in
-s|--strategy)
__gitcomp "$(__git_merge_strategies)"
return
esac
case "$cur" in
--strategy=*)
__gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
return
;;
--*)
__gitcomp "
--no-commit --no-stat --log --no-log --squash --strategy
Expand Down Expand Up @@ -1174,16 +1184,8 @@ _git_rebase ()
__gitcomp "--continue --skip --abort"
return
fi
case "${COMP_WORDS[COMP_CWORD-1]}" in
-s|--strategy)
__gitcomp "$(__git_merge_strategies)"
return
esac
__git_complete_strategy && return
case "$cur" in
--strategy=*)
__gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
return
;;
--*)
__gitcomp "--onto --merge --strategy --interactive"
return
Expand Down

0 comments on commit 3c7b480

Please sign in to comment.