@matheusbsbs / matheus-bagliano / commits / 4ad91321ee
Fork 0

Teach git-completion.bash how to complete git-merge.

Now that git-merge is high-level Porcelain users are going to expect to be able to use it from the command line, in which case we really should also be able to complete ref names as parameters. I'm also including completion support for the merge strategies that are supported by git-merge.sh, should the user wish to use a different strategy than their default. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Shawn O. Pearce committed Nov 27, 2006 at 03:40 UTC 4ad91321ee95598c2488ab5e39afec13575d4e3f
1 file changed +30
contrib/completion/git-completion.bash
+30
@@ -81,6 +81,16 @@ __git_remotes ()
81 done
82 }
83
84 +__git_merge_strategies ()
85 +{
86 + sed -n "/^all_strategies='/{
87 + s/^all_strategies='//
88 + s/'//
89 + p
90 + q
91 + }" "$(git --exec-path)/git-merge"
92 +}
93 +
94 __git_complete_file ()
95 {
96 local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
@@ -240,6 +250,24 @@ _git_log ()
250 esac
251 }
252
253 +_git_merge ()
254 +{
255 + local cur="${COMP_WORDS[COMP_CWORD]}"
256 + case "$cur" in
257 + --*)
258 + COMPREPLY=($(compgen -W "
259 + --no-commit --no-summary --squash
260 + " -- "$cur"))
261 + return
262 + esac
263 + if [ $COMP_CWORD -gt 1 -a X-s = "X${COMP_WORDS[COMP_CWORD-1]}" ]
264 + then
265 + COMPREPLY=($(compgen -W "$(__git_merge_strategies)" -- "$cur"))
266 + else
267 + COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
268 + fi
269 +}
270 +
271 _git_merge_base ()
272 {
273 local cur="${COMP_WORDS[COMP_CWORD]}"
@@ -348,6 +376,7 @@ _git ()
376 log) _git_log ;;
377 ls-remote) _git_ls_remote ;;
378 ls-tree) _git_ls_tree ;;
379 + merge) _git_merge;;
380 merge-base) _git_merge_base ;;
381 pull) _git_pull ;;
382 push) _git_push ;;
@@ -376,6 +405,7 @@ complete -o default -o nospace -F _git_fetch git-fetch
405 complete -o default -o nospace -F _git_log git-log
406 complete -o default -F _git_ls_remote git-ls-remote
407 complete -o default -o nospace -F _git_ls_tree git-ls-tree
408 +complete -o default -F _git_merge git-merge
409 complete -o default -F _git_merge_base git-merge-base
410 complete -o default -o nospace -F _git_pull git-pull
411 complete -o default -o nospace -F _git_push git-push