@matheusbsbs / matheus-bagliano / commits / 3c7b480a1c
Fork 0

bash completion: refactor --strategy completion

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>

Jay Soffian committed Mar 6, 2009 at 11:30 UTC 3c7b480a1cf6e1a1c73b4edde5d8cf0ac0c8111c
1 file changed +20 -18
contrib/completion/git-completion.bash
+20 -18
@@ -444,6 +444,23 @@ __git_complete_remote_or_refspec ()
444 esac
445 }
446
447 +__git_complete_strategy ()
448 +{
449 + case "${COMP_WORDS[COMP_CWORD-1]}" in
450 + -s|--strategy)
451 + __gitcomp "$(__git_merge_strategies)"
452 + return 0
453 + esac
454 + local cur="${COMP_WORDS[COMP_CWORD]}"
455 + case "$cur" in
456 + --strategy=*)
457 + __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
458 + return 0
459 + ;;
460 + esac
461 + return 1
462 +}
463 +
464 __git_all_commands ()
465 {
466 if [ -n "${__git_all_commandlist-}" ]; then
@@ -1095,17 +1112,10 @@ _git_log ()
1112
1113 _git_merge ()
1114 {
1115 + __git_complete_strategy && return
1116 +
1117 local cur="${COMP_WORDS[COMP_CWORD]}"
1099 - case "${COMP_WORDS[COMP_CWORD-1]}" in
1100 - -s|--strategy)
1101 - __gitcomp "$(__git_merge_strategies)"
1102 - return
1103 - esac
1118 case "$cur" in
1105 - --strategy=*)
1106 - __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
1107 - return
1108 - ;;
1119 --*)
1120 __gitcomp "
1121 --no-commit --no-stat --log --no-log --squash --strategy
@@ -1174,16 +1184,8 @@ _git_rebase ()
1184 __gitcomp "--continue --skip --abort"
1185 return
1186 fi
1177 - case "${COMP_WORDS[COMP_CWORD-1]}" in
1178 - -s|--strategy)
1179 - __gitcomp "$(__git_merge_strategies)"
1180 - return
1181 - esac
1187 + __git_complete_strategy && return
1188 case "$cur" in
1183 - --strategy=*)
1184 - __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
1185 - return
1186 - ;;
1189 --*)
1190 __gitcomp "--onto --merge --strategy --interactive"
1191 return