Skip to content

Commit 61d926a

Browse files
spearceJunio C Hamano
authored andcommitted
Teach bash how to complete git-rebase.
As git-rebase is a popular command bash should know how to complete reference names and its long options. We only support completions which make sense given the current state of the repository, that way users don't get shown --continue/--skip/--abort on the first execution. Also added support for long option --strategy to git-merge, as I missed that option earlier and just noticed it while implementing git-rebase. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 1273231 commit 61d926a

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

contrib/completion/git-completion.bash

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -367,16 +367,16 @@ _git_merge ()
367367
case "$cur" in
368368
--*)
369369
COMPREPLY=($(compgen -W "
370-
--no-commit --no-summary --squash
370+
--no-commit --no-summary --squash --strategy
371371
" -- "$cur"))
372372
return
373373
esac
374-
if [ $COMP_CWORD -gt 1 -a X-s = "X${COMP_WORDS[COMP_CWORD-1]}" ]
375-
then
374+
case "${COMP_WORDS[COMP_CWORD-1]}" in
375+
-s|--strategy)
376376
COMPREPLY=($(compgen -W "$(__git_merge_strategies)" -- "$cur"))
377-
else
378-
COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
379-
fi
377+
return
378+
esac
379+
COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
380380
}
381381

382382
_git_merge_base ()
@@ -443,6 +443,30 @@ _git_push ()
443443
esac
444444
}
445445

446+
_git_rebase ()
447+
{
448+
local cur="${COMP_WORDS[COMP_CWORD]}"
449+
if [ -d .dotest ]; then
450+
COMPREPLY=($(compgen -W "
451+
--continue --skip --abort
452+
" -- "$cur"))
453+
return
454+
fi
455+
case "$cur" in
456+
--*)
457+
COMPREPLY=($(compgen -W "
458+
--onto --merge --strategy
459+
" -- "$cur"))
460+
return
461+
esac
462+
case "${COMP_WORDS[COMP_CWORD-1]}" in
463+
-s|--strategy)
464+
COMPREPLY=($(compgen -W "$(__git_merge_strategies)" -- "$cur"))
465+
return
466+
esac
467+
COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
468+
}
469+
446470
_git_reset ()
447471
{
448472
local cur="${COMP_WORDS[COMP_CWORD]}"
@@ -500,6 +524,7 @@ _git ()
500524
name-rev) _git_name_rev ;;
501525
pull) _git_pull ;;
502526
push) _git_push ;;
527+
rebase) _git_rebase ;;
503528
reset) _git_reset ;;
504529
show) _git_show ;;
505530
show-branch) _git_log ;;
@@ -532,6 +557,7 @@ complete -o default -F _git_merge_base git-merge-base
532557
complete -o default -F _git_name_rev git-name-rev
533558
complete -o default -o nospace -F _git_pull git-pull
534559
complete -o default -o nospace -F _git_push git-push
560+
complete -o default -F _git_rebase git-rebase
535561
complete -o default -F _git_reset git-reset
536562
complete -o default -F _git_show git-show
537563
complete -o default -o nospace -F _git_log git-show-branch

0 commit comments

Comments
 (0)